Skip to main content

Possible javax.xml.stream.XMLInputFactory problem

3 replies [Last post]
joe_hart
Offline
Joined: 2007-12-07

I think that javax.xml.stream.XMLInputFactory.newInstance(String, ClassLoader) maybe behaving incorrectly.

Expected Behavior:

The first argument is name of the factory to find (ex "javax.xml.stream.XMLInputFactory"). Using this factory name go though the standard lookup procedure (ie check for a system property, check for $JAVA_HOME/lib/stax.properties, check jar META-INF/services) to determine the concrete class and return an instance loaded with the given classloader.

Actual Behavior:

The method assumes the first argument is the classname of the concrete XMLInputFactory subclass and tries to return an instance loaded by the given classloader.

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

According to the JavaDocs for the method, the purpose is to "Create a new instance of the factory." Plus it would throw "FactoryConfigurationError - if an instance of this factory cannot be loaded". I guess what's confusing is the "Returns" that says "the factory implementation". Nevertheless, a "newInstance" should do what it's supposed to do, that is, creating a new instance. Would you agree?

Thanks.

joe_hart
Offline
Joined: 2007-12-07

I agree that a new instance of a concrete XMLInputFactory should be returned. My problem is with the String argument that is passed into the method.

In the StAX 1.0.1 api (from stax.codehaus.org) the method took the factory id (i.e. "javax.xml.stream.XMLInputFactory"). This factory id would then be used to lookup the concrete class to instanciate.

The Java 1.6 api expects this to be the classname of the factory implementation to return (ex "com.ctc.wstx.stax.WstxInputFactory"). This seems a little silly because if I knew the concrete implementation I could just instanciate it myself.

joehw
Offline
Joined: 2004-12-15

Right, it looks like the original intension was as you stated. But that's a little silly too :) I mean, the property name (i.e. "javax.xml.stream.XMLInputFactory") is already known to the factory. I'm guessing that it is why it was changed in jdk1.6.