src/share/classes/java/lang/Long.java
Print this page
rev 9020 : 8030814: Long.parseUnsignedLong should throw exception on too large input
Summary: Change test for overflow of unsigned long
Reviewed-by: TBD
Contributed-by: Dmitry Nadezhin <dmitry.nadezhin@oracle.com>
*** 698,708 ****
int second = Character.digit(s.charAt(len - 1), radix);
if (second < 0) {
throw new NumberFormatException("Bad digit at end of " + s);
}
long result = first * radix + second;
! if (compareUnsigned(result, first) < 0) {
/*
* The maximum unsigned value, (2^64)-1, takes at
* most one more digit to represent than the
* maximum signed value, (2^63)-1. Therefore,
* parsing (len - 1) digits will be appropriately
--- 698,714 ----
int second = Character.digit(s.charAt(len - 1), radix);
if (second < 0) {
throw new NumberFormatException("Bad digit at end of " + s);
}
long result = first * radix + second;
! // final int GUARD_BIT = 7;
! // int guard = radix * (int) (first >>> (64 - GUARD_BIT));
! int guard = radix * (int) (first >>> 57);
! // if (guard >= (1 << GUARD_BIT) - Character.MAX_RADIX
! // && (guard >= (1 << GUARD_BIT) || result >= 0)) {
! if (guard >= 128 ||
! (result >= 0 && guard >= 128 - Character.MAX_RADIX)) {
/*
* The maximum unsigned value, (2^64)-1, takes at
* most one more digit to represent than the
* maximum signed value, (2^63)-1. Therefore,
* parsing (len - 1) digits will be appropriately