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

Justine Hlista justine at vsasset.com
Thu Jan 18 14:22:44 EST 2007


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)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20070118/ca16ef33/attachment.html 


More information about the rules-users mailing list