IllegalAccessError with --patch-module
Thiago Henrique Hupner
thihup at gmail.com
Wed Jan 6 21:47:05 UTC 2021
This is getting very confusing.
If you use any jar as an automatic module in the "--module-path" (-p) and
add the main class in another jar (in this example jar-b.jar), patch both
and the error happens.
The main class is literally just an empty main method [1].
The error happens even if we use an empty jar.
Running:
/jvms/jdk-15/bin/java -p /tmp/activation.jar --show-module-resolution
--patch-module=activation=target/jar-b.jar -m activation/com.foo.Main
root activation file:///tmp/activation.jar automatic
Error: Unable to load main class com.foo.Main in module activation
java.lang.IllegalAccessError: superclass access check failed: class
com.foo.Main (in module activation) cannot access class java.lang.Object
(in module java.base) because module java.base does not export java.lang to
module activation
However, it works if we --add-modules java.base
java -p /tmp/activation.jar --add-modules=java.base
--show-module-resolution --patch-module=activation=target/jar-b.jar -m
activation/com.foo.Main
root activation file:///tmp/activation.jar automatic
root java.base jrt:/java.base
java.base binds java.logging jrt:/java.logging
java.base binds java.management jrt:/java.management
java.base binds jdk.security.auth jrt:/jdk.security.auth
java.base binds jdk.charsets jrt:/jdk.charsets
java.base binds jdk.zipfs jrt:/jdk.zipfs
java.base binds jdk.localedata jrt:/jdk.localedata
[...]
Looks like if the automatic module is patched it loses the requires
java.base
java -p /tmp/activation.jar --add-modules=java.base
--describe-module=activation --patch-module=activation=target/jar-b.jar
WARNING: Unknown module: activation specified to --patch-module
activation file:///tmp/activation.jar automatic
contains com.foo
contains com.sun.activation.registries
contains com.sun.activation.viewers
contains javax.activation
java -p /tmp/activation.jar --add-modules=java.base
--describe-module=activation
activation file:///tmp/activation.jar automatic
requires java.base mandated
contains com.sun.activation.registries
contains com.sun.activation.viewers
contains javax.activation
[1]
package com.foo;
public class Main {
public static void main(String[] args) throws Exception{
}
}
Em qua., 6 de jan. de 2021 às 17:26, Alan Bateman <Alan.Bateman at oracle.com>
escreveu:
> On 06/01/2021 19:57, Thiago Henrique Hupner wrote:
> > Sorry, they are automatic modules.
> >
> > I'll create a test case.
> >
> Also if you can include the output with --show-module-resolution then it
> might help track this down quickly (running without any explicit modules
> on the module path is, on the surface, a bit unusual but I wouldn't
> expect any issues).
>
> -Alan
>
More information about the jigsaw-dev
mailing list