Fixing a drools regression

I am in the process of merging two applications. These applications have a similar structure and similar dependencies.
However, one of the applications uses Drools 5.4.0.Final because it needs an accumulate function which does not work in earlier versions. The other application runs fine using 5.3.1.Final but fails when updating to 5.4.

Though the exception is masked by other errors inside the application, some digging revealed the following:

java.lang.NullPointerException
at java.lang.String.<init>(String.java:177)
at org.mvel2.util.ErrorUtil.rewriteIfNeeded(ErrorUtil.java:12)
at org.mvel2.compiler.ExpressionCompiler._compile(ExpressionCompiler.java:302)
at org.mvel2.compiler.ExpressionCompiler.compile(ExpressionCompiler.java:62)
at org.mvel2.MVEL.compileExpression(MVEL.java:810)
at org.drools.base.mvel.MVELCompilationUnit.compile(MVELCompilationUnit.java:442)
at org.drools.base.mvel.MVELCompilationUnit.getCompiledExpression(MVELCompilationUnit.java:238)
at org.drools.rule.constraint.MvelConstraint.createMvelConditionEvaluator(MvelConstraint.java:173)
at org.drools.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:157)
at org.drools.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:124)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:137)
at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:141)
at org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:497)
at org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:382)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:235)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:240)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:337)
at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:298)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:888)
at org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:847)
at org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:269)
at org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:303)
...

Not nice.
Some debugging shows that the problem in the following rule:
rule "Check estimate values"
    when
        kb: Calculation(
            null == totalEstimateExVat || totalEstimateExVat <= 0 ||
            null == vatAmountEstimate || vatAmountEstimate < 0 ||
            Math.abs(totalEstimateExVat + vatAmountEstimate - totalEstimateWithVat) > .00001 )
    then
        validationException.addException("Estimate values are incorrect." );
end

Apparently, something changes in the way the expressions are evaluated. While it is a good practice in Java to do an equality test with the constant on the left (it avoids accidental assignment when typing = instead of ==), it seems that this coding style is no longer valid in Drools 5.4. Reverting the tests fixed the problem.

2 Comments

  1. Mario Fusco says:

    Hi Joachim,

    thanks for having found this. I am a developer of the Drools team and I am starting to give a look at this issue just now.

    If you will find other bugs in the future it will be very helpful (and will allow as to react in a more responsive way) if you could file the bug in our issue tracking system:

    https://issues.jboss.org/browse/JBRULES

    or at least send an email reporting the problem to our users mailing list:

    rules-users@lists.jboss.org

    Thanks again,
    Mario

  2. Mario Fusco says:

    I opened a ticket for this issue ( https://issues.jboss.org/browse/JBRULES-3627 ) and already fixed it. The fix will be available in the 5.5.0.Beta1 that we will release (hopefully) at the end of this week.

    Thanks again for having reported this.
    Mario

Leave a Reply

Your email address will not be published. Required fields are marked *

question razz sad evil exclaim smile redface biggrin surprised eek confused cool lol mad twisted rolleyes wink idea arrow neutral cry mrgreen

*