Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8173373

C1: NPE is thrown instead of LinkageError when accessing inaccessible field on NULL receiver

    Details

    • Subcomponent:
    • Resolved In Build:
      b157
    • Verification:
      Verified

      Backports

        Description

        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)

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  thartmann Tobias Hartmann
                  Reporter:
                  slukyanov Stanislav Lukyanov (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  5 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: