[rules-users] help! asserting facts before reading rules?

Edson Tirelli tirelli at post.com
Thu Jan 18 15:42:22 EST 2007


   Hey Justine,

   You found a nice scenario! Seems a bug to me.

   Would you like to please open a JIRA for that attaching your test 
code and your comments? This way you can follow the resolution of the 
problem. I will investigate that.
   BTW, what version are you using?

   Thank you,
     Edson

Justine Hlista wrote:

> I have a dummy program that asserts 2 simple facts into working 
> memory, then reads a simple rule file into the rule base, then fires 
> the rules. I've attached the rules and the NullPointerException that 
> results.
>
> However, if I read the rules first then assert the facts, the program 
> runs fine.
>
> Alternatively, if I modify the second rule such that the modify occurs 
> before the retract, the program runs fine even if I assert the facts 
> first then read the rules.
>  
> In general, I may not be able to control when facts are asserted vs. 
> when rules are read in. Should this be a problem?
>
> Any hints greatly appreciated!!
>
> Thanks,
> Justine
>
> simple.drl:
>
> rule "setupFactC"
> no-loop true
>     when
>         a: factA(s:field1, i:field2, f:field3)
>         not c : factC(f1==s)
>     then
>         assert(s != null ? new factC(s, i, f) :
>                                   new factC());
> end
>
> rule "factBWithRetract"
> no-loop true
>     when
>         b : factB(s:f1, i:f2, f:f3)
>         a : factA(field1==s)
>         c : factC(f1==s)
>     then
>         c.setF3(f);
>         retract(b);
>         modify(c);
> end
>
> Stack trace:
> java.lang.NullPointerException
>     at 
> org.drools.base.com.vsasset.rules.isolate.factB$getF1.getValue(Unknown 
> Source)
>     at org.drools.base.ClassFieldExtractor.getValue (Unknown Source)
>     at org.drools.rule.Declaration.getValue(Unknown Source)
>     at org.drools.rule.BoundVariableConstraint.isAllowed(Unknown Source)
>     at org.drools.common.BetaNodeBinder.isAllowed(Unknown Source)
>     at org.drools.reteoo.JoinNode.modifyObject(Unknown Source)
>     at org.drools.reteoo.ObjectSource.propagateModifyObject(Unknown 
> Source)
>     at org.drools.reteoo.ObjectTypeNode.modifyObject(Unknown Source)
>     at org.drools.reteoo.Rete.modifyObject(Unknown Source)
>     at org.drools.reteoo.ReteooRuleBase.modifyObject(Unknown Source)
>     at org.drools.reteoo.ReteooWorkingMemory.modifyObject(Unknown Source)
>     at org.drools.base.DefaultKnowledgeHelper.modifyObject (Unknown 
> Source)
>     at 
> com.vsasset.rules.isolate.Rule_factBWithRetract_0.consequence(Rule_factBWithRetract_0.java:10)
>     at 
> com.vsasset.rules.isolate.Rule_factBWithRetract_0ConsequenceInvoker.evaluate(Rule_factBWithRetract_0ConsequenceInvoker.java:26) 
>
>     at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)
>     at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
>     at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown 
> Source)
>     at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown 
> Source)
>     at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
>     at com.vsasset.rules.isolate.TestCase.main(TestCase.java:36)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java 
> :25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
> Exception in thread "main" org.drools.spi.ConsequenceException: 
> java.lang.NullPointerException
>     at org.drools.common.DefaultAgenda.fireActivation(Unknown Source)
>     at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
>     at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown 
> Source)
>     at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown 
> Source)
>     at org.drools.common.AbstractRuleBase.addPackage(Unknown Source)
>     at com.vsasset.rules.isolate.TestCase.main(TestCase.java:36)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java 
> :25)
>     at java.lang.reflect.Method.invoke(Method.java:585)
>     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
>
>------------------------------------------------------------------------
>
>_______________________________________________
>rules-users mailing list
>rules-users at lists.jboss.org
>https://lists.jboss.org/mailman/listinfo/rules-users
>  
>


-- 
 Edson Tirelli
 Software Engineer - JBoss Rules Core Developer
 Office: +55 11 3124-6000
 Mobile: +55 11 9218-4151
 JBoss, a division of Red Hat @ www.jboss.com





More information about the rules-users mailing list