Here is a real example of some code that does that, namely Glassfish 4.1 does not run on JDK nine because the JVM throws an IllegalAccessError
The error message is
class com.sun.enterprise.security.provider policy wrapper
in module unnamed module, cannot access class
com.sun.security.provider policy file
in module java.base.
263 public class PolicyFile extends java.security.Policy {
jdk9/dev/jdk/file/tip/src/java.base/share/classes/sun/security/provider/
* @see java.security.CodeSource
* @see java.security.Permissions
* @see java.security.ProtectionDomain
private static final Debug debug = Debug.getInstance("policy");
To be clear in JDK 9, the GlassFish code cannot access this public policy file class at compile time or runtime.
It is exactly like trying to access a "package private" class.
javac
gives an error and the virtual machine throws IllegalAccessError.
GlassFish will have to find a supported API, not one of these concealed sun.* API's.
module exports packages, but requires modules
I would like to return to the
module-info.java
file that declares the HelloWorld module.
module hello.world {
exports com.example.hello;
requires java.base;
}
module hello.world {
exports com.example.hello;
requires java.base;
}
module hello.world { ... }
hello.world
.hello.world
must match the logical module name used in the module-path
.exports com.example.hello;
com.example.hello
so other modules can access its public types.com.example.hello
would be internal to the hello.world
module, even if its classes are public
.requires java.base;
java.base
is the core module in Java (contains java.lang
, java.util
, java.io
, etc.).java.base
implicitly, so explicitly writing it here is optional — it’s included for clarity.module-info.class
(compiled from module-info.java
) to enforce strong encapsulation.