In the following test, the getDummyAge()
method should not be evaluated, because testage
variable is always null
.
public class IntegerTest {
@Test
public void intergerTestFailure() {
Integer testage = null;
Integer age = (testage != null) ? getDummyAge() : testage;
}
private int getDummyAge() {
return 0;
}
}
Though this throws an exception:
java.lang.NullPointerException at my.IntegerTest.intergerTestFailure(IntegerTest.java:18) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566)
Is this a jdk bug?