Exporting a package from system module is not allowed with --release

ZhekaKozlov picture ZhekaKozlov · Jul 28, 2017 · Viewed 8.9k times · Source

I have the following program:

module-info.java

module a {
}

Main.java

public class Main {
    public static void main(String[] args) {
        System.out.println(sun.nio.ByteBuffered.class);
    }
}

This program successfully compiles with the --add-exports option:

> javac --add-exports java.base/sun.nio=a module-info.java Main.java

However, when I add the --release argument, it fails:

> javac --add-exports java.base/sun.nio=a --release 9 module-info.java Main.java
error: exporting a package from system module java.base is not allowed with --release
1 error

Basically, these two commands are equivalent. So why is the latter one forbidden?

Also, since IDEA passes the --release argument to javac, this makes the development in IDEA impossible if my project needs an internal API.

I'm using JDK 9+178.

Answer

xoric picture xoric · Apr 6, 2019

If you are using IntelliJ idea, try checking your Java compiler settings:

Go to the File menu -> [Settings] -> [Build, Execution, Deployment] -> [Java Compiler] and check the setting "Project bytecode version". I got a similar error ("exporting a package from system module java.datatransfer is not allowed with --release") when using JDK 11 while this value was still set to version 9. Setting it to 11 fixed the problem for me.

Screenshot