Reviewer and committer request for 7198496

Paul Sandoz paul.sandoz at oracle.com
Wed Oct 3 12:50:54 UTC 2012


On Oct 3, 2012, at 2:41 PM, Peter Levart <peter.levart at gmail.com> wrote:

> I think that in the LazyIterator.hasNext() you still have to check for null loader:
> 
> 337                     if (loader == null)
> 338                         configs = ClassLoader.getSystemResources(fullName);
> 339                     else
> 340                         configs = loader.getResources(fullName);
> 
> 
> Because the ClassLoader.getSystemClassLoader() can return null. In that case, ClassLoader.getSystemResources() delegates just to .getBootstrapResources() which is in sync with later:
> 
> 
> 359                 S p = service.cast(Class.forName(cn, true, loader)
> 360                                    .newInstance());
> 
> 
> when loader is null - i.e. it loads just bootstrap classes.
> 

Yes, thanks, i just caught that silly mistake just before i received your email :-) , the webrev is updated.

--

For the benefit of others; for some context see this recent thread:

http://markmail.org/search/?q=openjdk#query:openjdk%20list%3Anet.java.openjdk.core-libs-dev%20order%3Adate-backward+page:2+mid:inod424lqbey5fms+state:results

Basically ServiceLoader is treating a null CL parameter as the system CL for loading the META-INF/services resources file and as the bootstrap CL for loading the classes of class names declared in those resource files.

Which also means that calls to:

  ServiceLoader.load(serviceInterface)
  ServiceLoader.load(serviceInterface, Thread.currentThread().getContextClassLoader());

Will behave oddly if the TCCL is null, from the JavaDoc of Thread.getContextClassLoader():

  http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#getContextClassLoader()
  Returns:
  the context ClassLoader for this Thread, or null indicating the system class loader (or, failing that, the bootstrap class loader)

Paul.


More information about the core-libs-dev mailing list