After JDK-8332457 (Examine startup overheads from JDK-8294961), the following example fails at runtime with a IllegalAccessError. It succeeds with earlier JDK versions.
I noticed this because it breaks test coverage for https://github.com/google/guice.
In this example the proxied interface I is public, so the proxy is generated into a separate package (jdk.proxy1), but the interface declares a method with a package access interface J. I think that after the changes in JDK-8332457 the type in the method signature is getting accessed from the jdk.proxy package, resulting in the IllegalAccessError.
import java.lang.reflect.Proxy;
public class Z {
public interface I {
void f(J j);
}
interface J {
void g();
}
public static void main(String[] args) {
I proxy =
(I)
Proxy.newProxyInstance(
I.class.getClassLoader(), new Class<?>[] {I.class}, (p, m, a) -> null);
proxy.f(() -> {});
}
}
$ java Z
Exception in thread "main" java.lang.IllegalAccessError: failed to access class Z$J from class jdk.proxy1.$Proxy0 (Z$J is in unnamed module of loader 'app'; jdk.proxy1.$Proxy0 is in module jdk.proxy1 of loader 'app')
at jdk.proxy1/jdk.proxy1.$Proxy0.f(Unknown Source)
at Z.main(Z.java:18)