Community
Participate
Working Groups
The following code should be rejected (invalid access to private type) 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()); } }
Should also reject: 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 { class P {} public P p; public Vector<P> vec; public A() { vec = new Vector<P>(); vec.add(new P()); } }
Should also reject: 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 { protected class P {} public P p; public Vector<P> vec; public A() { vec = new Vector<P>(); vec.add(new P()); } }
The problem comes from the generic cast which gets inserted, and introducing an illegal reference to non-visible type P.
Created attachment 82445 [details] Proposed patch
Created attachment 82458 [details] Patch for 3.3.x
Created attachment 82459 [details] Better patch
If not rejecting the code, a verify error is issued at runtime. Also see: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6495506
Released for 3.4M4 (HEAD). Fixed
Released for 3.3.2 (R3_2_maintenance) Fixed
Without the fix, the compiler may issue code which doesn't verify. The fix is quite simple.
+1 for 3.3.2
Verified for 3.4M4 using build I20071210-1800.