Unknown lookups in the java package give misleading compilation errors

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P5
    • 17
    • Affects Version/s: 11, 16
    • Component/s: tools
    • None
    • b20

      During work on JDK-8263900 I discovered that the error produced when selecting .class on an unknown/misspelled type gave an odd error:

      % javac -version
      javac 16

      % cat X.java
      public class X {
          void x() {
              Class c = java.lang.class;
          }
      }

      % javac X.java
      X.java:3: error: package java does not exist
              Class c = java.lang.class;
                            ^
      1 error
      I get the same confusing error with e.g. "new java.lang()"

      This bug goes back to at least Java 11, but Java 8 u232 appears to get it right, explaining that there's no java.lang class in those cases. I haven't bisected the exact cause, but I'm assuming that it may have been related to (or obscured by) access checkes introduced in module system.

      I believe the problem is the same as in JDK-8264216 which is specific to Valhalla -- a PR with a fix is underway.

            Assignee:
            Jesper Møller
            Reporter:
            Jesper Møller
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: