JDK-8347336 Add name property for every ModuleLayer instance
Code Ranger
coderanger2025 at outlook.com
Wed Jan 15 09:02:28 UTC 2025
When working with multiple ModuleLayers, it often becomes necessary to identify a specific layer and distinguish it from others. For example, when ModuleLayers are used for plugins, and the program retrieves a layer for a specific plugin, a map is typically required to determine which plugin the layer belongs to in order to give some name to the layer.
However, when different libraries interact with a layer, the need for layer identification becomes even more pressing. For instance, consider receiving a LogEvent in log4j2. By default, log4j2 provides information about the module that created the event via logEvent.getSource().moduleName. However, having only the module name, without the layer name, is not very helpful. The reason for this is that a module is part of a layer, and there can be multiple layers where a module with the same name is used. Thus, if we want to obtain log events for a specific plugin, we are forced to reinvent the wheel, as LogEvent does not provide access to the layer name. This limitation arises because, at present, ModuleLayer does not have a getName() method.
Because of this, I filed JDK-8347336. I would like to hear the opinions of JPMS developers and understand whether this issue will be addressed or not.
For example, it is possible to overload the methods defineModulesWithManyLoaders, defineModulesWithOneLoader etc adding a String name parameter, and add the getName() method to ModuleLayer. So, the name will be specified by user, at the same time ModuleLayer will be immutable.
More information about the jigsaw-dev
mailing list