[
http://jira.jboss.com/jira/browse/JBRULES-1091?page=comments#action_12373405 ]
Edson Tirelli commented on JBRULES-1091:
----------------------------------------
Alexander,
Yes, the problem is exactly further constraints on the null value.
I understand that in sql the result could be null, but in drools, it should only be null
if the user does it on purpose, what would be wrong. Such accumulations are always
initialized in the init block:
when
$c:Customer()
$totalPayments:Money()
from accumulate( Payment ( customer == $c, $val : value )
init( Money total = new Money( 0 ); )
action( total.add( $val ); )
reverse( total.subtract( $val ); )
result( total ) )
then
// ...
end
Is my assumption wrong?
So, maybe we can add a null check, so that we can provide a user friendly error message,
but allowing null into the engine has huge drawbacks.
On an unrelated note, did you saw the accumulate functions feature? It may be interesting
for you, doing things like:
when
$c:Customer()
$totalPayments:Number()
from accumulate( Payment ( customer == $c, $val : value )
sum( $val ) )
then
// ...
end
You can also create your own functions in case you want to return custom objects like the
Money object in your example.
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)
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