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

BigDecimal to Integer/Short/Byte should overflow like BigDecimal to Long does [SPR-14041] #18613

spring-projects-issues opened this issue Mar 11, 2016 · 1 comment
in: core type: enhancement


Copy link

@spring-projects-issues spring-projects-issues commented Mar 11, 2016

andyjojo opened SPR-14041 and commented

fix NumberUtils throws Exception when convert a BigDecimal to Long but sucess when convert to Integer

System.out.println(org.springframework.util.NumberUtils.convertNumberToTargetClass(new BigDecimal("18446744073709551611"), Integer.class));
System.out.println(org.springframework.util.NumberUtils.convertNumberToTargetClass(new BigDecimal("18446744073709551611"), Long.class));
first line returns -5 but second line throws exception java.lang.IllegalArgumentException: Could not convert number [18446744073709551611] of type [java.math.BigDecimal] to target class [java.lang.Long]: overflow

Is that the expect result of method org.springframework.util.NumberUtils.convertNumberToTargetClass?

Affects: 4.2.5

Reference URL: #990

Issue Links:

  • #16060 NumberUtils.convertNumberToTargetClass does not report overflow when converting BigInteger to Long

Referenced from: commits 1ca4340

Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Mar 18, 2016

Juergen Hoeller commented

I've addressed this in a slightly different fashion now, with a consistent long overflow check before we call Number.longValue() on the input.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
in: core type: enhancement
None yet

No branches or pull requests

2 participants