# HG changeset patch # User darcy # Date 1534353375 25200 # Node ID 8f7e3f9ddbc0a407672589d8cc2b85a167db464c # Parent 4699147a4f917f9e643f89412eeaad20cab0f9dd 8176425: Add radix indication in NumberFormatException message for Integer.decode Reviewed-by: lancea diff -r 4699147a4f91 -r 8f7e3f9ddbc0 src/java.base/share/classes/java/lang/Integer.java --- a/src/java.base/share/classes/java/lang/Integer.java Wed Aug 15 10:00:16 2018 -0700 +++ b/src/java.base/share/classes/java/lang/Integer.java Wed Aug 15 10:16:15 2018 -0700 @@ -635,11 +635,11 @@ negative = true; limit = Integer.MIN_VALUE; } else if (firstChar != '+') { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } if (len == 1) { // Cannot have lone "+" or "-" - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } i++; } @@ -649,17 +649,17 @@ // Accumulating negatively avoids surprises near MAX_VALUE int digit = Character.digit(s.charAt(i++), radix); if (digit < 0 || result < multmin) { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } result *= radix; if (result < limit + digit) { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } result -= digit; } return negative ? result : -result; } else { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } } @@ -745,7 +745,7 @@ } return negative ? result : -result; } else { - throw NumberFormatException.forInputString(""); + throw NumberFormatException.forInputString("", radix); } } @@ -842,7 +842,7 @@ } } } else { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } } diff -r 4699147a4f91 -r 8f7e3f9ddbc0 src/java.base/share/classes/java/lang/Long.java --- a/src/java.base/share/classes/java/lang/Long.java Wed Aug 15 10:00:16 2018 -0700 +++ b/src/java.base/share/classes/java/lang/Long.java Wed Aug 15 10:16:15 2018 -0700 @@ -675,11 +675,11 @@ negative = true; limit = Long.MIN_VALUE; } else if (firstChar != '+') { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } if (len == 1) { // Cannot have lone "+" or "-" - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } i++; } @@ -689,17 +689,17 @@ // Accumulating negatively avoids surprises near MAX_VALUE int digit = Character.digit(s.charAt(i++),radix); if (digit < 0 || result < multmin) { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } result *= radix; if (result < limit + digit) { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } result -= digit; } return negative ? result : -result; } else { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } } @@ -945,7 +945,7 @@ return result; } } else { - throw NumberFormatException.forInputString(s); + throw NumberFormatException.forInputString(s, radix); } } @@ -1063,7 +1063,7 @@ return result; } } else { - throw NumberFormatException.forInputString(""); + throw NumberFormatException.forInputString("", radix); } } diff -r 4699147a4f91 -r 8f7e3f9ddbc0 src/java.base/share/classes/java/lang/NumberFormatException.java --- a/src/java.base/share/classes/java/lang/NumberFormatException.java Wed Aug 15 10:00:16 2018 -0700 +++ b/src/java.base/share/classes/java/lang/NumberFormatException.java Wed Aug 15 10:16:15 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1994, 2012, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1994, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -61,8 +61,11 @@ * * @param s the input causing the error */ - static NumberFormatException forInputString(String s) { - return new NumberFormatException("For input string: \"" + s + "\""); + static NumberFormatException forInputString(String s, int radix) { + return new NumberFormatException("For input string: \"" + s + "\"" + + (radix == 10 ? + "" : + " under radix " + radix)); } /** diff -r 4699147a4f91 -r 8f7e3f9ddbc0 src/java.base/share/classes/java/lang/Package.java --- a/src/java.base/share/classes/java/lang/Package.java Wed Aug 15 10:00:16 2018 -0700 +++ b/src/java.base/share/classes/java/lang/Package.java Wed Aug 15 10:16:15 2018 -0700 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -286,7 +286,7 @@ for (int i = 0; i < sa.length; i++) { si[i] = Integer.parseInt(sa[i]); if (si[i] < 0) - throw NumberFormatException.forInputString("" + si[i]); + throw NumberFormatException.forInputString("" + si[i], 10); } String [] da = desired.split("\\.", -1); @@ -294,7 +294,7 @@ for (int i = 0; i < da.length; i++) { di[i] = Integer.parseInt(da[i]); if (di[i] < 0) - throw NumberFormatException.forInputString("" + di[i]); + throw NumberFormatException.forInputString("" + di[i], 10); } int len = Math.max(di.length, si.length);