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

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

Comments

@spring-projects-issues
Copy link
Collaborator

@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
http://stackoverflow.com/questions/35822941/numberutils-throws-exception-when-convert-a-bigdecimal-to-long-but-sucess-when-c

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

@spring-projects-issues
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.

Juergen

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

No branches or pull requests

2 participants