Hi Joe,

On Aug 30, 2012, at 1:08 AM, Joe Wang <huizhe.w...@oracle.com> wrote:

> I actually updated the webrev yesterday with your suggestion.  
> 

OK! Sorry if i am being stubbornly persistent!


> Recall our discussions back in June, the suggestion was to delegate to the 
> ServiceLoader, e.g. ServiceLoader.load(serviceClass). The rational was that 
> the ServiceLoader uses context and then bootstrap class loader.
> 

Yes.


> The spec for public static <S> ServiceLoader<S> load(Class<S> service, 
> ClassLoader loader) states:
> loader - The class loader to be used to load provider-configuration files and 
> provider classes, or null if the system class loader (or, failing that, the 
> bootstrap class loader) is to be used
> 
> This is different. In JAXP, null is recognized as bootstrap classloader, but 
> the  ServiceLoader actually assumes it as system class loader.  This will be 
> a problem, whether or now a classloader is passed to the load method.
> 

It's slightly different. For loading the provider-configuration file SL does:

                    if (loader == null)
                        configs = ClassLoader.getSystemResources(fullName);
                    else
                        configs = loader.getResources(fullName);

For loading the class:

                S p = service.cast(Class.forName(cn, true, loader)
                                   .newInstance());

And the JavaDoc for Class.forName states:

    "If the parameter loader is null, the class is loaded through the bootstrap 
class loader."

So there is some vagueness in the JavaDoc of SL of when the system CL is 
utilised.

However, i think things are consistent with loading the provider-configuration 
file, it's a bit of a tangle but AFAICT previously loading the configuration 
file deferred to SecuritySupport.getResourceAsStream which does:

                   if (cl == null) {
                        ris = Object.class.getResourceAsStream(name);
                    } else {
                        ris = cl.getResourceAsStream(name);
                    }

And the JavaDoc of Class.getResourceAsStream states:

  "If this object was loaded by the bootstrap class loader, the method 
delegates to 
   ClassLoader.getSystemResourceAsStream(java.lang.String)"

Paul.

Reply via email to