If a field access that always throws NPE, e.g. ((Foo)null).f, is compiled by HotSpot then NPE is thrown regardless of whether Foo.f can be resolved or not. This differs from the behavior of the interpreter which always performs resolution before the null-check. Example: ======================= public class TestGet version 52:0 { public static Method main:"([Ljava/lang/String;)V" stack 5 locals 1 { aconst_null; getfield Field T.f:I; // T does not exist return; } } ======================= $ java -cp out/ TestGet Exception in thread "main" java.lang.NoClassDefFoundError: T at TestGet.main(TestGet.jasm) Caused by: java.lang.ClassNotFoundException: T at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:532) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:186) at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:473) ... 1 more $ java -cp out/ -Xcomp TestGet Exception in thread "main" java.lang.NullPointerException at TestGet.main(TestGet.jasm)
|