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

XPathExpression.evaluate: IAE is not thrown for illegal return types

    Details

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

      Backports

        Description



        Name: eaR10174 Date: 12/24/2003


        The methods

             javax.xml.xpath.XPathExpression.evaluate(Object, QName)
             javax.xml.xpath.XPathExpression.evaluate(InputSource, QName)
             javax.xml.xpath.XPathExpression.evaluate(URL, QName)

        do not throw IllegalArgumentException in case when a return type is not one of the types defined in
        XPathConstants. The methods should throw the exception according to the javadoc.

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

           api/javax_xml/xpath/XPathExpression/index.html#Evaluate[Evaluate053]
           api/javax_xml/xpath/XPathExpression/index.html#Evaluate[Evaluate055]
           api/javax_xml/xpath/XPathExpression/index.html#Evaluate[Evaluate056]

        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 javax.xml.xpath.XPathExpression;
        import javax.xml.namespace.QName;
        import java.io.StringReader;
        import java.io.File;
        import org.xml.sax.InputSource;
        import java.net.URL;
        import javax.xml.parsers.DocumentBuilder;
        import javax.xml.parsers.DocumentBuilderFactory;
        import org.w3c.dom.Node;

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

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

             public Test() throws Exception {
                 XPathFactory xpf = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
                 XPath xpath = xpf.newXPath();
                 xpathExpression = xpath.compile("1+1");
             }

             public void case01() {
                 System.out.print("case01 - ");
                 try {
                     DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
                     DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
                     StringReader reader = new StringReader(XML);
                     InputSource inSource = new InputSource(reader);
                     Node document = docBuilder.parse(inSource);

                     xpathExpression.evaluate(document, new QName("int"));
                     System.out.println("Failed: exception was not thrown.");
                 } catch (IllegalArgumentException 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);

                     xpathExpression.evaluate(inSource, new QName("int"));
                     System.out.println("Failed: exception was not thrown.");
                 } catch (IllegalArgumentException e) {
                     System.out.println("OK");
                 } catch (Exception e) {
                     System.out.println("Failed: " + e.toString());
                 }
             }

             public void case03() {
                 System.out.print("case03 - ");
                 try {
                     URL url = new File("test.xml").toURL();
                     xpathExpression.evaluate(url, new QName("int"));
                     System.out.println("Failed: exception was not thrown.");
                 } catch (IllegalArgumentException 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: exception was not thrown.
        case02 - Failed: exception was not thrown.
        case03 - Failed: exception was not thrown.
        --------------------------------------------------------------------------

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

          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: