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

Binary names of local & inner classes can be referenced

XMLWordPrintable

      It should never be possible to refer to a local class or member class using a binary name, because that name is not in scope (JLS 6.3).

      Compile this:

      public class Declarations {

          public static class Inner {}
          
          static void m() {
              class Local {}
          }
      }

      Then compile this (with previously-generated classes on the class path):

      public class Uses {

          Declarations$Inner y;
          Declarations$1Local x;
          
          static class SubInner extends Declarations$Inner {}
          static class SubLocal extends Declarations$1Local {}
          
          Object o2 = new Declarations$Inner() {};
          Object o1 = new Declarations$1Local() {};

      }

      I get 2 errors in 9 (b130), 2 errors in 8 (u101), and 4 errors in 7 (u51). There should be 6 errors.

      If I try compiling any single line at a time (commenting out the rest), I get no error.

      If I reorder the declarations, I get different behaviors, but never all the expected errors.

            Unassigned Unassigned
            dlsmith Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: