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

[incubator-kie-drools] ArithmeticException: Non-terminating decimal e… #6250

Merged
merged 2 commits into from
Feb 14, 2025

Conversation

tkobayas
Copy link
Contributor

…xpansion with non-executable model after jitting
@tkobayas
Copy link
Contributor Author

GHA kogito-runtimes : Not related to this PR

2025-02-12T05:58:45.3603582Z [ERROR] org.kie.kogito.quarkus.workflows.PojoServiceIT.testPojo -- Time elapsed: 15.25 s <<< FAILURE!
2025-02-12T05:58:45.3604400Z java.lang.AssertionError:
2025-02-12T05:58:45.3604655Z
2025-02-12T05:58:45.3604805Z Expected size: 1 but was: 2 in:
2025-02-12T05:58:45.3605180Z {"age"=666, "name"="javierito"}

@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.

@@ -873,16 +875,20 @@ private void jitAritmeticOperation(Class<?> operationType, AritmeticOperator ope
try {
switch (operator) {
case ADD:
invoke(operationType.getMethod("add", operationType));
addMathContext();
Copy link
Contributor

@gitgabrio gitgabrio Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @tkobayas , thanks for the PR.

IIUC:

  1. the addMathContext() method has some kind of hidden side effect
  2. the invoke(operationType.getMethod("subtract", operationType, MathContext.class)); need that side effect, to work.
  3. this has to be replicated/duplicated for all the arithmetic operations

Would not be better to create a specific invoke method, to be called for arithmetic operations, that

  1. execute mv.visitFieldInsn(GETSTATIC, "java/math/MathContext", "DECIMAL128", "Ljava/math/MathContext;");
  2. execute invoke(operationType.getMethod("multiply", operationType, MathContext.class)); (with name of operation received from parameter:)

e.g. (inside ClassGenerator)

        protected final void invokeArithmeticaOperation(Class<?> operationType, String operation) throws NoSuchMethodException {
            mv.visitFieldInsn(GETSTATIC, "java/math/MathContext", "DECIMAL128", "Ljava/math/MathContext;");
            invoke(operationType.getMethod("operation", operationType, MathContext.class));
        }

What do you think ? Does this make sense ?

Copy link
Contributor Author

@tkobayas tkobayas Feb 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gitgabrio Thank you for the suggestion! Yes, it's better. I have refactored accordingly.

I also noticed that BigInteger needs to be handled differently. Updated with test cases.

Copy link
Contributor

@gitgabrio gitgabrio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx @tkobayas !

@tkobayas tkobayas merged commit 937aeab into apache:main Feb 14, 2025
10 checks passed
rgdoliveira pushed a commit to rgdoliveira/drools that referenced this pull request Feb 19, 2025
apache#6250)

* [incubator-kie-drools] ArithmeticException: Non-terminating decimal expansion with non-executable model after jitting

* - Refactor for invokeBigDecimalArithmeticOperation
- Add test for BigInteger
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

Successfully merging this pull request may close these issues.

3 participants