Once constraints containing remainder (%) operation for BigDecimal value like (*1-1) or (*1-2) are jitted, the constraints return incorrect result. The ConditionEvaluator<hash> class generated by ClassGenerator from (*1-1) is like (*2) and no remainder operation is seen in the code. (*3) is an example class generated by ClassGenerator from a constraint using '+' operator. Remainder operation for BigDecimal value should correctly jitted as well as the four basic operations '+', '-', '*', '/'.
(*1)
package com.example.reproducer import java.math.BigDecimal rule "rule_jitting_1b_51" when $fact : Fact( $value : (value % 10) == 0 ) // ..... (*1-1) then System.out.println("***** rule_jitting_1b_51: value = " + $fact.getValue() + ", $value = " + $value); end rule "rule_jitting_1b_52" when $fact : Fact( $value : (value % 10) != 0 ) // ..... (*1-2) then System.out.println("***** rule_jitting_1b_52: value = " + $fact.getValue() + ", $value = " + $value); end // Fact#value is a BigDecimal property.
(*2) ConditionEvaluator class generated from (*1-1) in RHDM 7.10.0
public class ConditionEvaluator87fdcd4618d94c78a57b47ccb07d9a17 implements ConditionEvaluator { private static final String EXPRESSION = "(value % 10) == 0"; private final Declaration[] declarations; public boolean evaluate(InternalFactHandle internalFactHandle, InternalWorkingMemory internalWorkingMemory, Tuple tuple) { BigDecimal bigDecimal = ((Fact)internalFactHandle.getObject()).getValue(); BigDecimal bigDecimal2 = new BigDecimal("10"); BigDecimal bigDecimal3 = new BigDecimal("0"); return bigDecimal2 == null ? bigDecimal3 == null : (bigDecimal3 == null ? false : bigDecimal2.compareTo(bigDecimal3) == 0); } public ConditionEvaluator87fdcd4618d94c78a57b47ccb07d9a17(Declaration[] declarationArray) { this.declarations = declarationArray; } }
(*3) ConditionEvaluator class generated from constraint (value + 10) == 20 in RHDM 7.10.0
public class ConditionEvaluatorae4e42acc2d6478eb149671a9c714c32 implements ConditionEvaluator { private static final String EXPRESSION = "(value + 10) == 20"; private final Declaration[] declarations; public boolean evaluate(InternalFactHandle internalFactHandle, InternalWorkingMemory internalWorkingMemory, Tuple tuple) { BigDecimal bigDecimal = ((Fact)internalFactHandle.getObject()).getValue().add(new BigDecimal("10")); BigDecimal bigDecimal2 = new BigDecimal("20"); return bigDecimal == null ? bigDecimal2 == null : (bigDecimal2 == null ? false : bigDecimal.compareTo(bigDecimal2) == 0); } public ConditionEvaluatorae4e42acc2d6478eb149671a9c714c32(Declaration[] declarationArray) { this.declarations = declarationArray; } }