Details
-
Bug
-
Resolution: Fixed
-
P2
-
23
Backports
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-8334957 | 23.0.1 | Chen Liang | P2 | Resolved | Fixed | b02 |
JDK-8334753 | 23 | Chen Liang | P2 | Closed | Fixed | b29 |
Description
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 inJDK-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)
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
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)
Attachments
Issue Links
- backported by
-
JDK-8334957 IllegalAccessError with proxies after JDK-8332457
-
- Resolved
-
-
JDK-8334753 IllegalAccessError with proxies after JDK-8332457
-
- Closed
-
- relates to
-
JDK-8332457 Examine startup overheads from JDK-8294961
-
- Closed
-
- links to
-
Commit openjdk/jdk/1dbad805
-
Commit openjdk/jdk/91bd85d6
-
Review(jdk23) openjdk/jdk/19815
-
Review(master) openjdk/jdk/19615
(2 links to)