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

throw IAE if returnType is not one of the types defined in XPathConstants

XMLWordPrintable

    • b41
    • generic
    • generic
    • Verified

      According to spec - If returnType is not one of the types defined in
      XPathConstants, then an IllegalArgumentException is thrown.

      XPath.evaluate(java.lang.String expression, InputSource source, QName returnType)
      and
      XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
      does not throw IAE when returnType is not one of the types defined in XPathConstants .

      -------------------------------------------------------------------------------
      java -version
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b37)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b37, mixed mode)

      javac Test10.java
      java Test10
      checkXPath33() failed , expected IAE not thrown
      Quantity : null
      checkXPath50() failed , expected IAE not thrown
      Quantity : null

      -------------------------------------------------------------------------------
      Testcase - Test10.java & sample xml - widgets.xml attached
      **********************************************************
      -------------------------------------------------------------------------------
      <?xml version="1.0" standalone="yes"?>
      <widgets>
      <widget name="a" style="red" quantity="6"/>
      <widget name="b" style="blue"/>
      <widget name="c">
      <style>green</style>
      </widget>
      </widgets>
      -------------------------------------------------------------------------------
      //checkXPath33()
      //checkXPath50()

      /*
      According to spec - If returnType is not one of the types defined in
      XPathConstants, then an IllegalArgumentException is thrown.

      */

      import javax.xml.xpath.XPath;
      import javax.xml.xpath.XPathFactory;
      import javax.xml.xpath.XPathConstants;
      import javax.xml.xpath.XPathExpression;
      import javax.xml.xpath.XPathFactoryConfigurationException;
      import javax.xml.xpath.XPathExpressionException;

      import javax.xml.namespace.QName;
      import javax.xml.XMLConstants;

      import org.xml.sax.InputSource;
      import java.net.URL;

      import java.io.FileInputStream;


      public class Test10 {

         String xmlPath = "";
         URL url = null;
         public static final javax.xml.namespace.QName qname = new QName( XMLConstants.XML_NS_URI , "" );
        
         Test10 () {
           xmlPath = "./";
         }
          
          // main()
          public static void main(String[] argv) {
              Test10 xpath01 = new Test10();
              xpath01.init();
              xpath01.checkXPath33();
              xpath01.checkXPath50();
              
          } // end main()
          
              // initializing
          private void init(){
              try {
                  url = new URL("http://sqindia.india.sun.com/disk06/tea/sreejith/jaxp/widgets.xml");
                        
              }catch (Exception e) {
                System.out.println(" Exception thrown in XPath01/init() - Test failed");
              }
          }


          // test for XPath.evaluate(java.lang.String expression, InputSource source, QName returnType)
          // if returnType is not one of the types defined in XPathConstants , should throw IllegalArgumentException
          private void checkXPath33() {
           try{
           FileInputStream fis = new FileInputStream(xmlPath+"widgets.xml");
                InputSource iSource = new InputSource(fis);
           XPathFactory xpathFactory = XPathFactory.newInstance();
           if( xpathFactory instanceof XPathFactory ){
           XPath xpath = xpathFactory.newXPath();
      if ( xpath instanceof XPath ){
      String expression = "/widgets/widget[@name='a']/@quantity";
      String quantity = (String) xpath.evaluate(expression,iSource,qname);
      System.out.println("checkXPath33() failed , expected IAE not thrown ");
      System.out.println("Quantity : "+quantity);
      }
           else{
           System.out.println("checkXPath33() failed - xpath not instance of XPath");
           }
           }else{
           System.out.println(" checkXPath33() failed - creating instance of XPathFactory ");
           }
           }catch(IllegalArgumentException iae ){
           System.out.println(" checkXPath33() - passed , expected IAE thrown ");
           }catch(XPathFactoryConfigurationException xpfce ){
           System.out.println(" checkXPath33() - failed , Default object model not available ");
           }catch(XPathExpressionException xpee ){
           System.out.println(" checkXPath33() - failed , XPathExpressionException thrown ");
           }catch(Exception e){
           System.out.println(" Exception thrown - checkXPath33() failed ");
           }
          }
          
          
          
          // test for XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
          // if returnType is not one of the types defined in XPathConstants , should throw IllegalArgumentException
          private void checkXPath50() {
           try{
           FileInputStream fis = new FileInputStream(xmlPath+"widgets.xml");
                InputSource iSource = new InputSource(fis);
           XPathFactory xpathFactory = XPathFactory.newInstance();
           if( xpathFactory instanceof XPathFactory ){
           XPath xpath = xpathFactory.newXPath();
      if ( xpath instanceof XPath ){
      String expression = "/widgets/widget[@name='a']/@quantity";
      String quantity = (String) xpath.evaluate(expression,url,qname);
      System.out.println("checkXPath50() failed , expected IAE not thrown ");
      System.out.println("Quantity : "+quantity);
      }
           else{
           System.out.println("checkXPath50() failed - xpath not instance of XPath");
           }
           }else{
           System.out.println(" checkXPath50() failed - creating instance of XPathFactory ");
           }
           }catch(IllegalArgumentException iae ){
           System.out.println(" checkXPath50() - passed , expected IAE thrown ");
           }catch(XPathFactoryConfigurationException xpfce ){
           System.out.println(" checkXPath50() - failed , Default object model not available ");
           }catch(XPathExpressionException xpee ){
           System.out.println(" checkXPath50() - failed , XPathExpressionException thrown ");
           }catch(Exception e){
           System.out.println(" Exception thrown - checkXPath50() failed ");
           }
          }
          
      }
      -------------------------------------------------------------------------------
      ---------------------------------
      verified in Tiger 1.5.0-beta2-b44
      ###@###.### 2004-03-30
      ---------------------------------

            rmandavasunw Ramesh Mandava (Inactive)
            saksunw Sreejith Ak (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: