United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6202043 XPathFactory.newFactory assumes wrong format for META-INF/services entry
JDK-6202043 : XPathFactory.newFactory assumes wrong format for META-INF/services entry

Details
Type:
Bug
Submit Date:
2004-11-30
Status:
Resolved
Updated Date:
2012-06-08
Project Name:
JDK
Resolved Date:
2005-11-11
Component:
xml
OS:
windows_xp
Sub-Component:
jaxp
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
1.4.0 (1.4)

Related Reports

Sub Tasks

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

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
EVALUATION

Fix available in Mustang b56
                                     
2005-11-11



Hardware and Software, Engineered to Work Together