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

Strange bug in assignment #313

Open
magicprinc opened this issue Oct 22, 2022 · 1 comment
Open

Strange bug in assignment #313

magicprinc opened this issue Oct 22, 2022 · 1 comment

Comments

@magicprinc
Copy link

magicprinc commented Oct 22, 2022

JDK 17

MVEL evaluates

obj.bigDecimalField = Long.valueOf('999999999999999999');

as 1000000000000000000

Example:

    public void testBugReport () {
        final String bigValue = "999999999999999999";
        MyObj obj = new MyObj();
        final String expr = "obj.bigDecimalField = bigValue";

        MVEL.eval(expr, Map.of("obj", obj, "bigValue", bigValue));
        assertEquals(bigValue, obj.bigDecimalField.toString());// OK

        assertEquals(bigValue, new BigDecimal(Long.valueOf(bigValue).toString()).toString());// OK bug not in JDK

        MVEL.eval(expr, Map.of("obj", obj, "bigValue", Long.valueOf(bigValue)));
        assertEquals(bigValue, obj.bigDecimalField.toString());// Failure
        // Expected :999999999999999999
        // Actual   :1000000000000000000
    }

    /** POJO for testing of copying values between Fields and domain objects */
    public static class MyObj {
      BigDecimal bigDecimalField;
      BigInteger bigIntegerField;

      public void setBigDecimalField (BigDecimal v) { bigDecimalField = v;}

      public void setBigIntegerField (BigInteger v) { bigIntegerField = v;}
    }
magicprinc added a commit to magicprinc/Apache-Click that referenced this issue Oct 22, 2022
@magicprinc
Copy link
Author

Any chance?

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