Problematic use of setAccessible
Claes Redestad
claes.redestad at oracle.com
Wed Sep 14 20:52:19 UTC 2016
Hi!
On a JDK 9 with patches for the recent jigsaw proposals[1], JMH runs
into some trouble due to the new behavior around reflective access
to non-exported types:
Exception in thread "main"
java.lang.reflect.InaccessibleObjectException: Unable to make private
java.nio.charset.Charset java.io.Console.cs accessible: module java.base
does not "exports private java.io" to unnamed module @78e67e0a
at
java.base/jdk.internal.reflect.Reflection.throwInaccessibleObjectException(Reflection.java:414)
at
java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:196)
at java.base/java.lang.reflect.Field.checkCanSetAccessible(Field.java:171)
at java.base/java.lang.reflect.Field.setAccessible(Field.java:165)
at org.openjdk.jmh.util.Utils.guessConsoleEncoding(Utils.java:205)
at org.openjdk.jmh.runner.Runner.createOutputFormat(Runner.java:106)
at org.openjdk.jmh.runner.Runner.<init>(Runner.java:87)
at org.openjdk.jmh.Main.main(Main.java:43)
Setting this on the command line works around the issue:
--add-exports-private java.base/java.io=ALL-UNNAMED
Better yet: adding something to that effect to the manifest is supported
and might be a transparent and backwards-compatible solution, e.g., in
the pom.xml:
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>org.openjdk.jmh.Main</mainClass>
+ <manifestEntries>
+
<Add-Exports-Private>java.base/java.io</Add-Exports-Private>
+ </manifestEntries>
</transformer>
</transformers>
<filters>
I guess updating the JMH archetype pom.xml's would be in order?
Thanks!
/Claes
[1]
http://mail.openjdk.java.net/pipermail/jpms-spec-experts/2016-September/000390.html
More information about the jmh-dev
mailing list