Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6202043

XPathFactory.newFactory assumes wrong format for META-INF/services entry

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.0
    • 5.0
    • xml
    • 1.4
    • x86
    • windows_xp

      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

            sreddysunw Sunitha Reddy (Inactive)
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: