Community
Participate
Working Groups
Build 3.5M2 Compiling and running the following code raises an IllegalAccessException at runtime: Exception in thread "main" java.lang.IllegalAccessError: tried to access class p.IA from class X at X.foo(X.java:4) at X.main(X.java:9) public class X<T extends AA & p.IB> { T t; void foo() { this.t.baz(); } public static void main(String[] args) { X<CC> xcc = new X<CC>(); xcc.t = new CC(); new X<CC>().foo(); } } class AA { void bar() {} } class CC extends AA implements p.IB { @Override public void baz() { System.out.println("done"); } }
Offending bytecode is: // Method descriptor #10 ()V // Stack: 1, Locals: 1 void foo(); 0 aload_0 [this] 1 getfield X.t : AA [21] 4 checkcast IA [23] 7 invokeinterface IA.baz() : void [25] [nargs: 1] 12 return it should rather use IB (which is accessible, whereas IA is not)
Same issue exists with fields, where we reject at compile-time due to accessibility problem. X.java [ public class X<T extends AA & p.IB> { T t; void foo() { System.out.println(this.t.baz); } public static void main(String[] args) { X<CC> xcc = new X<CC>(); xcc.t = new CC(); xcc.foo(); } } class AA { void bar() {} } class CC extends AA implements p.IB { } ] p/IB.java [ package p; interface IA { Object baz = "done"; } public interface IB extends IA { } ]
javac 1.6.0_10-beta does accept both testcases (no compile error) but its output raises IllegalAccessException at runtime.
Created attachment 113609 [details] In progress state need to handle msg like field refs need more tests for field assign cases (compact, postincr, etc...)
unclear we want this for a static field access (GenericTypeTest#test1387) " 4 getfield X.t : AA [27]\n" + " 7 checkcast p.IB [29]\n" + " 10 pop\n" + " 11 getstatic p.IB.baz : java.lang.Object [31]\n" + should avoid this ? " 7 checkcast p.IB [29]\n" +
Created attachment 113610 [details] Improved patch
Created attachment 113867 [details] Proposed patch
Added GenericTypeTest#test1381-1389
Released for 3.5M3 Fixed
Verified for 3.5M3 using I20081026-2000 build.