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

XPathExpression.evaluate() throws NPE if VariableResolver returns null

    Details

    • Subcomponent:
    • Resolved In Build:
      1.3
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description



        Name: erR10175 Date: 06/10/2004



        The methods

             javax.xml.xpath.XPathExpression.evaluate(Object item, QName returnType)
             javax.xml.xpath.XPath.evaluate(String expression, Object item, QName returnType)

        throws NullPointerException evaluating simple expressions with variables
        if the variable resolver returns null.

        According to the javadoc of those methods NullPointerException may be thrown only if
        the expression or returnType parameter is null. The tests expect XPathExpressionException
        because the expression cannot be evaluated.

        The bug affects new JCK1.5 tests:

          api/javax_xml/xpath/XPathExpression/index.html#Evaluate[Evaluate030]
          api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate031]

        The following test fails running on JDK 1.5.0-b55.
        See below the test source and the execution log:
        --------------------------------- test.java
        import javax.xml.namespace.QName;
        import javax.xml.xpath.XPath;
        import javax.xml.xpath.XPathConstants;
        import javax.xml.xpath.XPathExpression;
        import javax.xml.xpath.XPathExpressionException;
        import javax.xml.xpath.XPathVariableResolver;
        import javax.xml.xpath.XPathFactory;

        class test {
            public static void main(String [] args) throws Exception {

                XPath xpath = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL)
                              .newXPath();
                XPathVariableResolver varResolver = new XPathVariableResolver() {
                    public Object resolveVariable(QName variableName) {
                        return null;
                    }
                };
                xpath.setXPathVariableResolver(varResolver);
                XPathExpression xpathExpr = xpath.compile("$v");

                try {
                    xpathExpr.evaluate((Object)null, XPathConstants.NUMBER);
                    System.out.println("Failed: XPathExpressionException is not thrown.");
                } catch (XPathExpressionException e) {
                    System.out.println("Passed.");
                }
            }
        }
        -------------------------------------------

        -------------------------------------- log
        $javac test.java && java -showversion test
        java version "1.5.0-beta3"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b55)
        Java HotSpot(TM) Client VM (build 1.5.0-beta3-b55, mixed mode)

        SystemId Unknown; Line #0; Column #0; resolveVariable for variable 'v' returning null
        Exception in thread "main" java.lang.NullPointerException
                at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.getResultAsType(XPathExpressionImpl.java:278)
                at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:76)
                at com.sun.org.apache.xpath.internal.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:162)
                at test.main(test.java:23)
        ------------------------------------------


        ======================================================================

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  rmandavasunw Ramesh Mandava (Inactive)
                  Reporter:
                  reysunw Rey Rey (Inactive)
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  0 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: