JDK-6202043 : XPathFactory.newFactory assumes wrong format for META-INF/services entry
  • Type: Bug
  • Component: xml
  • Sub-Component: jaxp
  • Affected Version: 5.0
  • Priority: P2
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2004-11-30
  • Updated: 2012-06-08
  • Resolved: 2005-11-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 1.4Fixed
Description
FULL PRODUCT VERSION :
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
Java HotSpot(TM) Client VM (build 1.5.0-b64, mixed mode, sharing)


A DESCRIPTION OF THE PROBLEM :
javax.xml.xpath.XpathFactoryFinder assumes that the META-INF/services/javax.xml.xpath.XPathFactory file is a properties file instead of the format specified by the jar service provider documentation:

http://java.sun.com/j2se/1.5.0/docs/guide/jar/jar.html#Service%20Provider


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Create an implementation of XPathFactory with the following method:
public class BasicXPathFactory extends XPathFactory {
   ....
    public boolean isObjectModelSupported(String objectModel) {
       // match any object model for testing.
        return true;
    }
    ...
}

2. Create the text file META-INF/services/javax.xml.xpath.XPathFactory containing only the name of the implementation class on a single line.

3. Create a new factory instance.
XPathFactory  factory = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);





EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The expected result is an instance of BasicXPathFactory.

ACTUAL -
The instance was null.


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package bugs;

public class BasicXPathFactory extends XPathFactory {
    /**
     *
     */
    public BasicXPathFactory() {
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.xml.xpath.XPathFactory#isObjectModelSupported(java.lang.String)
     */
    public boolean isObjectModelSupported(String objectModel) {
            return true;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.xml.xpath.XPathFactory#setFeature(java.lang.String, boolean)
     */
    public void setFeature(String name, boolean value) throws XPathFactoryConfigurationException {
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.xml.xpath.XPathFactory#getFeature(java.lang.String)
     */
    public boolean getFeature(String name) throws XPathFactoryConfigurationException {
          return false;
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.xml.xpath.XPathFactory#setXPathVariableResolver(javax.xml.xpath.XPathVariableResolver)
     */
    public void setXPathVariableResolver(XPathVariableResolver resolver) {
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.xml.xpath.XPathFactory#setXPathFunctionResolver(javax.xml.xpath.XPathFunctionResolver)
     */
    public void setXPathFunctionResolver(XPathFunctionResolver resolver) {
    }

    /*
     * (non-Javadoc)
     *
     * @see javax.xml.xpath.XPathFactory#newXPath()
     */
    public XPath newXPath() {
        // not needed for the test.
        return null;
    }

    public static void main(String[] argc)
    {
         XPathFactory factory =  XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);

        if (factory instanceof BasicXPathFactory)
        {
             System.out.println("Passed");
        }
       else
       {
             System.out.println("Failed");
        }
    }
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
The code assumes that META-INF/services/javax.xml.xpath.XPathFactory is a property file.  Add an entry in the property file for each object model that your code supports.

http\://java.sun.com/jaxp/xpath/dom=bugs.BasicXPathFactory

Comments
EVALUATION Fix available in Mustang b56
2005-11-11

EVALUATION this is a clear violation of JSR 206 that impacts portability and plugability. the priority is being raised. ###@###.### 2004-11-30 22:06:59 GMT
2004-11-30