When running the following rule multiple times,
rule "rule1" when $f : Fact( $bd : new BigDecimal(30), bd.compareTo(new BigDecimal($bd)) < 0) then System.out.println( "Rule ["+kcontext.getRule().getName()+"] is fired with fact:"+$f ); end
sometimes exception like the following happens once Constraint Jitting takes place.
java.lang.RuntimeException: Error evaluating constraint 'bd.compareTo($bd) < 0' in [Rule "rule2" in /home/Case/03083956/rh/constraintJittingTest/target/classes/com/sample/rules/Sample.drl] at org.drools.core.rule.constraint.MvelConstraint.evaluate(MvelConstraint.java:277) at org.drools.core.rule.constraint.MvelConstraint.isAllowed(MvelConstraint.java:225) at org.drools.core.reteoo.AlphaNode.assertObject(AlphaNode.java:139) at org.drools.core.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:503) at org.drools.core.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:401) at org.drools.core.reteoo.ObjectTypeNode.propagateAssert(ObjectTypeNode.java:329) at org.drools.core.phreak.PropagationEntry$Insert.propagate(PropagationEntry.java:161) at org.drools.core.phreak.PropagationEntry$Insert.execute(PropagationEntry.java:166) at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:96) at org.drools.core.phreak.SynchronizedPropagationList.flush(SynchronizedPropagationList.java:91) at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:1085) at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:1048) at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1040) at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1337) at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1328) at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1312) at com.sample.DroolsTest.main(DroolsTest.java:28) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:254) at java.lang.Thread.run(Thread.java:748) Caused by: [Error: bd.compareTo($bd): java.lang.Integer cannot be cast to java.math.BigDecimal] [Near : {... bd.compareTo($bd) < 0 ....}]
In this example rule, $bd is BigDecimal. Therefore, new BigDecimal($bd) is incorrect as Java syntax and Constraint Jitting is trying to generate appropriate constructor by org.mvel2.util.ParseTools#getBestConstructorCandidate
and this results depends on Class#getConstructors.
Customer reported the issue with RHDM7.7.1(mvel2-2.4.4.Final-redhat-00001) and
org.mvel2.util.ParseTools#getBestConstructorCandidate was improved by the following commit:
https://github.com/mvel/mvel/commit/6b8faadf042f2fc9c752148d432f2b678bdfab3e
But the issue still happens randomly even with the latest Mvel2 version because results of Class#getConstructors are not same always. Please run attached project named 'bd-constructor-check' several times. You would see different results even when running it with same JDK version/update.
- clones
-
DROOLS-6729 Exception happens randomly in specific rule after Constraint Jitting
- Closed