Hi Wolfgang,

   Can you please open a JIRA for this. 

   It seems the consequence is not properly managing the scope of $m. I.e., it must either cache it locally or queue the WMA until it executes completely.

   Thanks,
       Edson

On Fri, Feb 10, 2012 at 6:52 AM, Wolfgang Laun <wolfgang.laun@gmail.com> wrote:
5.3.0 Final.

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


_______________________________________________
rules-dev mailing list
rules-dev@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-dev




--
  Edson Tirelli
  JBoss Drools Core Development
  JBoss by Red Hat @ www.jboss.com