Hi - me again :-(
Unfortunately I receive a NPE (3.1-M1) as follows (a complete JAR
illustrating the problem is available):-
**Java
Man man=new Man();
Machine machine=new Machine();
Process p = new Process();
wm.assertObject(man);
wm.assertObject(machine);
wm.assertObject(p);
**Rules
package drools.debug
rule "Rule-1"
no-loop true
when
$p : Process()
then
System.out.println("DEBUG [Rule-1]---> Add ProcessAlternative to
Process");
ProcessAlternative pa = new ProcessAlternative();
$p.addProcessAlternative(pa);
assert(pa);
modify($p);
end
rule "Rule-2"
no-loop true
when
$m : Machine()
then
System.out.println("DEBUG [Rule-2]---> Add Machine to
MachineEntry");
MachineEntry me = new MachineEntry();
me.setMachine($m);
assert(me);
end
rule "Rule-3"
no-loop true
when
$me : MachineEntry()
$pa : ProcessAlternative()
then
System.out.println("DEBUG [Rule-3]---> Add MachineEntry to
ProcessAlternative");
$pa.addMachineEntry($me);
modify($pa);
end
//rule "Rule-4 (Null Pointer Exception)"
//no-loop true
//when
// $h : Man ( )
// $m : Machine ( )
// $mte : MachineEntry ( machine == $m )
//then
// System.out.println("DEBUG [Rule 4]---> Assigned resource");
// $m.setManualResource($h);
// modify($m);
//end
**Output
DEBUG [Rule-1]---> Add ProcessAlternative to Process
DEBUG [Rule-2]---> Add Machine to MachineEntry
DEBUG [Rule-3]---> Add MachineEntry to ProcessAlternative
This is what I'd expect. If however rule "Rule-4" is uncommented the
output is:-
DEBUG [Rule-1]---> Add ProcessAlternative to Process
DEBUG [Rule-2]---> Add Machine to MachineEntry
DEBUG [Rule-3]---> Add MachineEntry to ProcessAlternative
DEBUG [Rule 4]---> Assigned resource
DEBUG [Rule-2]---> Add Machine to MachineEntry <-- Why
activated? no-loop is true
DEBUG [Rule 4]---> Assigned resource <-- Presumably
activated as a consequence of above
And I receive a NPE with the following stack trace:-
java.lang.NullPointerException
at
org.drools.reteoo.RuleTerminalNode.retractTuple(RuleTerminalNode.java:26
7)
at
org.drools.reteoo.SingleTupleSinkAdapter.propagateRetractTuple(SingleTup
leSinkAdapter.java:38)
at org.drools.reteoo.JoinNode.retractTuple(JoinNode.java:217)
at
org.drools.reteoo.SingleTupleSinkAdapter.propagateRetractTuple(SingleTup
leSinkAdapter.java:38)
at org.drools.reteoo.JoinNode.retractObject(JoinNode.java:183)
at
org.drools.reteoo.CompositeObjectSinkAdapter.propagateRetractObject(Comp
ositeObjectSinkAdapter.java:369)
at
org.drools.reteoo.ObjectTypeNode.retractObject(ObjectTypeNode.java:189)
at org.drools.reteoo.Rete.retractObject(Rete.java:171)
at
org.drools.reteoo.ReteooRuleBase.retractObject(ReteooRuleBase.java:215)
at
org.drools.reteoo.ReteooWorkingMemory.doRetract(ReteooWorkingMemory.java
:76)
at
org.drools.common.AbstractWorkingMemory.modifyObject(AbstractWorkingMemo
ry.java:940)
at
org.drools.base.DefaultKnowledgeHelper.modifyObject(DefaultKnowledgeHelp
er.java:95)
at
drools.debug.Rule_Rule_4__Null_Pointer_Exception__0.consequence(Rule_Rul
e_4__Null_Pointer_Exception__0.java:8)
at
drools.debug.Rule_Rule_4__Null_Pointer_Exception__0ConsequenceInvoker.ev
aluate(Rule_Rule_4__Null_Pointer_Exception__0ConsequenceInvoker.java:24)
at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:467)
at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:431)
at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemo
ry.java:360)
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?
With kind regards,
Mike