[jboss-jira] [JBoss JIRA] (JBRULES-3390) Drools java.lang.NullPointerException at org.drools.reteoo.RuleTerminalNode
RH Bugzilla Integration (JIRA)
jira-events at lists.jboss.org
Thu Mar 15 12:15:49 EDT 2012
[ https://issues.jboss.org/browse/JBRULES-3390?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12677095#comment-12677095 ]
RH Bugzilla Integration commented on JBRULES-3390:
--------------------------------------------------
Justin Holmes <jholmes at redhat.com> made a comment on [bug 803460|https://bugzilla.redhat.com/show_bug.cgi?id=803460]
After further debugging, I think this error is not a regression in Drools. Rather, this is an error that should occur but ought to be a properly handled expression. Consider the rule below (slightly modified from above). Attached is a screenshot of the reteoo tree Drools builds for this rule:
When
$A : A() &&
($B : B() ||
($C : C() && $D : D ())
)
Then
insert new E($A, $D)
End
Drools transforms this into two rete patterns: ($A && $B) || ($A && $C && $D).
The consequence references both $A and $D, but $D is only present in one pattern, and therefore only present in one of the two terminal nodes that executes the consequence. Therefore, one would expect this rule to fail at some point, so the question becomes when and how. In 5.1.1, a ConsequenceException with a NPE is thrown at runtime when the ($A && $B) pattern is matched. In 5.2.x, the kbuilder throws an NPE while build the knowledgeBase (attached stack trace).
In conclusion, this error is good and should be expected behavior. However, the error needs to be thrown as a properly handled exception and should preferably be thrown when building the KnowledgePackage, not the KnowledgeBase. This would make it more clear to end users that the rule itself is problematic, not the implementation of Drools.
> Drools java.lang.NullPointerException at org.drools.reteoo.RuleTerminalNode
> ---------------------------------------------------------------------------
>
> Key: JBRULES-3390
> URL: https://issues.jboss.org/browse/JBRULES-3390
> Project: Drools
> Issue Type: Bug
> Security Level: Public(Everyone can see)
> Affects Versions: 5.3.0.Final
> Environment: eclipse 3.6, Drools 5.3, jdk1.6.0_25_x64
> Reporter: Alberto Rugnone
> Assignee: Mark Proctor
>
> My application has to monitor when a magnetic contact is activated and when it is contact released event has to be retracted. And viceversa. Here is my rule and the big null pointer I have. Any helps will be very appreciated! Thank you a lot!!
> rule "contact activated vs contact released" salience 0 no-loop true
> when
> $contact_activated : Event(type == EventType.CONTACT_ACTIVATED) ||
>
> $contact_released : Event(type == EventType.CONTACT_RELEASED)
> then
>
> if($contact_activated!= null) {
> retract($contact_activated);
> } else {
> retract($contact_released);
> }
> end
> and
> I have
> java.lang.NullPointerException
> at org.drools.reteoo.RuleTerminalNode$SortDeclarations.compare(RuleTerminalNode.java:477)
> at org.drools.reteoo.RuleTerminalNode$SortDeclarations.compare(RuleTerminalNode.java:473)
> at java.util.Arrays.mergeSort(Arrays.java:1270)
> at java.util.Arrays.sort(Arrays.java:1210)
> at org.drools.reteoo.RuleTerminalNode.<init>(RuleTerminalNode.java:119)
> at org.drools.RuleActivationListenerFactory.createActivationListener(RuleActivationListenerFactory.java:21)
> at org.drools.reteoo.builder.ReteooRuleBuilder.addSubRule(ReteooRuleBuilder.java:157)
> at org.drools.reteoo.builder.ReteooRuleBuilder.addRule(ReteooRuleBuilder.java:123)
> at org.drools.reteoo.ReteooBuilder.addRule(ReteooBuilder.java:110)
> at org.drools.reteoo.ReteooRuleBase.addRule(ReteooRuleBase.java:441)
> at org.drools.common.AbstractRuleBase.addRule(AbstractRuleBase.java:821)
> at org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:555)
> at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:458)
> at org.drools.impl.KnowledgeBaseImpl.addKnowledgePackages(KnowledgeBaseImpl.java:150)
> at it.ipiu.pch.sel.RuleTest.before(RuleTest.java:1272)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:27)
> at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:76)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:49)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list