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

Cast inserted by generics can cause IllegalAccessError

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 7
    • 6
    • tools
    • b05
    • x86
    • linux
    • Verified

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

        A DESCRIPTION OF THE PROBLEM :
        When a class A has a generic field with a private class P as parameter, and another class Main without access to P uses this field, generics may insert a casts to P in Main, to which it has no access. This results in an IllegalAccessError.
        This may actually be a bug in the specification, I'm not sure.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile and run the provided code.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The compiler shouldn't accept such code.
        ACTUAL -
        java.lang.IllegalAccessError: tried to access class a.A$P from class Main

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        Main.java:
        public class Main {
        public static void main(String[] args) {
        a.A myA = new a.A();
        myA.p = myA.vec.get(0);
        }
        }

        a/A.java:
        package a;
        import java.util.Vector;
        public class A {
        private class P {}
        public P p;
        public Vector<P> vec;
        public A() {
        vec = new Vector<P>();
        vec.add(new P());
        }
        }
        ---------- END SOURCE ----------

              ahe Peter Ahe
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: