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

XPath.evaluate: XPathExpressionException is thrown instead of NPE

XMLWordPrintable

    • 1.3
    • generic
    • generic



        Name: eaR10174 Date: 12/26/2003


        The methods

             javax.xml.xpath.XPath.evaluate(String expression, InputSource source, QName returnType)
             javax.xml.xpath.XPath.evaluate(String expression, InputSource source)
             javax.xml.xpath.XPath.evaluate(String expression, URL documentURL, QName returnType)
             javax.xml.xpath.XPath.evaluate(String expression, URL documentURL)

        throw XPathExpressionException instead of NullPointerException in cases when the methods
        are called with either null expression or null returnType.The methods should throw the
        NullPointerException according to the javadoc.

        The bug affects new JCK1.5 tests (not integrated yet):

           api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate053]
           api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate055]
           api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate057]
           api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate059]
           api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate061]
           api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate063]

        The following test fails running on JDK 1.5.0-beta-b32.
        See below the test source and the execution log:
        ------------------------------------test.xml------------------------------
        <?xml version='1.0'?>
        <root/>
        ------------------------------------Test.java-----------------------------
        import javax.xml.xpath.XPath;
        import javax.xml.xpath.XPathFactory;
        import javax.xml.xpath.XPathConstants;
        import java.io.StringReader;
        import java.io.File;
        import org.xml.sax.InputSource;
        import java.net.URL;

        public class Test {
             public static final String XML = "<?xml version='1.0'?>\n"
                                            + "<root/>\n";
             private XPath xpath;

             public static void main (String[] args) {
                 try {
                     Test test = new Test();
                     test.case01();
                     test.case02();
                     test.case03();
                     test.case04();
                     test.case05();
                     test.case06();
                 } catch (Exception e) {
                     e.printStackTrace();
                     System.exit(1);
                 }
             }

             public Test() throws Exception {
                 XPathFactory xpf = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
                 xpath = xpf.newXPath();
             }

             public void case01() {
                 System.out.print("case01 - ");
                 try {
                     StringReader reader = new StringReader(XML);
                     InputSource inSource = new InputSource(reader);

                     xpath.evaluate((String)null, inSource, XPathConstants.NUMBER);
                     System.out.println("Failed: exception was not thrown.");
                 } catch (NullPointerException e) {
                     System.out.println("OK");
                 } catch (Exception e) {
                     System.out.println("Failed: " + e.toString());
                 }
             }

             public void case02() {
                 System.out.print("case02 - ");
                 try {
                     StringReader reader = new StringReader(XML);
                     InputSource inSource = new InputSource(reader);

                     xpath.evaluate("/", inSource, null);
                     System.out.println("Failed: exception was not thrown.");
                 } catch (NullPointerException e) {
                     System.out.println("OK");
                 } catch (Exception e) {
                     System.out.println("Failed: " + e.toString());
                 }
             }

             public void case03() {
                 System.out.print("case03 - ");
                 try {
                     StringReader reader = new StringReader(XML);
                     InputSource inSource = new InputSource(reader);

                     xpath.evaluate((String)null, inSource);
                     System.out.println("Failed: exception was not thrown.");
                 } catch (NullPointerException e) {
                     System.out.println("OK");
                 } catch (Exception e) {
                     System.out.println("Failed: " + e.toString());
                 }
             }

             public void case04() {
                 System.out.print("case04 - ");
                 try {
                     URL url = new File("test.xml").toURL();

                     xpath.evaluate((String)null, url, XPathConstants.NUMBER);
                     System.out.println("Failed: exception was not thrown.");
                 } catch (NullPointerException e) {
                     System.out.println("OK");
                 } catch (Exception e) {
                     System.out.println("Failed: " + e.toString());
                 }
             }

             public void case05() {
                 System.out.print("case05 - ");
                 try {
                     URL url = new File("test.xml").toURL();

                     xpath.evaluate("/", url, null);
                     System.out.println("Failed: exception was not thrown.");
                 } catch (NullPointerException e) {
                     System.out.println("OK");
                 } catch (Exception e) {
                     System.out.println("Failed: " + e.toString());
                 }
             }

             public void case06() {
                 System.out.print("case06 - ");
                 try {
                     URL url = new File("test.xml").toURL();

                     xpath.evaluate((String)null, url);
                     System.out.println("Failed: exception was not thrown.");
                 } catch (NullPointerException e) {
                     System.out.println("OK");
                 } catch (Exception e) {
                     System.out.println("Failed: " + e.toString());
                 }
             }
        }
        --------------------------------------------------------------------------
        % java -showversion test
        java version "1.5.0-beta"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b32)
        Java HotSpot(TM) Client VM (build 1.5.0-beta-b32, mixed mode)

        case01 - Failed: javax.xml.xpath.XPathExpressionException: java.lang.NullPointerException: XPath
        expression OR returnType can't be null
        case02 - Failed: javax.xml.xpath.XPathExpressionException: java.lang.NullPointerException: XPath
        expression OR returnType can't be null
        case03 - Failed: javax.xml.xpath.XPathExpressionException: java.lang.NullPointerException: XPath
        expression OR returnType can't be null
        case04 - Failed: javax.xml.xpath.XPathExpressionException: java.lang.NullPointerException: XPath
        expression OR returnType can't be null
        case05 - Failed: javax.xml.xpath.XPathExpressionException: java.lang.NullPointerException: XPath
        expression OR returnType can't be null
        case06 - Failed: javax.xml.xpath.XPathExpressionException: java.lang.NullPointerException: XPath
        expression OR returnType can't be null
        --------------------------------------------------------------------------

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

              rmandavasunw Ramesh Mandava (Inactive)
              evgsunw Evg Evg (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: