Binding a variable to a fact in a branch of an 'or' (as you are doing with EtsExecutionOrderXref_core00) is not useful, since you cannot use this binding in the consequence. (The rule might just as well fire due to the 2nd term (the "or not...") being true, and then the variable would not be bound, causing NPE.

If you do need this binding to access the fact in the consequence, you should splt the rule.

-W

2009/12/2 Shah, Malay <Malay.Shah@morganstanley.com>
Thanks Mark. I removed the binding and the rule is compiled now, but while firing the rule over set of objects, I get a Null pointer exception.
Here is the updated Drool rule:
 
dialect "mvel"
rule "Legacy ETSDB Rule"
when
        EtsExecutionOrderHist_core0:EtsExecutionOrderHist_core(customerOrFirm != "0")
        EtsExecutionOrderXref_core00:EtsExecutionOrderXref_core
        (
            entityOID == EtsExecutionOrderHist_core0.entityOID,
            entityRID == EtsExecutionOrderHist_core0.entityRID,
            entityVID == EtsExecutionOrderHist_core0.entityVID,
            referenceID != "2" && referenceIDType == "orderSubCapacity"
        )
        or
        not(EtsExecutionOrderXref_core
                (
                    entityOID == EtsExecutionOrderHist_core0.entityOID,
                    entityRID == EtsExecutionOrderHist_core0.entityRID,
                    entityVID == EtsExecutionOrderHist_core0.entityVID,
                    referenceIDType == "orderSubCapacity"
                )
            )
then
    System.out.println("Rule fired");
end
 
and here is the stack trace:
 
Exception in thread "main" org.drools.runtime.rule.ConsequenceException: java.lang.NullPointerException
 at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
 at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
 at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
 at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
 at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
 at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:637)
 at org.drools.reteoo.ReteooStatelessSession.execute(ReteooStatelessSession.java:203)
 at com.ms.ruleutils.RuleProcessor.process(RuleProcessor.java:142)
 at com.ms.ruleutils.RuleProcessor.process(RuleProcessor.java:73)
 at com.ms.ieddata.dataQuality.dqWithRR.DQCommandLineMain.performDQ(DQCommandLineMain.java:291)
 at com.ms.ieddata.dataQuality.dqWithRR.DQCommandLineMain.runEngine(DQCommandLineMain.java:196)
 at com.ms.ieddata.dataQuality.dqWithRR.DQCommandLineMain.main(DQCommandLineMain.java:170)
Caused by: java.lang.NullPointerException
 at org.drools.base.mvel.DroolsMVELFactory.getTupleObjectFor(DroolsMVELFactory.java:182)
 at org.drools.base.mvel.DroolsMVELFactory.setContext(DroolsMVELFactory.java:176)
 at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:57)
 at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
 ... 10 more
 
After debugging through, DroolMVELFactory class object is looking for Declaration definition for "EtsExecutionOrderXref_core00", not finding it, and hence giving a null pointer exception. I am using Drools 5.0.1. Any idea about why this would happen? Does the rule seem right now?
Thanks
 
Malay Shah

 

From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Mark Proctor
Sent: Tuesday, December 01, 2009 6:56 PM
To: Rules Users List
Subject: Re: [rules-users] Drool Rule Error with "or not" condition

You are binding the result of the 'or' to EtsExecutionOrderXref_core00 as the second part is a 'not' which returns nothing, how would it be bound to?

Shah, Malay wrote:
Hi All,
 
I have the following drool rule that has "or not" under Entity Block. Basically, the rule tries to check if there either exists an entity object EtsExecutionOrderXref_core00 with the given conditions, or the entity does not exist at all with some other conditions. 
 
dialect "mvel"
rule "Legacy ETSDB Rule"
when
EtsExecutionOrderHist_core0:EtsExecutionOrderHist_core(customerOrFirm != "0")
EtsExecutionOrderXref_core00:
(
 EtsExecutionOrderXref_core
 (
  entityOID == EtsExecutionOrderHist_core0.entityOID , entityRID == EtsExecutionOrderHist_core0.entityRID , entityVID == EtsExecutionOrderHist_core0.entityVID , referenceID != "2" && referenceIDType == "orderSubCapacity"
 )
 or not(EtsExecutionOrderXref_core
 (
  entityOID == EtsExecutionOrderHist_core0.entityOID , entityRID == EtsExecutionOrderHist_core0.entityRID , entityVID == EtsExecutionOrderHist_core0.entityVID , referenceIDType == "orderSubCapacity"
 ))
)
then
end
 
But, while compiling the rule, I am getting the following errors:
 
org.drools.compiler.DroolsParserException: [ERR 101] Line 22:16 no viable alternative at input 'entityOID' in rule "Legacy ETSDB Rule" in pattern not,

org.drools.compiler.DroolsParserException: [ERR 102] Line 22:68 mismatched input ',' expecting '(' in rule "Legacy ETSDB Rule" in pattern EtsExecutionOrderHist_core0.entityOID,

org.drools.compiler.DroolsParserException: [ERR 102] Line 22:122 mismatched input ',' expecting '(' in rule "Legacy ETSDB Rule" in pattern EtsExecutionOrderHist_core0.entityOID in pattern EtsExecutionOrderHist_core0.entityRID,

org.drools.compiler.DroolsParserException: [ERR 102] Line 22:176 mismatched input ',' expecting '(' in rule "Legacy ETSDB Rule" in pattern EtsExecutionOrderHist_core0.entityOID in pattern EtsExecutionOrderHist_core0.entityRID in pattern EtsExecutionOrderHist_core0.entityVID]

I think the rule is correct, but am not able to figure out these compilation errors. Could anybody please comment on why this would happen?
 
Thanks
 
Malay Shah

NOTICE: If received in error, please destroy, and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. We may monitor and store emails to the extent permitted by applicable law.


_______________________________________________ rules-users mailing list rules-users@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-users


NOTICE: If received in error, please destroy, and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. We may monitor and store emails to the extent permitted by applicable law.


_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users