8267844: Replace Integer/Long.valueOf() with Integer/Long.parse*() where applicable

Reviewed-by: redestad
This commit is contained in:
Sergey Tsypanov 2021-08-12 10:03:52 +00:00 committed by Claes Redestad
parent d38b31438d
commit b29fbad940
6 changed files with 31 additions and 13 deletions

View file

@ -1254,7 +1254,7 @@ public final class Long extends Number
int radix = 10;
int index = 0;
boolean negative = false;
Long result;
long result;
if (nm.isEmpty())
throw new NumberFormatException("Zero length string");
@ -1284,15 +1284,15 @@ public final class Long extends Number
throw new NumberFormatException("Sign character in wrong position");
try {
result = Long.valueOf(nm.substring(index), radix);
result = negative ? Long.valueOf(-result.longValue()) : result;
result = parseLong(nm, index, nm.length(), radix);
result = negative ? -result : result;
} catch (NumberFormatException e) {
// If number is Long.MIN_VALUE, we'll end up here. The next line
// handles this case, and causes any genuine format error to be
// rethrown.
String constant = negative ? ("-" + nm.substring(index))
: nm.substring(index);
result = Long.valueOf(constant, radix);
result = parseLong(constant, radix);
}
return result;
}