Thanks Dave.

I think the '||' on rule 1 is getting short-circuited. However, it is the '&&' on rule 2 that is not getting short circuited.

Kind regards
Meeraj

2010/7/16 David Sinclair <dsinclair@chariotsolutions.com>
Drools doesn't use short circuit evaluation, so all of those ORs are going to be evaluated. You may want to consider re-writing your rules or you can use MVEL's null safe navigation for this. dbtrAcct.?id == null, dbtrAcct.?id.?othr == nulll, etc.

dave



2010/7/16 Meeraj Kunnumpurath <mkunnumpurath@googlemail.com>
Hi,

I have the following rules,

global java.util.Set accountNumbers;

rule "rule 1"
when
    $d : Document()
    $c : CreditTransferTransactionInformation (dbtrAcct == null || dbtrAcct.id == null || dbtrAcct.id.othr == null || dbtrAcct.id.othr.id == null) from $d.cstmrCdtTrfInitn.cdtTrfTxInf
    $i : InternalInfo() from $c.internalInfo
then
    $i.setStatus(PaymentStatus.INVALID);
    $i.setErrorCode("PR002");
    $i.setAdditionalInfo("Account number is null");
end

rule "rule 2"
when
    $d : Document()
    $c : CreditTransferTransactionInformation(internalInfo.status != PaymentStatus.INVALID && dbtrAcct.id.othr.id not memberOf accountNumbers) from $d.cstmrCdtTrfInitn.cdtTrfTxInf
    $i : InternalInfo() from $c.internalInfo
then
    $i.setStatus(PaymentStatus.INVALID);
    $i.setErrorCode("PR002");
    $i.setAdditionalInfo("Account number not available in the routing table");
end

My assumption is rule 1 and rule 2 will be executed in the order they appear. Rule 1 checks all the nested attributes are not null and set the status as invalid if any of them is null. Rule 2 uses the and operator and checks the nested attribute is in the collection defined by the global, only if the object is valid. I assume the LHS of rule 2 will be short circuited if the object is invalid. However, if any of the nested property is null I get the following exception from MVEL.

Caused by: [Error: unable to access property (null parent): id]
[Near : {... Unknown ....}]
             ^
[Line: 1, Column: 0]
    at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:861)

Regards
Meeraj

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



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