--- old/src/javax/xml/stream/FactoryFinder.java Tue Nov 26 14:07:23 2013 +++ new/src/javax/xml/stream/FactoryFinder.java Tue Nov 26 14:07:22 2013 @@ -262,9 +262,7 @@ } if (systemProp != null) { dPrint("found system property, value=" + systemProp); - // There's a bug here - because 'cl' is ignored. - // This will be handled separately. - return newInstance(type, systemProp, null, true); + return newInstance(type, systemProp, cl, true); } } catch (SecurityException se) { @@ -303,9 +301,7 @@ if (factoryClassName != null) { dPrint("found in " + configFile + " value=" + factoryClassName); - // There's a bug here - because 'cl' is ignored. - // This will be handled separately. - return newInstance(type, factoryClassName, null, true); + return newInstance(type, factoryClassName, cl, true); } } catch (Exception ex) { @@ -314,7 +310,7 @@ if (type.getName().equals(factoryId)) { // Try Jar Service Provider Mechanism - final T provider = findServiceProvider(type); + final T provider = findServiceProvider(type, cl); if (provider != null) { return provider; } @@ -340,12 +336,18 @@ * * @return instance of provider class if found or null */ - private static T findServiceProvider(final Class type) { + private static T findServiceProvider(final Class type, final ClassLoader cl) { try { return AccessController.doPrivileged(new PrivilegedAction() { @Override public T run() { - final ServiceLoader serviceLoader = ServiceLoader.load(type); + final ServiceLoader serviceLoader; + if (cl == null) { + //the current thread's context class loader + serviceLoader = ServiceLoader.load(type); + } else { + serviceLoader = ServiceLoader.load(type, cl); + } final Iterator iterator = serviceLoader.iterator(); if (iterator.hasNext()) { return iterator.next();