ServiceLoader.load(Class, ClassLoader) does not load services exposed in modules and loaded by parent CL

Alan Bateman Alan.Bateman at oracle.com
Wed May 23 15:08:57 UTC 2018


On 23/05/2018 15:29, Peter Levart wrote:
> :
>
> Maven seems to load plugins in a child class loader of the "system" 
> (application) class loader and also sets this class loader as thread 
> context class loader. ServiceLoader does not find any 
> ScriptEngineFactory services when using this class loader.
>
> The question is: Is this maven plugin's fault? Should the plugin load 
> services using explicit "system" (application) class loader or should 
> the ServiceLoader lookup strategy climb the class loader delegation 
> chain and include service providers that are registered in system 
> Layer too if given class loader is a descendant of "system" 
> (application) class loader?
>
> Before JDK 9, using an child class loader of "system" (application) 
> class loader would locate system services, but since JDK 9, they are 
> invisible to such child class loaders. Is this intentional? Would it 
> be wrong if the lookup strategy was more "backwards compatible" ?
Are you sure the Maven plugin is setting the TCCL to a child of the 
application class loader? Any chance that the parent is null which would 
bypass the platform (formerly the extension) class loader?

-Alan


More information about the core-libs-dev mailing list