RFR: 8294962: Convert java.base/jdk.internal.module package to use the Classfile API to modify and write module-info.class [v4]

Adam Sotona asotona at openjdk.org
Mon Mar 13 13:50:40 UTC 2023


On Mon, 13 Mar 2023 13:43:22 GMT, Adam Sotona <asotona at openjdk.org> wrote:

>> Maybe the variants of Classfile.buildModule need to be looked at again. For the usage here, buildModule(ModuleAttribute, Consumer<? super ClassBuilder>) would be more useful as it would allow all of the additional attributes to be emitted in the handler rather than having buildModule making the decision on whether to emit the ModulePackages attribute.
>
> `Classfile::buildModule` is a helper method simplifying the major use case - building valid module with minimal user effort and knowledge. It emits `ModulePackages` if there are any packages specified and not exported nor opened. That is the configuration which JVM expects and majority of users are not aware of.
> Other module-specific attributes can be added in the underlying handler, using `ClassBuilder::with`.
> 
> A different building approach can be used in cases (which I would like to know more about) where even `ModulePackages` attribute needs to be "customised" or provided unconditionally. It is always possible to build module as a class using `Classfile::build` from scratch and provide all the attributes manually.

Or another approach for the specific use cases might be to use `Classfile::buildModule` with empty list of packages and then provide custom `ModulePackagesAttribute` to the handler directly.

-------------

PR: https://git.openjdk.org/jdk/pull/11368


More information about the core-libs-dev mailing list