The JVMS states in section 4.7.26 that:
The ModulePackages attribute indicates all the packages of a module that are exported or opened by the Module attribute, as well as all the packages of the service implementations recorded in the Module attribute. The ModulePackages attribute may also indicate packages in the module that are neither exported nor opened nor contain service implementations.
When would it be meaningful to add such a package when it is not exported or opened? I cannot see that the Java compiler is ever adding packages this way.
I stumbled over this since ASM also offers a ModuleVisitor::visitPackage
method.
To answer my own questions based on the comments of Alan Bateman:
The ModulePackages
property is an optimization and optional. If the attribute is present, the JVM can get hold of a list of the module's packages by simply reading this property. If this property is not present, the jar file must be scanned what involves I/O and is therefore undesired.
If the list of packages in incomplete, the runtime will fail to load classes from these packages as if those packages were not included in the jar.
The attribute is added by the jar tool but not by javac.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With