Preserve magnitude in BigInteger and BigDecimal locale converters (1.X)#403
Merged
Merged
Conversation
DecimalLocaleConverter.parse builds a DecimalFormat without enabling setParseBigDecimal, so a value past long/double range comes back from DecimalFormat.parse as a clamped Long or a lossy Double; the BigInteger and BigDecimal converters then derive their result from that Number and return it silently wrong (9999999999999999999 -> 9223372036854775807 for BigInteger, -> 1.0E+19 for BigDecimal). Add a protected isParseBigDecimal() hook (default false) and pass it to formatter.setParseBigDecimal; only BigIntegerLocaleConverter and BigDecimalLocaleConverter override it to true, so DecimalFormat returns a lossless BigDecimal for them while the narrowing Byte/Short/Integer/Long/ Float/Double converters stay on the Long/Double path. BigIntegerLocaleConverter converts the BigDecimal via toBigInteger(). Found by comparing the locale converters with the non-locale BigInteger/BigDecimal converters that parse the string directly.
7 tasks
Member
|
Thank you @rootvector2 , merged 🚀 |
garydgregory
added a commit
that referenced
this pull request
Jun 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Port of #401 to the
1.Xbranch.DecimalLocaleConverter.parsebuilds aDecimalFormatbut never enablessetParseBigDecimal, soDecimalFormat.parsereturns a clampedLong(when the value fits in long) or a lossyDouble(out of long range).BigIntegerLocaleConverterandBigDecimalLocaleConverterthen derive their result from thatNumber, so a value pastlong/doublerange comes back silently wrong:9999999999999999999becomes9223372036854775807forBigIntegerand1.0E+19forBigDecimal. The non-localeBigIntegerConverter/BigDecimalConverteravoid this by parsing the string directly.Added a protected
isParseBigDecimal()hook (defaultfalse) onDecimalLocaleConverterand pass it toformatter.setParseBigDecimal(...); onlyBigIntegerLocaleConverterandBigDecimalLocaleConverteroverride it totrue, soDecimalFormatreturns a losslessBigDecimalfor them while the narrowingByte/Short/Integer/Long/Float/Doubleconverters keep theLong/Doublepath.BigIntegerLocaleConverterconverts theBigDecimalviatoBigInteger().Added regression tests to
BigIntegerLocaleConverterTestandBigDecimalLocaleConverterTest; both fail without the runtime change (9223372036854775807and1.0E+19respectively).mvn test -Dtest='*LocaleConverterTest'is green (106 tests). The only failure in a fullmvnrun isLocaleBeanificationTest.testContextClassloaderIndependence, a pre-existing flake unrelated to this change (it fails the same way on a clean1.Xcheckout).mvn; that'smvnon the command line by itself.