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

issue with large array size inputs for JavaBigDecimalParser.parseBigDecimal #80

Closed
pjfanning opened this issue Sep 11, 2024 · 3 comments

Comments

@pjfanning
Copy link
Contributor

This relates to FasterXML/jackson-databind#4694 (comment)

A Jackson user hit an issue with the test case below. The JavaBigDecimalParser.parseBigDecimal call works for the String input but with the char array input, the wrong result is generated. The wrong value is -1.1000E-648.

    @Test
    void issueDatabind4694() {
        final String str = "-11000.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
        final BigDecimal expected = new BigDecimal(str);
        assertEquals(expected, JavaBigDecimalParser.parseBigDecimal(str));
        final char[] arr = str.toCharArray();
        assertEquals(expected, JavaBigDecimalParser.parseBigDecimal(arr, 0, arr.length));
    }
@cowtowncoder
Copy link

Without digging deeper, exception suggests like there was an off-by-one bug somewhere (one or more extra/missing digits).

@wrandelshofer
Copy link
Owner

Yes, this is a off-by-one bug. I have not properly kept up the code of the char-array implementations in sync with the byte-array and CharSequence implementations.

I am going to fix this asap.

wrandelshofer added a commit that referenced this issue Sep 13, 2024
…r.parseBigDecimal.

AbstractBigDecimalParserTest.java:
- Add a test for the input value that reproduces the problem.

JavaBigDecimalFromByteArray.java,
JavaBigDecimalFromCharArray.java,
JavaBigDecimalFromCharSequence.java:
- Fix the off-by-one issue in JavaBigDecimalFromCharArray.
- Harmonize the code in all 3 implementations.

Strings.java,
FftMultiplierTest.java,
JmhBigDecimalScalability.java,
JmhDoubleScalability.java,
JmhJavaBigIntegerFromByteArrayScalability.java,
JmhJavaDoubleFromCharSequenceScalability.java:
 - Implement a better method for creating Strings from repeated characters.
wrandelshofer added a commit that referenced this issue Sep 13, 2024
Fix issue #80: Bug in large array size inputs for JavaBigDecimalParse…
@wrandelshofer
Copy link
Owner

Fixed in #81

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

3 participants