Hi all!
I noticed problems when using retract in rules. Thereby, I get sometimes
NullPointerExceptions like this (Drools Version 6.0.0.Beta1):
Exception executing consequence for rule "rule 6 - ts filter" in test:
java.lang.NullPointerException
at
org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at
org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1409)
at
org.drools.core.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1328)
at
org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1546)
at
org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:637)
at
org.drools.core.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:601)
at
org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:233)
at test.DroolsMain.insertEvent(DroolsMain.java:50)
at test.EventSender.run(EventSender.java:73)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.NullPointerException
at
org.drools.core.util.index.LeftTupleIndexHashTable.remove(LeftTupleIndexHashTable.java:381)
at org.drools.core.reteoo.NotNode.retractLeftTuple(NotNode.java:301)
at
org.drools.core.reteoo.CompositeLeftTupleSinkAdapter.doPropagateRetractLeftTuple(CompositeLeftTupleSinkAdapter.java:261)
at
org.drools.core.reteoo.CompositeLeftTupleSinkAdapter.propagateRetractRightTuple(CompositeLeftTupleSinkAdapter.java:172)
at org.drools.core.reteoo.JoinNode.retractRightTuple(JoinNode.java:181)
at
org.drools.core.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:344)
at
org.drools.core.reteoo.EntryPointNode.retractObject(EntryPointNode.java:406)
at
org.drools.core.common.NamedEntryPoint.delete(NamedEntryPoint.java:591)
at
org.drools.core.base.DefaultKnowledgeHelper.retract(DefaultKnowledgeHelper.java:429)
at
test.Rule_rule_6___ts_filter247591339.defaultConsequence(Rule_rule_6___ts_filter247591339.java:18)
at
test.Rule_rule_6___ts_filter247591339DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
test.Rule_rule_6___ts_filter247591339DefaultConsequenceInvoker.evaluate(Unknown Source)
at
org.drools.core.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1399)
... 8 more
Or, using Drools 5.5.1-SNAPSHOT
Exception executing consequence for rule "rule 3 - remove start stop fact" in
test: java.lang.NullPointerException
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1291)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1215)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1450)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
at test.DroolsMain.insertEvent(DroolsMain.java:50)
at test.EventSender.run(EventSender.java:73)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at
org.drools.base.DefaultKnowledgeHelper.retract(DefaultKnowledgeHelper.java:419)
at
test.Rule_rule_3___remove_start_stop_fact.defaultConsequence(Rule_rule_3___remove_start_stop_fact.java:8)
at
test.Rule_rule_3___remove_start_stop_factDefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
test.Rule_rule_3___remove_start_stop_factDefaultConsequenceInvoker.evaluate(Unknown
Source)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1281)
... 8 more
The problematic rules mostly look something like this:
rule "rule 6 - ts filter"
agenda-group "evaluation"
when
$evtA : Event(type == EventType.START) from entry-point "InputStream"
$evtB : Event(type == EventType.START, this after $evtA, this != $evtA, senderId ==
$evtA.senderId) from entry-point "InputStream"
then
//do something
//...
retract($evtA);
end
The exception does not immediately occur. Sometimes it occurs sooner, sometimes it takes
longer until it occurs. When the exception is thrown, it looks like that the event is not
removed from the knowledge base (I watch the number of events in the knowledge base - fact
count). I made the experience that this problem only occurs when the rule file grows (e.g.
when there are more than 10 rules to execute) and when the load increases. To work
temporarily around this problem, I set the java process to use only 1 processor in the
windows task manager - which looks like this is a multi threading issue.
I can reproduce this exception with the Drools versions 5.5.0, 5.5.1-SNAPSHOT and
6.0.0.Beta1. I did not test the previous versions explicitly.
Please find attached a small dummy test application to reproduce this problem. Execute
therefore the main method from the class "test.DroolsMain". Depending on your
machine and load, the problem occurs sometimes sooner or sometimes later. Or, you might
notice some other exception, but the problem when retracting events or facts is currently
the biggest one in my productive applications.
Best regards,
Wolfgang
Show replies by date