Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArithmeticException: Non-terminating decimal expansion with non-executable model after jitting #6249

Closed
tkobayas opened this issue Feb 12, 2025 · 2 comments
Assignees

Comments

@tkobayas
Copy link
Contributor

  • non-executable model (= drools-engine-classic)
  • After jitting (= after evaluating the constraint 20 times)

A constraint like this fails, where value is BigDecimal

    Fact( value / 7B >= 0 )
 org.drools.mvel.ConstraintEvaluationException: Error evaluating constraint 'value / 7B >= 0' in [Rule "Rule 1" in /tmp/reproducer_arithmeticexception_1c/target/classes/com/example/reproducer/Sample.drl]
        at org.drools.mvel.MVELConstraint.evaluate(MVELConstraint.java:287)
        at org.drools.mvel.MVELConstraint.isAllowed(MVELConstraint.java:235)
        at org.drools.core.reteoo.AlphaNode.modifyObject(AlphaNode.java:145)
...
    Caused by: java.lang.ArithmeticException: Non-terminating decimal expansion; no exact representable decimal result. 
        at java.base/java.math.BigDecimal.divide(BigDecimal.java:1736)
        at ConditionEvaluator05169571c7d846e3b0c6e6e4439e0ef9.evaluate(Unknown Source)
        at org.drools.mvel.MVELConstraint.evaluate(MVELConstraint.java:285)
@tkobayas
Copy link
Contributor Author

In jitting, ASMConditionEvaluatorJitter generates bigDecimal1.divide(bigDecimal2) for / operation, which causes this ArithmeticException.

https://github.com/apache/incubator-kie-drools/blob/main/drools-mvel/src/main/java/org/drools/mvel/ASMConditionEvaluatorJitter.java#L885

Note: Mvel (= before jitting) and executable-model use bigDecimal1.divide(bigDecimal2, MathContext.DECIMAL128) for the calculation, so we should align with it.

@tkobayas
Copy link
Contributor Author

Fixed by #6250

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant