CFR: javax.xml.parsers: Using ServiceLoader to load JAXP parser factories (7169894: JAXP Plugability Layer: using service loader)

Daniel Fuchs daniel.fuchs at
Mon Dec 3 19:04:45 UTC 2012


This is a first webrev in a series that addresses a change intended
for JDK 8:

7169894: JAXP Plugability Layer: using service loader

I've been building up on Joe's work and Paul & Alan comments
from an earlier discussion thread [1]

This here addresses changes in the javax.xml.parsers
package for the SAXParserFactory and DocumentBuilderFactory - and
more specifically their no-argument newInstance() method.

This change replaces the custom code that was reading the
META-INF/services/ resources by a simple call to ServiceLoader.


In addition - since it is foreseen that the default implementation
for the parsers might come as a separate Module in the future, we
cannot make the assumption that the first service provider encountered
by the ServiceLoader will be the third-party/custom provider to
As a consequence, since we must allow for a third-party/custom provider
to override the default implementation - we will skip over any
provider whose class name has the default implementation class name,
and return it only if no other provider is found.

This is a small spec change intended for JDK8 which is reflected in
the API Documentation of the two factory classes. The impact is that
in the very rare configuration where you have on the classpath
two providers:  A.jar:B.jar, where A.jar has a services/* config that 
points at the default factory implementation, and B.jar points at a
custom implementation, then the new XxxxFactory will return the
custom implementation pointed at by B.jar, whereas it used to
return the default implementation pointed at by A.jar.

best regards,

-- daniel



More information about the core-libs-dev mailing list