将 non-exported/non-opened 包添加到 module-info 模块包的用例是什么?

What is the use case for adding non-exported/non-opened packages to a module-info's ModulePackages?

JVMS states in section 4.7.26 那个:

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.

在没有导出和打开的情况下添加这样的包什么时候有意义?我看不到 Java 编译器曾经以这种方式添加包。

我无意中发现了这个,因为 ASM 也 offers a ModuleVisitor::visitPackage method

根据 Alan Bateman 的评论回答我自己的问题:

ModulePackages 属性 是优化和可选的。如果该属性存在,JVM 可以通过简单地读取此 属性 来获取模块包的列表。如果此 属性 不存在,则必须扫描涉及 I/O 的 jar 文件,因此不需要。

如果包列表不完整,运行时将无法从这些包加载类,就好像这些包不包含在 jar 中一样。

该属性由 jar 工具添加,而不是由 javac 添加。