FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
A DESCRIPTION OF THE PROBLEM :
The following simple example code leads to a NullPointerException:
import java.util.function.Supplier;
public class MethodReferenceNpeTest {
public static void main(String[] args) {
Object object = createObject();
Supplier<String> supplier = object::toString;
if (object != null) {
System.out.println(supplier.get());
}
}
private static Object createObject() {
return null;
}
}
RESULT :
After compiling it with javac and running it, following NPE occurs:
Exception in thread "main" java.lang.NullPointerException
at de.fhg.iwes.ui.vpp.MethodReferenceNpeTest.main(MethodReferenceNpeTest.java:9)
-- Compiling the same code with the eclipse compiler doesn't lead to a NPE
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
A DESCRIPTION OF THE PROBLEM :
The following simple example code leads to a NullPointerException:
import java.util.function.Supplier;
public class MethodReferenceNpeTest {
public static void main(String[] args) {
Object object = createObject();
Supplier<String> supplier = object::toString;
if (object != null) {
System.out.println(supplier.get());
}
}
private static Object createObject() {
return null;
}
}
RESULT :
After compiling it with javac and running it, following NPE occurs:
Exception in thread "main" java.lang.NullPointerException
at de.fhg.iwes.ui.vpp.MethodReferenceNpeTest.main(MethodReferenceNpeTest.java:9)
-- Compiling the same code with the eclipse compiler doesn't lead to a NPE
- relates to
-
JDK-8131323 java.lang.NullPointerException when lambda replaced by method reference
- Closed