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

IllegalAccessError for code passed by compiler

    Details

    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      When an abstract class calls a method that is specified in an interface and implemented by a subclass, and a private method with the same signature exists in a superclass, the code compiles fine but an IllegalAccessException is thrown at runtime. From the JLS, it appears that any "not inherited" method should not have any effect on method resolution at all. It seems that the subclass method should be called in this case, but I may be missing something.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile code. Run.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expect "2" to be printed to standard out.
      ACTUAL -
      An IllegalAccessException is thrown.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.IllegalAccessError: tried to access method A1.getI()I from class A2
      at A2.test(AccessBug.java:19)
      at AccessBug.main(AccessBug.java:3)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class AccessBug {
         public static void main(String[] args) {
            new A3().test();
         }
      }
         
      class A1 {
         private int getI() {
            return 1;
         }
      }
         
      interface I1 {
          int getI();
      }
         
      abstract class A2 extends A1 implements I1 {
         public void test() {
            System.out.println(getI());
         }
      }
         
      class A3 extends A2 {
         public int getI() {
            return 2;
         }
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                ndcosta Nelson Dcosta
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: