-
Bug
-
Resolution: Fixed
-
P3
-
5.0
-
b41
-
generic
-
generic
According to spec , evaluate() should throw NPE if expression or returnType is null
XPath.evaluate(java.lang.String expression, java.net.URL documentURL)
XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
---------------------------------------------------------------------------
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 Test8.java
java Test8
checkXPath41() - failed : expecting NPE , but XPathExpressionException thrown
checkXPath46() - failed : expecting NPE , but XPathExpressionException thrown
checkXPath47() - failed : expecting NPE , but XPathExpressionException thrown
---------------------------------------------------------------------------
Testcase - Test8.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>
---------------------------------------------------------------------------
// checkXPath41()
// checkXPath46()
// evaluate() should throw NPE when expression or returnType is null
/*
According to spec , evaluate() should throw NPE if expression or returnType is null
XPath.evaluate(java.lang.String expression, java.net.URL documentURL)
XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
*/
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 java.net.URL;
public class Test8 {
URL url = null;
Test8 () { }
// main()
public static void main(String[] argv) {
Test8 xpath01 = new Test8();
xpath01.init();
xpath01.checkXPath41();
xpath01.checkXPath46();
xpath01.checkXPath47();
}
// 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, java.net.URL documentURL)
// expression is null , should throw NPE
private void checkXPath41() {
try{
XPathFactory xpathFactory = XPathFactory.newInstance();
if( xpathFactory instanceof XPathFactory ){
XPath xpath = xpathFactory.newXPath();
if ( xpath instanceof XPath ){
String expression = null;
String quantity = (String) xpath.evaluate(expression, url);
System.out.println("checkXPath41() : failed - expected NPE not thrown");
}
else{
System.out.println("checkXPath41() failed - xpath not instance of XPath");
}
}else{
System.out.println(" checkXPath41() failed - creating instance of XPathFactory ");
}
}catch(NullPointerException npe ){
System.out.println(" checkXPath41() - passed , expected NPE thrown ");
}catch(XPathFactoryConfigurationException xpfce ){
System.out.println(" checkXPath41() - failed , Default object model not available ");
}catch(XPathExpressionException xpee ){
System.out.println(" checkXPath41() - failed : expecting NPE , but XPathExpressionException thrown ");
}catch(Exception e){
System.out.println(" Exception thrown - checkXPath41() failed ");
}
}
// test for XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
// expression is null , should throw NPE
private void checkXPath46() {
try{
XPathFactory xpathFactory = XPathFactory.newInstance();
if( xpathFactory instanceof XPathFactory ){
XPath xpath = xpathFactory.newXPath();
if ( xpath instanceof XPath ){
String expression = null;
String quantity = (String) xpath.evaluate(expression, url, XPathConstants.STRING);
System.out.println("checkXPath46() : failed - expected NPE not thrown" );
}
else{
System.out.println("checkXPath46() failed - xpath not instance of XPath");
}
}else{
System.out.println(" checkXPath46() failed - creating instance of XPathFactory ");
}
}catch(NullPointerException npe ){
System.out.println(" checkXPath46() - passed , expected NPE thrown ");
}catch(XPathFactoryConfigurationException xpfce ){
System.out.println(" checkXPath46() - failed , Default object model not available ");
}catch(XPathExpressionException xpee ){
System.out.println(" checkXPath46() - failed : expecting NPE , but XPathExpressionException thrown ");
}catch(Exception e){
System.out.println(" Exception thrown - checkXPath46() failed ");
}
}
// test for XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
// returnType is null , should throw NPE
private void checkXPath47() {
try{
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, null);
System.out.println("checkXPath47() : failed - expected NPE not thrown" );
}
else{
System.out.println("checkXPath47() failed - xpath not instance of XPath");
}
}else{
System.out.println(" checkXPath47() failed - creating instance of XPathFactory ");
}
}catch(NullPointerException npe ){
System.out.println(" checkXPath47() - passed , expected NPE thrown ");
}catch(XPathFactoryConfigurationException xpfce ){
System.out.println(" checkXPath47() - failed , Default object model not available ");
}catch(XPathExpressionException xpee ){
System.out.println(" checkXPath47() - failed : expecting NPE , but XPathExpressionException thrown ");
}catch(Exception e){
System.out.println(" Exception thrown - checkXPath47() failed ");
}
}
}
---------------------------------------------------------------------------
XPath.evaluate(java.lang.String expression, java.net.URL documentURL)
XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
---------------------------------------------------------------------------
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 Test8.java
java Test8
checkXPath41() - failed : expecting NPE , but XPathExpressionException thrown
checkXPath46() - failed : expecting NPE , but XPathExpressionException thrown
checkXPath47() - failed : expecting NPE , but XPathExpressionException thrown
---------------------------------------------------------------------------
Testcase - Test8.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>
---------------------------------------------------------------------------
// checkXPath41()
// checkXPath46()
// evaluate() should throw NPE when expression or returnType is null
/*
According to spec , evaluate() should throw NPE if expression or returnType is null
XPath.evaluate(java.lang.String expression, java.net.URL documentURL)
XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
*/
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 java.net.URL;
public class Test8 {
URL url = null;
Test8 () { }
// main()
public static void main(String[] argv) {
Test8 xpath01 = new Test8();
xpath01.init();
xpath01.checkXPath41();
xpath01.checkXPath46();
xpath01.checkXPath47();
}
// 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, java.net.URL documentURL)
// expression is null , should throw NPE
private void checkXPath41() {
try{
XPathFactory xpathFactory = XPathFactory.newInstance();
if( xpathFactory instanceof XPathFactory ){
XPath xpath = xpathFactory.newXPath();
if ( xpath instanceof XPath ){
String expression = null;
String quantity = (String) xpath.evaluate(expression, url);
System.out.println("checkXPath41() : failed - expected NPE not thrown");
}
else{
System.out.println("checkXPath41() failed - xpath not instance of XPath");
}
}else{
System.out.println(" checkXPath41() failed - creating instance of XPathFactory ");
}
}catch(NullPointerException npe ){
System.out.println(" checkXPath41() - passed , expected NPE thrown ");
}catch(XPathFactoryConfigurationException xpfce ){
System.out.println(" checkXPath41() - failed , Default object model not available ");
}catch(XPathExpressionException xpee ){
System.out.println(" checkXPath41() - failed : expecting NPE , but XPathExpressionException thrown ");
}catch(Exception e){
System.out.println(" Exception thrown - checkXPath41() failed ");
}
}
// test for XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
// expression is null , should throw NPE
private void checkXPath46() {
try{
XPathFactory xpathFactory = XPathFactory.newInstance();
if( xpathFactory instanceof XPathFactory ){
XPath xpath = xpathFactory.newXPath();
if ( xpath instanceof XPath ){
String expression = null;
String quantity = (String) xpath.evaluate(expression, url, XPathConstants.STRING);
System.out.println("checkXPath46() : failed - expected NPE not thrown" );
}
else{
System.out.println("checkXPath46() failed - xpath not instance of XPath");
}
}else{
System.out.println(" checkXPath46() failed - creating instance of XPathFactory ");
}
}catch(NullPointerException npe ){
System.out.println(" checkXPath46() - passed , expected NPE thrown ");
}catch(XPathFactoryConfigurationException xpfce ){
System.out.println(" checkXPath46() - failed , Default object model not available ");
}catch(XPathExpressionException xpee ){
System.out.println(" checkXPath46() - failed : expecting NPE , but XPathExpressionException thrown ");
}catch(Exception e){
System.out.println(" Exception thrown - checkXPath46() failed ");
}
}
// test for XPath.evaluate(java.lang.String expression, java.net.URL documentURL, QName returnType)
// returnType is null , should throw NPE
private void checkXPath47() {
try{
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, null);
System.out.println("checkXPath47() : failed - expected NPE not thrown" );
}
else{
System.out.println("checkXPath47() failed - xpath not instance of XPath");
}
}else{
System.out.println(" checkXPath47() failed - creating instance of XPathFactory ");
}
}catch(NullPointerException npe ){
System.out.println(" checkXPath47() - passed , expected NPE thrown ");
}catch(XPathFactoryConfigurationException xpfce ){
System.out.println(" checkXPath47() - failed , Default object model not available ");
}catch(XPathExpressionException xpee ){
System.out.println(" checkXPath47() - failed : expecting NPE , but XPathExpressionException thrown ");
}catch(Exception e){
System.out.println(" Exception thrown - checkXPath47() failed ");
}
}
}
---------------------------------------------------------------------------
- relates to
-
JDK-4972843 XPath.evaluate: XPathExpressionException is thrown instead of NPE
- Resolved