Bug 247953 - [1.5][compiler] IllegalAccessError: tried to access class p.IA from class X
Summary: [1.5][compiler] IllegalAccessError: tried to access class p.IA from class X
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.5 M3   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-19 07:30 EDT by Philipe Mulet CLA
Modified: 2008-10-28 13:09 EDT (History)
0 users

See Also:


Attachments
In progress state (15.85 KB, patch)
2008-09-26 12:34 EDT, Philipe Mulet CLA
no flags Details | Diff
Improved patch (19.77 KB, patch)
2008-09-26 12:48 EDT, Philipe Mulet CLA
no flags Details | Diff
Proposed patch (29.49 KB, patch)
2008-09-30 09:18 EDT, 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 2008-09-19 07:30:26 EDT
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");
	}
}
Comment 1 Philipe Mulet CLA 2008-09-19 07:31:47 EDT
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)
Comment 2 Philipe Mulet CLA 2008-09-19 07:54:43 EDT
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 {
}

]


Comment 3 Philipe Mulet CLA 2008-09-19 07:56:03 EDT
javac 1.6.0_10-beta does accept both testcases (no compile error) but its output raises IllegalAccessException at runtime.
Comment 4 Philipe Mulet CLA 2008-09-26 12:34:53 EDT
Created attachment 113609 [details]
In progress state

need to handle msg like field refs
need more tests for field assign cases (compact, postincr, etc...)
Comment 5 Philipe Mulet CLA 2008-09-26 12:46:12 EDT
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" + 
Comment 6 Philipe Mulet CLA 2008-09-26 12:48:02 EDT
Created attachment 113610 [details]
Improved patch
Comment 7 Philipe Mulet CLA 2008-09-30 09:18:58 EDT
Created attachment 113867 [details]
Proposed patch
Comment 8 Philipe Mulet CLA 2008-09-30 09:20:16 EDT
Added GenericTypeTest#test1381-1389
Comment 9 Philipe Mulet CLA 2008-09-30 13:31:22 EDT
Released for 3.5M3
Fixed
Comment 10 Kent Johnson CLA 2008-10-28 13:09:22 EDT
Verified for 3.5M3 using I20081026-2000 build.