1

I have the following codes which I got from here.

import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.queue.ChronicleQueue;
import net.openhft.chronicle.queue.ExcerptAppender;
import net.openhft.chronicle.queue.ExcerptTailer;

public class ChronicleQueueTutorial {

    public static void main(String[] args) {
        String basePath = OS.getTarget() + "/getting-started";
        System.out.println("Base path: " + basePath);
        try (ChronicleQueue queue = ChronicleQueue.singleBuilder(basePath).build()) {
            ExcerptAppender appender = queue.acquireAppender();
            appender.writeText("TestMessage");
            ExcerptTailer tailer = queue.createTailer();
            System.out.println(tailer.readText());
        }
    }

}

Here is my pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>ChronicleTutorial</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>net.openhft</groupId>
            <artifactId>chronicle-queue</artifactId>
            <version>5.23ea25</version>
        </dependency>
    </dependencies>
</project>

I tried to run it in IntelliJ with Java 17, but it threw the following exception:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at net.openhft.chronicle.core.Jvm.getSetAccessible0Method(Jvm.java:232)
    at net.openhft.chronicle.core.Jvm.<clinit>(Jvm.java:132)
    at net.openhft.chronicle.core.OS.<clinit>(OS.java:48)
    at ChronicleQueueTutorial.main(ChronicleQueueTutorial.java:9)
Caused by: java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:568)
    at net.openhft.chronicle.core.Jvm.getSetAccessible0Method(Jvm.java:228)
    ... 3 more
Caused by: java.lang.IllegalAccessException: module java.base does not open java.lang.reflect to unnamed module @39ed3c8d
    at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:259)
    ... 8 more

I am not even using the Java module system (I don't have module.info). Why am I getting this error?

user3573403
  • 1,780
  • 5
  • 38
  • 64
  • 1
    The library you use tries to use reflection on some Java internal classes. That's no longer allowed by default (since Java 9 or 11, I don't quite remember which one). – Joachim Sauer Jul 25 '22 at 12:09
  • 1
    Does this answer your question? [How to fix the ''module java.base does not "opens java.io" to unnamed module '' error in Android Studio?](https://stackoverflow.com/questions/67782975/how-to-fix-the-module-java-base-does-not-opens-java-io-to-unnamed-module) – Joachim Sauer Jul 25 '22 at 12:09
  • My JDK is version 17 but in Intellij, I changed the settings to compile to Java 8. I'm still getting the same exception when I run. – user3573403 Jul 25 '22 at 12:29
  • 1
    The version you compile towards doesn't matter. This is a runtime change, so only which Java version you *run* your code with matters. – Joachim Sauer Jul 25 '22 at 12:33
  • I see. Thanks. I found the solution that works with Java 17: https://chronicle.software/chronicle-support-java-17/ – user3573403 Jul 25 '22 at 12:45
  • Great. Feel free to post an answer to your own question if you want (just make sure it's more than just the plain link, if you do). – Joachim Sauer Jul 25 '22 at 12:45

1 Answers1

0

You need to add these options for Java 11 and 17

--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED
--add-exports=java.base/sun.nio.ch=ALL-UNNAMED
--add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED
--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-opens=jdk.compiler/com.sun.tools.javac=ALL-UNNAMED
--add-opens=java.base/java.lang=ALL-UNNAMED
--add-opens=java.base/java.lang.reflect=ALL-UNNAMED
--add-opens=java.base/java.io=ALL-UNNAMED
--add-opens=java.base/java.util=ALL-UNNAMED

https://github.com/OpenHFT/OpenHFT/blob/ea/docs/Java-Version-Support.adoc

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130