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

npe when parsing valid bigdecimal #77

Closed

Conversation

pjfanning
Copy link
Contributor

@pjfanning pjfanning commented Dec 10, 2023

Adds test case based on FasterXML/jackson-core#1162

Only seems to have when char[] or byte[] is passed, not when String input is used.

java.lang.NullPointerException: Cannot invoke "java.util.Map.get(Object)" because "powersOfTen" is null
	at ch.randelshofer.fastdoubleparser.ParseDigitsTaskCharArray.parseDigitsRecursive(ParseDigitsTaskCharArray.java:82)
	at ch.randelshofer.fastdoubleparser.JavaBigDecimalFromCharArray.valueOfBigDecimalString(JavaBigDecimalFromCharArray.java:305)
	at ch.randelshofer.fastdoubleparser.JavaBigDecimalFromCharArray.parseBigDecimalStringWithManyDigits(JavaBigDecimalFromCharArray.java:241)
	at ch.randelshofer.fastdoubleparser.JavaBigDecimalFromCharArray.parseBigDecimalString(JavaBigDecimalFromCharArray.java:41)
	at ch.randelshofer.fastdoubleparser.JavaBigDecimalParser.parseBigDecimal(JavaBigDecimalParser.java:197)
	at ch.randelshofer.fastdoubleparser.JavaBigDecimalParser.parseBigDecimal(JavaBigDecimalParser.java:178)
	at ch.randelshofer.fastdoubleparser.JavaBigDecimalLargeInputTest.testLongValidStringFastParse(JavaBigDecimalLargeInputTest.java:18)

The NPE happens because the following line passes a null value (explicitly) for the powersOfTen param.

fractionalPart = ParseDigitsTaskCharArray.parseDigitsRecursive(str, decimalPointIndex + 1, exponentIndicatorIndex, null);

The ParseDigitsTaskCharArray.parseDigitsRecursive method cannot handle null values for this param.

Edit: I have changed the code in this PR to call ParseDigitsTaskCharArray.parseDigitsInteractive instead.

Update JavaBigDecimalLargeInputTest.java
@wrandelshofer
Copy link
Owner

Thank you very much for this pull request.
Unfortunately the suggested fix is incomplete.
We have to replace all calls to parseDigitsRecursive with last argument null by calls to parseDigitsIterative.
I am going to fix this.

@pjfanning
Copy link
Contributor Author

Thanks @wrandelshofer - I added an extra commit but feel free to ignore this PR and look at your own fix.

@wrandelshofer
Copy link
Owner

I have fixed it know. The fix is in the main branch.
The main branch should be good for use in rev 6080865

@pjfanning pjfanning deleted the npe-for-valid-bigdec-chararray branch December 10, 2023 19:16
@cowtowncoder
Copy link

Thank you @wrandelshofer for such a quick fix!

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.

None yet

3 participants