On Aug 30, 2012, at 8:59 AM, Joe Wang <huizhe.w...@oracle.com> wrote:
> Alan, Paul, > > While I was writing a summery as you suggested below, I noticed an issue with > using ServiceLoader. I was trying to use the word 'delegate' but found the > ServiceLoader might be doing sth. different than the original jaxp process. > > Here's the spec: > The ServiceLoader.load(service) is equivalent to ServiceLoader.load(service, > Thread.currentThread().getContextClassLoader()) where "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 " > > > Somehow, our earlier discussion concluded that the original process I > created, where the context class loader is tried first, if no provider found, > bootstrap classloader will be tried next, could be 'delegated' to the > ServiceLoader. But the above didn't really showed that. When I looked at the > code, it actually simply returns false if loader.getResources fails to find a > provider. The CL.getResources will also delegate to the parent CL if one is present which should eventually get to the bootstrap CL. > Also, it calls ClassLoader.getSystemResources when loader=null. The later > would be a regression to CR6723276 if we had called > ServiceLoader.load(service, loader) with loader=null. > Seems as OK as i said in the previous email, since Object.class.getResourceAsStream does: public InputStream getResourceAsStream(String name) { name = resolveName(name); ClassLoader cl = getClassLoader0(); // <--- This will be null for Object.class if (cl==null) { // A system class. return ClassLoader.getSystemResourceAsStream(name); // <--- Look! } return cl.getResourceAsStream(name); } This area is complicated i think you need to write some SL tests. Paul.