How to open a package from a module in the boot layer to a module in another layer?
Code Ranger
coderanger2025 at outlook.com
Sun Jan 12 09:12:52 UTC 2025
1. I see that JDK-8347283 was closed with your comment. I don't agree with you decision, but I can be wrong. Let me explain, why I think that is wrong using this concrete example.
Boot layer has jdk modules and main application modules. The CORE module of the application creates plugins with child layers. No one in the world can know what plugins will be created and used when the main application starts. Now, somewhere in the future, the module A from plugin X will require module B from boot layer to open its package to module A. I believe, that the only solution to do it is to provide the controller of the boot layer.
2. Now, I tried to do apiModule.addOpens in CORE module. I got:
java.lang.IllegalCallerException: com.foo.api.packagename is not open to module com.foo.core
at java.base/java.lang.Module.addOpens(Module.java:918) ~[?:?]
Therefore, as far as I understand, for the solution you are suggesting to work, the packagename package of the API module must be opened to the Core module. But the main problem, as I've said above - no one knows in advance which packages of which modules from the boot layer will need to be opened/exported, etc., to the plugins that will be created by users and deployed dynamically.
So, I still have no solution for this problem. This question is very important for me. If you say, that boot layer controller can't be provided, please, suggest a good solution for this problem. I think you will agree that to open/export all packages of all modules of the boot layer to CORE module is a bad solution. I really need to find a way how to do to, so I will test every your suggestion.
On 1/12/25 10:35, Alan Bateman wrote:
>
>
> On 11/01/2025 22:06, Code Ranger wrote:
>> I have an application that consists of a main part and plugins. The main part is in the boot layer, and for each plugin, a child layer is created. Plugins are dynamically added and removed.
>>
>> In one of my plugins, I use Gson, which requires the API module (located in the boot layer) to open a package to Gson. The boot layer controller is not accessible.
>>
>> Important! A few days ago (2025-01-08), I created an issue with ID 9077987 suggesting providing access to the boot layer controller, as it is impossible to work without it. However, my issue probably hasn't been reviewed yet, as I haven't received an email with the JDK_ID.
>
> JDK-8347283 [1] was created a few days ago, looks like the same topic.
>
> From the information in this mail then it looks like the API module (in the boot layer) will need to open, using Module.addOpens, its package to the plugin that uses Gson. The plugin will then, in turn, open it to the Gson module. The API module doesn't need to know anything about Gson in this setup, but it does allow need to allow for plugins that possibly break in.
>
> -Alan
>
> [1] https://bugs.openjdk.org/browse/JDK-8347283
More information about the jigsaw-dev
mailing list