[
http://jira.jboss.com/jira/browse/JBRULES-1091?page=comments#action_12373555 ]
Alexandre Gattiker commented on JBRULES-1091:
---------------------------------------------
Thanks for the tip on accumulate functions. Indeed that is what I developed in my case,
though it doesn't help on the null issue of course.
I agree with your assumption, as I understand that Drools cannot handle null facts. There
is not always a direct null object available, however (such as your example with Money(0),
which lacks a currency). We can still use either the Null Object pattern or a mutable
object (commons-lang), something like
MutableObject(value: $totalPayments:)
from accumulate( Payment ( customer == $c, $val : value )
init( MutableObject total = new MutableObject(); )
action( total.setValue(addNullSafe( $val,
total.getValue()) ); )
result( total ) )
So the bug can only be solved in catching the error early and provide a meaningful error
message.
Thank you very much for your tips. Drools is so elegant it's highly addictive :)
NullPointerException when the 'result' block of an
'accumulate' function returns null
-------------------------------------------------------------------------------------
Key: JBRULES-1091
URL:
http://jira.jboss.com/jira/browse/JBRULES-1091
Project: JBoss Rules
Issue Type: Bug
Security Level: Public(Everyone can see)
Components: Reteoo
Affects Versions: 4.0.0.GA
Reporter: Alexandre Gattiker
Assigned To: Edson Tirelli
Fix For: 4.0.1
java.lang.NullPointerException
at org.drools.common.DefaultFactHandle.<init>(DefaultFactHandle.java:73)
at
org.drools.reteoo.ReteooFactHandleFactory.newFactHandle(ReteooFactHandleFactory.java:34)
at
org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:57)
at
org.drools.common.AbstractFactHandleFactory.newFactHandle(AbstractFactHandleFactory.java:48)
at org.drools.reteoo.AccumulateNode.assertTuple(AccumulateNode.java:176)
at
org.drools.reteoo.SingleTupleSinkAdapter.createAndPropagateAssertTuple(SingleTupleSinkAdapter.java:55)
at org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:131)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:20)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:168)
at org.drools.reteoo.Rete.assertObject(Rete.java:168)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:190)
at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:163)
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1241)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:858)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:822)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:623)
at com.sample.DroolsTest.main(DroolsTest.java:28)
Example rule:
rule "Example"
no-loop true
when
$d: Double()
from accumulate ( m : Message( $value: status ),
init( double total = 0; ),
action( System.out.println($value); ),
result( null )
)
then
System.out.println( "xx");
end
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.jboss.com/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira