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

XPath.evaluate: IAE is thrown instead of NPE

    Details

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

      Backports

        Description



        Name: eaR10174 Date: 12/26/2003


        The methods

             javax.xml.xpath.XPath.evaluate(String, InputSource, QName)
             javax.xml.xpath.XPath.evaluate(String, InputSource)

        throw IllegalArgumentException in case when InputSource is null.
        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[Evaluate054]
           api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate058]

        The following test fails running on JDK 1.5.0-beta-b32.
        See below the test source and the execution log:
        ------------------------------------Test.java-----------------------------
        import javax.xml.xpath.XPath;
        import javax.xml.xpath.XPathFactory;
        import javax.xml.xpath.XPathConstants;
        import org.xml.sax.InputSource;

        public class Test {
             private XPath xpath;

             public static void main (String[] args) {
                 try {
                     Test test = new Test();
                     test.case01();
                     test.case02();
                 } 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 {
                     xpath.evaluate("/", (InputSource)null, XPathConstants.NODE);
                     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 {
                     xpath.evaluate("abc", (InputSource)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());
                 }
             }
        }
        --------------------------------------------------------------------------
        % 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.IllegalArgumentException:
        InputSource cannot be null
        case02 - Failed: javax.xml.xpath.XPathExpressionException: java.lang.IllegalArgumentException:
        InputSource cannot be null
        --------------------------------------------------------------------------

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

          Attachments

            Issue Links

              Activity

                People

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

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Imported:
                    Indexed: