ArithmeticException (Non-terminating decimal expansion) occurs in the executable model.

Solution Unverified - Updated -

Issue

In executable model, running rules written in MVEL dialect and containing a divide operation of BigDecimal values whose exact quotient has a nonterminating decimal expansion (e.g. 1/3 is 0.3333..., 10/11 is 0.9090...) causes ArithmeticException (Non-terminating decimal expansion).

For example, when running a rule like (*1) by giving a Fact object where value1 property is BigDecimal("1") and value2 is BigDecimal("3") in non-executable model, I can get a result like (*2) successfully.

(*1)

rule "Rule 1"
    dialect "mvel"
    when
        $fact : Fact( $value1 : value1, $value2 : value2 )
    then
        $fact.result = $value1 / $value2;
        System.out.println("Action of Rule 1: " + $fact);
end
// value1 and value2 are BigDecimal-type properties of Fact class.

(*2)

Action of Rule 1: com.example.reproducer.Fact[value1=1,value2=3,result=0.3333333333333333333333333333333333]

On the other hand, when running the same thing in executable model, the execution fails due to ArithmeticException like (*3) below.

(*3)

Exception executing consequence for rule "Rule 1" in com.example.reproducer: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
    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:1343)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1334)
    at org.drools.core.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:1318)
    at com.example.reproducer.DroolsTest.main(DroolsTest.java:24)
Caused by: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result.
    at java.base/java.math.BigDecimal.divide(BigDecimal.java:1722)
    at com.example.reproducer.P9E.LambdaConsequence9ED3D482DC0FFF72FA6A4480D1D7551F.execute(LambdaConsequence9ED3D482DC0FFF72FA6A4480D1D7551F.java:23)
    at com.example.reproducer.P9E.LambdaConsequence9ED3D482DC0FFF72FA6A4480D1D7551F.execute(LambdaConsequence9ED3D482DC0FFF72FA6A4480D1D7551F.java:1)
    at org.drools.model.functions.Block3$Impl.execute(Block3.java:40)
    at org.drools.modelcompiler.consequence.LambdaConsequence.evaluate(LambdaConsequence.java:75)
    at org.drools.core.phreak.RuleExecutor.innerFireActivation(RuleExecutor.java:455)
    ... 12 more

Environment

  • Red Hat Decision Manager (RHDM)
    • 7.10.0 - 7.12.0

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