-
Enhancement
-
Resolution: Fixed
-
P4
-
22
-
Does not matter, JDK-22-ea+20
-
b21
-
generic
-
generic
We hit this bug with Lucene tests. When you parse an empty string with Integer#parseInt(""), it thros an NumberFormatException with an empty message.
Before the change inJDK-8317515 it was correctly using NumberFormatException#forInputString("",..) which creates a correct message like: java.lang.NumberFormatException: For input string: ""
Reproduce:
$ ./jdk-17.0.2/bin/jshell
| Welcome to JShell -- Version 17.0.2
| For an introduction type: /help intro
jshell> Integer.parseInt("");
| Exception java.lang.NumberFormatException: For input string: ""
| at NumberFormatException.forInputString (NumberFormatException.java:67)
| at Integer.parseInt (Integer.java:678)
| at Integer.parseInt (Integer.java:786)
| at (#1:1)
$ ./jdk-22/bin/jshell
| Willkommen bei JShell - Version 22-ea
| Geben Sie für eine Einführung Folgendes ein: /help intro
jshell> Integer.parseInt("");
| Ausnahme java.lang.NumberFormatException:
| at Integer.parseInt (Integer.java:565)
| at Integer.parseInt (Integer.java:685)
| at (#1:1)
This should be fixed because the exception message is the same since early times of Java and code may rely on this.
The fix is easy: Replace:
throw new NumberFormatException("")
by
throw NumberFormatException.forInputString("", radix);
at beginning of method.
Before the change in
Reproduce:
$ ./jdk-17.0.2/bin/jshell
| Welcome to JShell -- Version 17.0.2
| For an introduction type: /help intro
jshell> Integer.parseInt("");
| Exception java.lang.NumberFormatException: For input string: ""
| at NumberFormatException.forInputString (NumberFormatException.java:67)
| at Integer.parseInt (Integer.java:678)
| at Integer.parseInt (Integer.java:786)
| at (#1:1)
$ ./jdk-22/bin/jshell
| Willkommen bei JShell - Version 22-ea
| Geben Sie für eine Einführung Folgendes ein: /help intro
jshell> Integer.parseInt("");
| Ausnahme java.lang.NumberFormatException:
| at Integer.parseInt (Integer.java:565)
| at Integer.parseInt (Integer.java:685)
| at (#1:1)
This should be fixed because the exception message is the same since early times of Java and code may rely on this.
The fix is easy: Replace:
throw new NumberFormatException("")
by
throw NumberFormatException.forInputString("", radix);
at beginning of method.
- relates to
-
JDK-8317515 Unify the code of the parse*() families of methods in j.l.Integer and j.l.Long
- Resolved