-
Bug
-
Resolution: Fixed
-
P2
-
8u45, 9
-
b69
-
Verified
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8098647 | emb-9 | Tobias Hartmann | P2 | Resolved | Fixed | team |
JDK-8086536 | 8u65 | Tobias Hartmann | P2 | Resolved | Fixed | b01 |
JDK-8081054 | 8u60 | Andreas Eriksson | P2 | Closed | Fixed | b18 |
JDK-8137620 | emb-8u65 | Unassigned | P2 | Resolved | Fixed | b01 |
JDK-8086153 | emb-8u60 | Tobias Hartmann | P2 | Resolved | Fixed | team |
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Integer.toString(int value) sometimes throws a NullPointerException. I am not entirely certain what circumstances are required, but the attached source can reproduce the problem quite easily. Note that other test cases, where I'm not assigning random values, does not seem to reproduce the problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached code and run the test.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The test should complete without output.
ACTUAL -
An NPE is often thrown, and the value of the primitive that was attempted to be converted to a String is printed. The test terminates after the first NPE.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
NPE converting ??? to a String!
Exception in thread "main" java.lang.NullPointerException
at java.lang.Integer.getChars(Unknown Source)
at java.lang.Integer.toString(Unknown Source)
at IntegerToStringNPE.doStuff(IntegerToStringNPE.java:19)
at IntegerToStringNPE.main(IntegerToStringNPE.java:4)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class IntegerToStringNPE {
public static void main(String[] args) {
for (int i = 0; i < 1000000; i++) {
String a = doStuff();
}
}
public static String doStuff() {
int a = Integer.MIN_VALUE;
int bounds = (int) (Math.random() * 150);
for (int i = 0; i < bounds; i++) {
int random = (int) (Math.random() * 1000);
if (random > a) {
a = random;
}
}
try {
return Integer.toString(a);
} catch (NullPointerException e) {
System.err.println("NPE converting " + a + " to a String!");
throw e;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap the Integer.toString() call in a try/catch block. If an exception is caught, just make the call again. This doesn't guarantee that it will work on the second attempt, but it is extremely unlikely to fail.
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]
A DESCRIPTION OF THE PROBLEM :
Integer.toString(int value) sometimes throws a NullPointerException. I am not entirely certain what circumstances are required, but the attached source can reproduce the problem quite easily. Note that other test cases, where I'm not assigning random values, does not seem to reproduce the problem.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile the attached code and run the test.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The test should complete without output.
ACTUAL -
An NPE is often thrown, and the value of the primitive that was attempted to be converted to a String is printed. The test terminates after the first NPE.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
NPE converting ??? to a String!
Exception in thread "main" java.lang.NullPointerException
at java.lang.Integer.getChars(Unknown Source)
at java.lang.Integer.toString(Unknown Source)
at IntegerToStringNPE.doStuff(IntegerToStringNPE.java:19)
at IntegerToStringNPE.main(IntegerToStringNPE.java:4)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
public class IntegerToStringNPE {
public static void main(String[] args) {
for (int i = 0; i < 1000000; i++) {
String a = doStuff();
}
}
public static String doStuff() {
int a = Integer.MIN_VALUE;
int bounds = (int) (Math.random() * 150);
for (int i = 0; i < bounds; i++) {
int random = (int) (Math.random() * 1000);
if (random > a) {
a = random;
}
}
try {
return Integer.toString(a);
} catch (NullPointerException e) {
System.err.println("NPE converting " + a + " to a String!");
throw e;
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Wrap the Integer.toString() call in a try/catch block. If an exception is caught, just make the call again. This doesn't guarantee that it will work on the second attempt, but it is extremely unlikely to fail.
- backported by
-
JDK-8086153 Integer.toString(int value) sometimes throws NPE
-
- Resolved
-
-
JDK-8086536 Integer.toString(int value) sometimes throws NPE
-
- Resolved
-
-
JDK-8098647 Integer.toString(int value) sometimes throws NPE
-
- Resolved
-
-
JDK-8137620 Integer.toString(int value) sometimes throws NPE
-
- Resolved
-
-
JDK-8081054 Integer.toString(int value) sometimes throws NPE
-
- Closed
-
- duplicates
-
JDK-8060036 C2: CmpU nodes can end up with wrong type information
-
- Resolved
-
- relates to
-
JDK-8042786 Proper fix for 8032566
-
- Resolved
-
(1 duplicates, 1 relates to)