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

evaluate(expression,source,returnType) should throw NPE if returnType is null

    XMLWordPrintable

Details

    • b41
    • generic
    • generic

    Description

      According to the spec ,
      XPath.evaluate(java.lang.String expression, InputSource source, QName returnType) should throw NPE if returnType is null

      ---------------------------------------------------------------
      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 Test5.java
      java Test5
      checkXPath30() - failed , expecting NPE - but XPathExpressionException thrown
      ---------------------------------------------------------------
      Testcase - Test5.java & widgets.xml attached
      ********************************************
      ---------------------------------------------------------------
      //checkXPath30()
      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 org.xml.sax.InputSource;

      import java.io.FileInputStream;


      public class Test5 {
         
         String xmlPath = "";
         FileInputStream fis30 = null;
         InputSource iSource30 = null;
         Test5 () {
           xmlPath = "./";
         }
          
          // main()
          public static void main(String[] argv) {
              Test5 test5 = new Test5();
              test5.checkXPath30();
          
          }// end main()
          

          // test for XPath.evaluate(java.lang.String expression, InputSource source, QName returnType)
          // returnType is null , should throw NPE
          private void checkXPath30() {
           try{
           fis30 = new FileInputStream(xmlPath+"widgets.xml");
                iSource30 = new InputSource(fis30);
           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, iSource30, null);
      System.out.println("checkXPath30() : failed - expected NPE not thrown ");
      }
           else{
           System.out.println("checkXPath30() failed - xpath not instance of XPath");
           }
           }else{
           System.out.println(" checkXPath30() failed - creating instance of XPathFactory ");
           }
           }catch(XPathFactoryConfigurationException xpfce ){
           System.out.println(" checkXPath30() - failed , Default object model not available ");
           }catch(XPathExpressionException xpee ){
           System.out.println(" checkXPath30() - failed , expecting NPE - but XPathExpressionException thrown ");
           }catch(Exception e){
           System.out.println(" Exception thrown - checkXPath30() failed ");
           }
          }
          


      }
      ---------------------------------------------------------------

      Attachments

        Activity

          People

            kkawagucsunw Kohsuke Kawaguchi (Inactive)
            saksunw Sreejith Ak (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: