On Mon, 13 Mar 2023 13:43:22 GMT, Adam Sotona <asot...@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