Could you please provide some more details, such as a code snippet of your main and the version of Drools you are using?
This said, it seems to me that the only difference between the two rules is that the first uses "ArrayList( size < 1 ) from collect ...", while the other uses "not ....". They are essentially equivalent, so for each printout due to the first you should also see a printout due to the second. I would use a more traceable method in the RHS, such as adding the result messages to a global list in addition to printing them. Notice that Set(size>0) in your rules will cause a rule to fire again every time the size of the set changes, as long as it remains > 0. I suspect that you may want to try "exists" (the counterpart of not), which will cause a rule to evaluate only once. The "mixed" message/exception is almost certainly due to the IDE console. It would be extremely odd, instead, if some of your rules started printing out before you called fireAllRules(). On 04/25/2013 08:31 AM, burmanator wrote: > I am running 2 rules that are very similar but with a slight change: > > rule One > when > $foo : Foo($name : Name, $msg : Message !="") > $prev : ArrayList(size<1) from collect( Foo(Name==$name, Message == $msg, > this before $foo) > $list : Set(size>0) from accumulate( Foo(Name == $name, $msgs: Message != > $msg, this after $foo), collectSet($msgs)) > then > System.out.println($name + "\twent from \"" + $msg + "\"\tto " + $list); > end > > rule Two > when > $foo : Foo($name : Name, $msg : Message !="") > Not( Foo(Name==$name, Message == $msg, this before $foo)) > $list : Set(size>0) from accumulate( Foo(Name == $name, $msgs: Message != > $msg, this after $foo), collectSet($msgs)) > then > System.out.println($name + "\twent A from \"" + $msg + "\"\tto " + $list); > end > > rule One works just fine however its rule Two I seem to be having trouble > with. In my main method I have an initial print statement, then I go through > this whole process of parsing XML files into objects and then adding those > objects into the session. Once all the objects are entered I do a print out, > I then call fireAllRules on the session and then do another print out. > > When I use rule Two, my program starts firing the rules and displaying their > results almost immediately, even before the 2nd print out (sometimes even > before the first initial print out). Most of the time I get a Null Pointer > Exception but it does occasionally finish running. In the cases it does > finish it spits out the output from most of the rules then displays the 2nd > printout, the print out from a rule and then the ending print out. When it > does throw the null pointer exception I get: > > java.lang.NullPointerException > at org.drools.core.util.LinkedList.remove(LinkedList.java:133) > at > org.drools.common.DefaultAgenda.addActivation(DefaultAgenda.java.446) > at > org.drools.common.DefaultAgenda.modifyActivation(DefaultAgenda.java:382) > at > org.drools.reteoo.RuleTerminalNode.modifyLeftTuple(RuleTerminalNode.java:301) > at > org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateModifyChildLeftTuple(SingleLeftTupleSinkAdapter.java:259) > at > org.drools.reteoo.AccumulateNode.exaluateResultConstraints(AccumulateNode.java:676) > at > org.drools.reteoo.ReteooWorkingMemory$EvaluateResultConstraints.execute(ReteooWorkingMemory.java:590) > at > org.drools.common.PropagationContextImpl.evaluateActionQueue(PropagationContextimple:350) > at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:355) > at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:311) > at > org.drools.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:903) > at > org.drools.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847) > at > org.drools.imp.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269) > at test2.Engine2.main(Engine2.java:80) > > However sometimes when it throws the Null pointer exception, it prints out > some of the results of the rules in the middle of the display of the > exception, such as: > > java.lang.NullPointerExceptionName1 went A from "msg1" to [msg2] > Name2 went A from "msg1" to [msg2] > > at org.drools.core.util.LinkledList.remove(LinkedList.java.133) > and you know the rest. > > > When I run both rules together, for some reason it seems to run rule One > over the same name and message pair multiple times even though based on the > logic it should only run it based on the first occurrence. > > Also I don't know if this matters but there are 361,694 objects that are > entered into the session, 44,269 of which are Foo objects > > > > > > > -- > View this message in context: > http://drools.46999.n3.nabble.com/fusion-weird-race-conditions-and-a-null-pointer-exception-tp4023532.html > Sent from the Drools: User forum mailing list archive at Nabble.com. > _______________________________________________ > rules-users mailing list > [email protected] > https://lists.jboss.org/mailman/listinfo/rules-users > _______________________________________________ rules-users mailing list [email protected] https://lists.jboss.org/mailman/listinfo/rules-users
