In non-executable model, when I assign an integer value to a BigDecimal-type variable, the type of the variable changes to Integer unexpectedly.

Solution Verified - Updated -

Issue

In non executable model, when I build a maven project containing rules like (*1), maven build fails with a ClassCastException like (*e1).
Specifically, when I assign an integer value to BigDecimal-type variable $value1 at line (*1-1), the ClassCastException (*e1) occurs at subsequent addition expression at line (*1-2).

(*1) Example rule

dialect "mvel"


rule "Rule 1"
    when
        $fact : Fact()
    then
        $value1 = $fact.value1;
        $value2 = $fact.value2;

        $value1 = 5;                   // <---------- (*1-1)

        $total = $value1 + $value2;    // <---------- (*1-2)

        System.out.println("$total = " + $total);
end
// Fact#value1 and Fact#value2 are both BigDecimal-type properties.

(*e1) Exception

Exception executing consequence for rule "Rule 1" in com.example.reproducer: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.math.BigDecimal (java.lang.Integer and java.math.BigDecimal are in module java.base of loader 'bootstrap')
    at org.drools.core.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
    at org.drools.core.common.DefaultAgenda.handleException(DefaultAgenda.java:1056)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:462)
    at org.drools.core.phreak.RuleExecutor.fireActivation(RuleExecutor.java:402)
    at org.drools.core.phreak.RuleExecutor.fire(RuleExecutor.java:158)
    at org.drools.core.phreak.RuleExecutor.evaluateNetworkAndFire(RuleExecutor.java:110)
    at org.drools.core.concurrent.AbstractRuleEvaluator.internalEvaluateAndFire(AbstractRuleEvaluator.java:33)
    at org.drools.core.concurrent.SequentialRuleEvaluator.evaluateAndFire(SequentialRuleEvaluator.java:43)
    at org.drools.core.common.DefaultAgenda.fireLoop(DefaultAgenda.java:869)
    at org.drools.core.common.DefaultAgenda.internalFireAllRules(DefaultAgenda.java:816)
    at org.drools.core.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:808)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.internalFireAllRules(StatefulKnowledgeSessionImpl.java:1341)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1332)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1316)
    at com.example.reproducer.DroolsTest.main(DroolsTest.java:25)
Caused by: java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.math.BigDecimal (java.lang.Integer and java.math.BigDecimal are in module java.base of loader 'bootstrap')
    at org.mvel2.math.MathProcessor.doOperations(MathProcessor.java:65)
    at org.mvel2.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:146)
    at org.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)
    at org.mvel2.ast.AssignmentNode.getReducedValueAccelerated(AssignmentNode.java:116)
    at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
    at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:115)
    at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:111)
    at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:105)
    at org.mvel2.MVEL.executeExpression(MVEL.java:946)
    at org.kie.soup.project.datamodel.commons.util.RawMVELEvaluator.executeExpression(RawMVELEvaluator.java:103)
    at org.drools.mvel.expr.MvelEvaluator.internalEvaluate(MvelEvaluator.java:131)
    at org.drools.mvel.expr.MvelEvaluator.evaluate(MvelEvaluator.java:115)
    at org.drools.mvel.expr.MVELConsequence.evaluate(MVELConsequence.java:94)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:455)
    ... 12 more

Environment

  • Red Hat Process Automation Manager (RHPAM)
    • 7.12.1 - 7.13.4
  • Red Hat Decision Manager (RHDM)
    • 7.12.1 - 7.13.4

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content