Skip to main content

XPathFactory.newInstance() in webapp classloader not picking up saxon-xpath

8 replies [Last post]
bruyeron
Offline
Joined: 2004-07-12
Points: 0

I am struggling with a webapp that refuses to load the saxon-xpath implementation despite the saxon-xpath.jar being present in WEB-INF/lib. This jar contains the META-INF/services/javax.xml.xpath.XPathFactory file needed to be discovered by the JAXP factory finder mecanism.
I tried to set -Djaxp.debug=true to see what javax.xml.xpath.XPathFactoryFinder is doing, and I see this in the output:
JAXP: using thread context class loader (WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@ee0cc23
) for search
JAXP: Looking up system property 'javax.xml.xpath.XPathFactory:http://java.sun.com/jaxp/xpath/dom'
JAXP: The property is undefined.
JAXP: found null in $java.home/jaxp.properties
JAXP: no META-INF/services/javax.xml.xpath.XPathFactory file was found
JAXP: attempting to use the platform default W3C DOM XPath lib
JAXP: instanciating com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl

Troubling, I might say. I went digging into the code, and found this:
if (cl == null) {
enumeration = ClassLoader.getSystemResources(name);
} else {
enumeration = cl.getSystemResources(name);
}
This is in javax.xml.xpath.SecuritySupport.getResources(String name), which is called by the factoryfinder with parameter "META-INF/services/javax.xml.xpath.XPathFactory". I am surprised by the "else" statement: it seems to me that this will not search the context classloader but only the system classloader, and it should read "cl.getResources(name)". The other JAXP factory finders (the ones for parsers or transform) seem to be doing the latter.

Is this intended?

Message was edited by: bruyeron

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

And, for your information, jdk 6u3 is scheduled to be available in late October, 2007.

bruyeron
Offline
Joined: 2004-07-12
Points: 0

I've just ran some tests on JDK6 as well, same problem.
This definitely does not look right to me.

I just tried dropping a xercesImpl.jar in my webapp, and indeed SAXParserFactory.newInstance() picks up xerces instead of the JDK implementation, thanks to the META-INF/services/javax.xml.parsers.SAXParserFactory inside the xercesImpl.jar

Therefore the JAXP service resolution does not work the same for javax.xml.parsers (or javax.xml.transform) and javax.xml.xpath - is this right?

Looking back at the javax.xml.xpath.SecuritySupport.getResources(ClassLoader, String) code shipped with JDK5 (or JDK6), this definitely looks like a bug:
if (cl == null) {
enumeration = ClassLoader.getSystemResources(name);
} else {
enumeration = cl.getSystemResources(name);
}

The else statement actually does the same thing as the if statement because getSystemResources() is a static method on ClassLoader. I think this was meant to read:
if (cl == null) {
enumeration = ClassLoader.getSystemResources(name);
} else {
enumeration = cl.getResources(name);
}

bruyeron
Offline
Joined: 2004-07-12
Points: 0

http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6354969

I guess i should have started there...

bruyeron
Offline
Joined: 2004-07-12
Points: 0

The bug above is (incorrectly) closed - how do we go about and make sure it does not slip through the cracks again?
FYI, the bug was reported on 1.5.0_02, and is reported fixed, however 1.5.0_11 and 1.6.0u1 are still affected.

bruyeron
Offline
Joined: 2004-07-12
Points: 0

Still no fix in the recently release jdk6u2...

spericas
Offline
Joined: 2003-06-10
Points: 0

The fix is in JAXP 1.4.2 RI. See here,

https://jaxp-sources.dev.java.net/source/browse/jaxp-sources/jaxp-api/sr...

which is available from https://jaxp.dev.java.net. It will also be JDK 6u3. Sorry we couldn't get it out sooner. In the mean time, you could try JAXP 1.4.2 RI. Thanks.

spericas
Offline
Joined: 2003-06-10
Points: 0

What version of the JDK or of JAXP RI are you using?

bruyeron
Offline
Joined: 2004-07-12
Points: 0

Good point, I meant to include this information and forgot...

JDK5, Tomcat 5.5.23, and whatever JAXP is included in the JDK.