FULL PRODUCT VERSION :
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
A DESCRIPTION OF THE PROBLEM :
The generated proxy is not put in the proper package.
The Javadoc for java.lang.reflect.Proxy says:
"If a proxy class implements a non-public interface, then it will be defined in the same package as that interface. Otherwise, the package of a proxy class is also unspecified. Note that package sealing will not prevent a proxy class from being successfully defined in a particular package at runtime, and neither will classes already defined by the same class loader and the same package with particular signers."
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Put Outer.java and Test.java included below in package p1.
2) Compile them.
3) Run p1.Test.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Class class p1.$Proxy0
is in package p1
Class class p1.$Proxy1
is in package p1
ACTUAL -
Class class p1.$Proxy0
is in package p1
Class class $Proxy1
is in null
ERROR MESSAGES/STACK TRACES THAT OCCUR :
Since the proxy is in the wrong package, this can lead to spurious and tricky IllegalAccessErrors like this:
java.lang.IllegalAccessError: tried to access class com.foo.Bar from class $Proxy1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package p1;
interface Outer {
interface Inner {
}
}
============================================================
package p1;
import java.lang.reflect.*;
public class Test {
public static void main(String[] args) {
makeProxy(Outer.class);
makeProxy(Outer.Inner.class);
}
private static void makeProxy(Class oneInterface) {
ClassLoader loader = Test.class.getClassLoader();
Class[] interfaces = new Class[] { oneInterface };
InvocationHandler handler = new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) {
System.out.println("doing " + method);
return method;
}
};
Object proxy = Proxy.newProxyInstance(
loader,interfaces,handler);
System.out.println("Class " + proxy.getClass());
System.out.println("is in " + proxy.getClass().getPackage());
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Increase visibility from package to protected as required to eliminate any IllegalAccessErrors.
###@###.### 2005-04-18 19:34:48 GMT