[jboss-jira] [JBoss JIRA] (DROOLS-2715) Null Pointer Exception on Accumulate

Mario Fusco (JIRA) issues at jboss.org
Wed Jul 11 04:31:00 EDT 2018


    [ https://issues.jboss.org/browse/DROOLS-2715?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13603484#comment-13603484 ] 

Mario Fusco edited comment on DROOLS-2715 at 7/11/18 4:30 AM:
--------------------------------------------------------------

I simplified the rule causing the problem as it follows

{code}
rule "Rule X" when
    openAlarms: Collection( ) from accumulate (
            MyAlarm(
                openAlarms_ek: externalKey
            ),
            init( Map map = new HashMap(); ),
            action( map.put(openAlarms_ek, openAlarms); ),
            result( map.values() ) )
then
end
{code}

As you can see you're trying to use the result of the accumulation (the openAlarms collection) inside the action function of the accumulate itself. I guess this is not what you wanted and anyway doesn't make any sense. Do you agree?

I think that in this case the drl shouldn't compile at all and I'll try to change the compiler to raise a compilation error in this case.


was (Author: mfusco):
I simplified the rule causing the problem as it follows

{code}
rule "Rule X" when
    *openAlarms*: Collection( ) from accumulate (
            MyAlarm(
                openAlarms_ek: externalKey
            ),
            init( Map map = new HashMap(); ),
            action( map.put(openAlarms_ek, *openAlarms*); ),
            result( map.values() ) )
then
end
{code}

As you can see you're trying to use the result of the accumulation inside the action function of the accumulate itself. I guess this is not what you wanted and anyway doesn't make any sense. Do you agree?

I think that in this case the drl shouldn't compile at all and I'll try to change the compiler to raise a compilation error in this case.

> Null Pointer Exception on Accumulate
> ------------------------------------
>
>                 Key: DROOLS-2715
>                 URL: https://issues.jboss.org/browse/DROOLS-2715
>             Project: Drools
>          Issue Type: Bug
>    Affects Versions: 7.6.0.Final, 7.7.0.Final, 7.8.0.Final
>            Reporter: Pedro Almeida
>            Assignee: Mario Fusco
>         Attachments: DroolsBug.zip
>
>
> I was able to get a Null Pointer out of a simple accumulate.
> Download the attached zip and run the test.
> java.lang.RuntimeException: java.lang.NullPointerException
> 	at org.drools.core.rule.SingleAccumulate.init(SingleAccumulate.java:88)
> 	at org.drools.core.phreak.PhreakAccumulateNode.doLeftInserts(PhreakAccumulateNode.java:148)
> 	at org.drools.core.phreak.PhreakAccumulateNode.doNode(PhreakAccumulateNode.java:89)
> 	at org.drools.core.phreak.RuleNetworkEvaluator.switchOnDoBetaNode(RuleNetworkEvaluator.java:567)
> 	at org.drools.core.phreak.RuleNetworkEvaluator.evalBetaNode(RuleNetworkEvaluator.java:538)
> 	at org.drools.core.phreak.RuleNetworkEvaluator.evalNode(RuleNetworkEvaluator.java:373)
> 	at org.drools.core.phreak.RuleNetworkEvaluator.innerEval(RuleNetworkEvaluator.java:333)
> 	at org.drools.core.phreak.RuleNetworkEvaluator.outerEval(RuleNetworkEvaluator.java:169)
> 	at org.drools.core.phreak.RuleNetworkEvaluator.evaluateNetwork(RuleNetworkEvaluator.java:127)
> 	at org.drools.core.phreak.RuleExecutor.reEvaluateNetwork(RuleExecutor.java:212)
> 	at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:87)
> 	at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:34)
> 	at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
> 	at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1067)
> 	at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1014)
> 	at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1006)
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1308)
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1299)
> 	at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1283)
> 	at tests.TestsClass.test(TestsClass.java:52)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> 	at java.lang.reflect.Method.invoke(Method.java:498)
> 	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> 	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> 	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> 	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> 	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
> 	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
> 	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> 	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> 	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> 	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> 	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> 	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> 	at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> 	at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
> 	at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
> 	at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
> 	at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
> Caused by: java.lang.NullPointerException
> 	at org.drools.core.reteoo.BaseLeftTuple.getObject(BaseLeftTuple.java:628)
> 	at org.drools.core.reteoo.BaseTuple.getObject(BaseTuple.java:48)
> 	at defaultpkg.Rule_Rule_X0Accumulate0Invoker.init(Rule_Rule_X0Accumulate0Invoker.java:21)
> 	at org.drools.core.rule.SingleAccumulate.init(SingleAccumulate.java:82)
> 	... 41 more



--
This message was sent by Atlassian JIRA
(v7.5.0#75005)


More information about the jboss-jira mailing list