Uploaded image for project: 'Drools'
  1. Drools
  2. DROOLS-7540

Coercion from Interger literal to BigDecimal bind variable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • None
    • 7.67.0.Final, 7.74.1.Final
    • core engine
    • None
    • 2023 Week 33-35 (from Aug 14), 2023 Week 36-38 (from Sep 4)
    • 4
    • NEW
    • NEW
    • ---
    • ---

      Issue Description:

      In non-exec-model,

      Where Fact.value1 and value2 are both BigDecimal,

          when
              $fact : Fact( $value1 : value1,
                            $value2 : value2 )
          then
              $value1 = 5;
              $total = $value1 + $value2;
      

       this rule fails with

      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')    <---------- (*2-4)
              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
      

      $value1 = 5; makes $value1 as Integer type.

      exec-model has no issue because `5` is coerced to a BigDecimal.

      Acceptance Criteria:

      • Run without an Exception.
      • Likely meet with the exec-model behaviour

              rhn-support-tkobayas Toshiya Kobayashi
              rhn-support-tkobayas Toshiya Kobayashi
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: