<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7651.59">
<TITLE>Null Pointer Exception in "org.drools.reteoo.RuleTerminalNode.retractTuple"</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<P><FONT SIZE=2 FACE="Arial">Hi - me again :-(</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Unfortunately I receive a NPE (3.1-M1) as follows (a complete JAR illustrating the problem is available):-</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">**Java</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">Man man=</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Man();</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">Machine machine=</FONT><B><FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Machine();</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">Process p =</FONT><B> <FONT COLOR="#7F0055" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> Process();</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.assertObject(man);</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.assertObject(machine);</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">wm.assertObject(p);</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">**Rules</FONT>
</P>
<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">package</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> drools.debug</FONT>
</P>
<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">"Rule-1"</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">no-loop</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">true</FONT></B>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">$p : Process()</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">"DEBUG [Rule-1]---> Add ProcessAlternative to Process"</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">ProcessAlternative pa =</FONT><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> ProcessAlternative();</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">$p.addProcessAlternative(pa);</FONT>
<BR> <B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">assert</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New">(pa);</FONT>
<BR> <B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">modify</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New">($p);</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">e</FONT><FONT COLOR="#960000" SIZE=2 FACE="Courier New">nd</FONT></B>
</P>
<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">"Rule-2"</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">no-loop</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">true</FONT></B>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">$m : Machine()</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">"DEBUG [Rule-2]---> Add Machine to MachineEntry"</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">MachineEntry me =</FONT><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">new</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"> MachineEntry();</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">me.setMachine($m);</FONT>
<BR> <B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">assert</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New">(me);</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">end</FONT></B>
</P>
<P><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">rule</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT> <FONT COLOR="#008000" SIZE=2 FACE="Courier New">"Rule-3"</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">no-loop</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New"></FONT><B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">true</FONT></B>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">when</FONT></B>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">$me : MachineEntry()</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">$pa : ProcessAlternative()</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">then</FONT></B>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">System.out.println(</FONT><FONT COLOR="#008000" SIZE=2 FACE="Courier New">"DEBUG [Rule-3]---> Add MachineEntry to ProcessAlternative"</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">);</FONT>
<BR> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">$pa.addMachineEntry($me);</FONT>
<BR> <B> <FONT COLOR="#960000" SIZE=2 FACE="Courier New">modify</FONT></B><FONT COLOR="#000000" SIZE=2 FACE="Courier New">($pa);</FONT>
<BR><B><FONT COLOR="#960000" SIZE=2 FACE="Courier New">end</FONT></B>
</P>
<P><FONT COLOR="#808000" SIZE=2 FACE="Courier New">//rule "Rule-4 (Null Pointer Exception)</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">"</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">//no-loop tru</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">e</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">//whe</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">n</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">// $h : Man (</FONT> <FONT COLOR="#808000" SIZE=2 FACE="Courier New">)</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">// $m : Machine (</FONT> <FONT COLOR="#808000" SIZE=2 FACE="Courier New">)</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">// $mte : MachineEntry ( machine == $m</FONT> <FONT COLOR="#808000" SIZE=2 FACE="Courier New">)</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">//the</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">n</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">// System.out.println("DEBUG [Rule</FONT> <FONT COLOR="#808000" SIZE=2 FACE="Courier New">4</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">]---> Assigned resource")</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">;</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">// $m.setManualResource($h)</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">;</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">// modify($m)</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">;</FONT>
<BR><FONT COLOR="#808000" SIZE=2 FACE="Courier New">//en</FONT><FONT COLOR="#808000" SIZE=2 FACE="Courier New">d</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">**Output</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">DEBUG [Rule-1]---> Add ProcessAlternative to Process</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">DEBUG [Rule-2]---> Add Machine to MachineEntry</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">DEBUG [Rule-3]---> Add MachineEntry to ProcessAlternative</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">This is what I'd expect. If however rule "Rule-4" is uncommented the output is:-</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Courier New">DEBUG [Rule-1]---> Add ProcessAlternative to Process</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">DEBUG [Rule-2]---> Add Machine to MachineEntry</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">DEBUG [Rule-3]---> Add MachineEntry to ProcessAlternative</FONT>
<BR><FONT COLOR="#000000" SIZE=2 FACE="Courier New">DEBUG [Rule</FONT> <FONT COLOR="#000000" SIZE=2 FACE="Courier New">4</FONT><FONT COLOR="#000000" SIZE=2 FACE="Courier New">]---> Assigned resource</FONT>
<BR><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">DEBUG [Rule-2]---> Add Machine to MachineEntry</FONT> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New"><-- Why activated? no-loop is true</FONT>
<BR><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">DEBUG [Rule</FONT> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">4</FONT><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">]---> Assigned resource</FONT> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New"><-- Presumably activated as a consequence of above</FONT>
</P>
<P><FONT COLOR="#000000" SIZE=2 FACE="Arial">And I receive a NPE with the following stack trace:-</FONT>
</P>
<P><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">java.lang.NullPointerException</FONT></U>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.RuleTerminalNode.retractTuple(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">RuleTerminalNode.java:267</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.SingleTupleSinkAdapter.propagateRetractTuple(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">SingleTupleSinkAdapter.java:38</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.JoinNode.retractTuple(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">JoinNode.java:217</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.SingleTupleSinkAdapter.propagateRetractTuple(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">SingleTupleSinkAdapter.java:38</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.JoinNode.retractObject(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">JoinNode.java:183</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.CompositeObjectSinkAdapter.propagateRetractObject(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">CompositeObjectSinkAdapter.java:369</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.ObjectTypeNode.retractObject(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">ObjectTypeNode.java:189</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.Rete.retractObject(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">Rete.java:171</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.ReteooRuleBase.retractObject(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">ReteooRuleBase.java:215</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.reteoo.ReteooWorkingMemory.doRetract(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">ReteooWorkingMemory.java:76</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.common.AbstractWorkingMemory.modifyObject(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">AbstractWorkingMemory.java:940</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.base.DefaultKnowledgeHelper.modifyObject(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">DefaultKnowledgeHelper.java:95</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at drools.debug.Rule_Rule_4__Null_Pointer_Exception__0.consequence(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">Rule_Rule_4__Null_Pointer_Exception__0.java:8</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT></P>
<P> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at drools.debug.Rule_Rule_4__Null_Pointer_Exception__0ConsequenceInvoker.evaluate(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">Rule_Rule_4__Null_Pointer_Exception__0ConsequenceInvoker.java:24</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT></P>
<P> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.common.DefaultAgenda.fireActivation(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">DefaultAgenda.java:467</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.common.DefaultAgenda.fireNextItem(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">DefaultAgenda.java:431</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
<BR> <FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">at org.drools.common.AbstractWorkingMemory.fireAllRules(</FONT><U><FONT COLOR="#000080" SIZE=2 FACE="Courier New">AbstractWorkingMemory.java:360</FONT></U><FONT COLOR="#FF0000" SIZE=2 FACE="Courier New">)</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">I have also encountered NPE in "org.drools.reteoo.AlphaNode.retractObject" when using my actual rules other than these simplifications put together to demonstrate the error (both are caused by a call to "final Activation activation = tuple.getActivation();" returning NULL so I suspect the root cause to be common). Is this a case for a new JIRA entry or have I done something idiotic?</FONT></P>
<P><FONT SIZE=2 FACE="Arial">With kind regards,</FONT>
</P>
<P><FONT SIZE=2 FACE="Arial">Mike</FONT>
</P>
</BODY>
</HTML>