lundi 27 mai 2019

MethodHandles throws IllegalAccessException when accessing sun.nio.ch in Java 11

I upgraded my jdk from 8 to 11, and then the ChronicleMap failed to init itself, throwing exceptions like

Caused by: java.lang.IllegalAccessException: member is private: sun.nio.ch.FileChannelImpl.unmap0[Ljava.lang.Object;@21f50d2c/invokeStatic, from net.openhft.chronicle.core.OS (unnamed module @8bc0696)
  at java.base/java.lang.invoke.MemberName.makeAccessException(MemberName.java:942)
  at java.base/java.lang.invoke.MethodHandles$Lookup.checkAccess(MethodHandles.java:2215)
  at java.base/java.lang.invoke.MethodHandles$Lookup.checkMethod(MethodHandles.java:2155)
  at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodCommon(MethodHandles.java:2299)
  at java.base/java.lang.invoke.MethodHandles$Lookup.getDirectMethodNoSecurityManager(MethodHandles.java:2292)
  at java.base/java.lang.invoke.MethodHandles$Lookup.unreflect(MethodHandles.java:1756)
  at net.openhft.chronicle.core.OS.<clinit>(OS.java:79)
  ... 52 common frames omitted

This exception is caused by the source code in net.openhft.chronicle.core.OS at line 79:

Method unmap0 = Jvm.getMethod(FileChannelImpl.class, "unmap0", long.class, long.class); // this line worked
UNMAPP0_MH = MethodHandles.lookup().unreflect(unmap0); // this line failed

MethodHandles.lookup() failed to unreflect this method in java 11 (most possibly because of modularity)

I tried to add arguments to jvm like this issue suggests: https://github.com/OpenHFT/Chronicle-Core/issues/15

And my jvm param now includes:

--add-exports java.base/sun.nio.ch=ALL-UNNAMED 

(Or add-opens, not working either)

--add-opens java.base/sun.nio.ch=ALL-UNNAMED 

The maven plugin

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.8.0</version>
    <configuration>
        <source>11</source>
        <release>11</release>
        <compilerArgs>
            <arg>--add-opens</arg>
            <arg>java.base/sun.nio.ch=ALL-UNNAMED</arg>
        </compilerArgs>
    </configuration>
....

But it didn't work.

It seems chronicle-map had solved this issue, but I'm still getting these exceptions in Java 11.

chronicle-map version:

<groupId>net.openhft</groupId>
<artifactId>chronicle-map</artifactId>
<version>3.17.2</version>





Aucun commentaire:

Enregistrer un commentaire