add-opens for dynamically created layers

Alan Bateman Alan.Bateman at oracle.com
Mon Nov 16 19:27:04 UTC 2020


On 16/11/2020 18:35, Alex Orlov wrote:
> :
>   
> When I start my application I get:
>   
> java.lang.IllegalAccessError: class org.springframework.core.log.CompositeLog (in module spring.core) cannot access class org.apache.commons.logging.impl.NoOpLog (in module org.apache.commons.logging) because module org.apache.commons.logging does not export org.apache.commons.logging.impl to module spring.core.
>   
> To fix it, I wanted in the Framework dynamically addOpens to module (module.addOpens(...)), however, I got
>   
> Caused by: java.lang.IllegalCallerException: org.apache.commons.logging.impl is not open to module fw.module.
>   
> To fix it I added jvm argument:
>   
> --add-opens org.apache.commons.logging/org.apache.commons.logging.impl=fw.module \
>   
> However, it didn’t help. It seems to me that jvm arguments add-opens works only when the module that must open
> its package is in boot layer, but in my situation fw.module that is in boot layer knows nothing about web application modules.
The static defineModulesXXXX methods return a ModuleLayer.Controller 
that can be used to export or open any package of any module in the 
layer to any other module. It's the equivalent of using the 
--add-exports or --add-opens on the command line to export or open 
packages of modules in the boot layer. So in this case you should be 
able to use the ModuleLayer.Controller for (I assume) the "Web 
Application Layer" to export 
org.apache.commons.logging/org.apache.commons.logging.impl to 
spring.core. That can be a workaround using spring.core and 
org.apache.commons.logging agree sort out their differences on whether 
org.apache.commons.logging.impl is part of the supported API or not.

-Alan.


More information about the jigsaw-dev mailing list