-
Type:
Bug
-
Resolution: Not an Issue
-
Priority:
P4
-
None
-
Affects Version/s: 11
-
Component/s: core-libs
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
Using the ternary operator to assign a value to an Integer variable results in a Nullpointer exception. If one part of this operator is a Optional.ofNullable((Integer)null).orElse(null) call, execution of this assignment will result in an exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compiling the given source code and execute it with "java OptionalTest"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Variable i been assigned value null.
ACTUAL -
Exception in thread "main" java.lang.NullPointerException
at OptionalTest.main(OptionalTest.java:6)
---------- BEGIN SOURCE ----------
import java.util.Optional;
public class OptionalTest {
public static void main(String[] args) {
final Integer i = false ? 0 : Optional.ofNullable((Integer)null).orElse(null);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using a if/else construct instead of a ternary operator will not result in this exception.
Using the ternary operator to assign a value to an Integer variable results in a Nullpointer exception. If one part of this operator is a Optional.ofNullable((Integer)null).orElse(null) call, execution of this assignment will result in an exception.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compiling the given source code and execute it with "java OptionalTest"
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Variable i been assigned value null.
ACTUAL -
Exception in thread "main" java.lang.NullPointerException
at OptionalTest.main(OptionalTest.java:6)
---------- BEGIN SOURCE ----------
import java.util.Optional;
public class OptionalTest {
public static void main(String[] args) {
final Integer i = false ? 0 : Optional.ofNullable((Integer)null).orElse(null);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Using a if/else construct instead of a ternary operator will not result in this exception.
- relates to
-
JDK-8240345 Ternary operator cause unnecessary unboxing
-
- Closed
-