KnowledgeBase using STREAM, running a stateful session in one thread, inserting events from another fact.
class Event{ String name; }
class Monitor{ Event event; String name; }
rule "start monitoring"
when
$e: Event($name: name)
not Monitor( name == $name )
then
insert( new Monitor( $e, $name ) );
end
rule "timeout"
timer( int: 10s )
when
$m: Monitor( name == $name )
$e: Event($name: name)
then
retract( $m ); // =======================
retract( $m.getEvent() ); // ========================
end
This order of retracts results in a NPE, see the dump below.
Reversing these two works correctly.
Exception in thread "main" Exception executing consequence for rule "start monitoring" in hashcode: java.lang.NullPointerException
at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at org.drools.common.DefaultAgenda.fireUntilHalt(DefaultAgenda.java:1229)
at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:753)
at org.drools.common.AbstractWorkingMemory.fireUntilHalt(AbstractWorkingMemory.java:729)
at org.drools.impl.StatefulKnowledgeSessionImpl.fireUntilHalt(StatefulKnowledgeSessionImpl.java:234)
at hashcode.Main.execute(Main.java:148)
at hashcode.Main.main(Main.java:206)
Caused by: java.lang.NullPointerException
at org.drools.base.hashcode.StateEvent42211789$getItemName.getValue(Unknown Source)
at org.drools.base.ClassFieldReader.getValue(ClassFieldReader.java:87)
at org.drools.rule.Declaration.getValue(Declaration.java:219)
at hashcode.Rule_start_monitoringDefaultConsequenceInvoker.evaluate(Unknown Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
... 7 more