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

Accessing protected static methods

XMLWordPrintable

    • b01
    • x86
    • windows_xp
    • Verified

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

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

        A DESCRIPTION OF THE PROBLEM :
        Example below throws a runtime exception
        Exception in thread "main" java.lang.IllegalAccessError: tried to access method
        ab.A.m()V from class c.C
                at c.C.c(C.java:8)
                at D.main(D.java:5)

        It compiles and runs w/o exception in jdk 1.5.


        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        either a compile time error or no error as in jdk 1.5
        ACTUAL -
        Exception in thread "main" java.lang.IllegalAccessError: tried to access method
        ab.A.m()V from class c.C
                at c.C.c(C.java:8)
                at D.main(D.java:5)


        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        package ab;

        public abstract class A{
        protected static void m(){
        System.out.println("A.m()");
        }
        }
        -----------------------------------------------------------------------
        package ab;

        public abstract class B extends A{
        }
        -----------------------------------------------------------------------
        package c;

        import ab.A;
        import ab.B;

        public class C extends A{
        public static void c(){
        B.m();
        }
        }
        ------------------------------------------------------------------------
        import c.C;

        public class D {
        public static void main(String [] argv){
        C.c();
        }
        }
        ------------------------------------------------------------------------
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        change a call B.m() to A.m()

        Release Regression From : 6
        The above release value was the last known release where this
        bug was not reproducible. Since then there has been a regression.

              kamg Keith Mcguigan (Inactive)
              ryeung Roger Yeung (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: