Bug 209153 - [1.5][compiler] VerifyError due to generic cast to a non visible type
Summary: [1.5][compiler] VerifyError due to generic cast to a non visible type
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.4   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.3.2   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-11-08 05:24 EST by Philipe Mulet CLA
Modified: 2007-12-11 11:45 EST (History)
2 users (show)

See Also:
philippe_mulet: pmc_approved+


Attachments
Proposed patch (16.39 KB, patch)
2007-11-08 09:47 EST, Philipe Mulet CLA
no flags Details | Diff
Patch for 3.3.x (16.49 KB, patch)
2007-11-08 11:35 EST, Philipe Mulet CLA
no flags Details | Diff
Better patch (16.26 KB, patch)
2007-11-08 11:54 EST, Philipe Mulet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Philipe Mulet CLA 2007-11-08 05:24:14 EST
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());
	}
}
Comment 1 Philipe Mulet CLA 2007-11-08 05:25:31 EST
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());
        }
}
Comment 2 Philipe Mulet CLA 2007-11-08 05:26:53 EST
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());
        }
}
Comment 3 Philipe Mulet CLA 2007-11-08 09:47:16 EST
The problem comes from the generic cast which gets inserted, and introducing an illegal reference to non-visible type P.

Comment 4 Philipe Mulet CLA 2007-11-08 09:47:41 EST
Created attachment 82445 [details]
Proposed patch
Comment 5 Philipe Mulet CLA 2007-11-08 11:35:01 EST
Created attachment 82458 [details]
Patch for 3.3.x
Comment 6 Philipe Mulet CLA 2007-11-08 11:54:44 EST
Created attachment 82459 [details]
Better patch
Comment 7 Philipe Mulet CLA 2007-11-08 11:57:36 EST
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
Comment 8 Philipe Mulet CLA 2007-11-09 03:20:14 EST
Released for 3.4M4 (HEAD).
Fixed
Comment 9 Philipe Mulet CLA 2007-11-09 04:03:56 EST
Released for 3.3.2 (R3_2_maintenance)
Fixed
Comment 10 Jerome Lanneluc CLA 2007-11-22 10:37:29 EST
Without the fix, the compiler may issue code which doesn't verify.
The fix is quite simple.
Comment 11 Philipe Mulet CLA 2007-11-23 09:20:12 EST
+1 for 3.3.2
Comment 12 Kent Johnson CLA 2007-12-11 11:45:36 EST
Verified for 3.4M4 using build I20071210-1800.