Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2077296 | 5.0 | Ramesh Mandava | P3 | Closed | Fixed | b32 |
Name: eaR10174 Date: 11/18/2003
The following methods of the class javax.xml.xpath.XPath
public Object evaluate(String expression, Object item,
QName returnType) throws XPathException
public String evaluate(String expression, Object item)
throws XPathException
throw XPathException instead of NullPointerException (see test.java below) in case when
the expression is null.
According to the javadoc the methods should throw NullPointerException in such a case.
The bug appears in jdk1.5.0beta-b28 and affects new JCK1.5 tests:
api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate033]
api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate037]
------------------------------------test.java-----------------------------
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Node;
public class test {
public static void main (String[] args) {
XPath xpath = null;
Node node = null;
try {
XPathFactory xpf = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
xpath = xpf.newXPath();
node = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.newDocument();
} catch (Exception e) {
System.err.println("Can not create xpath.");
e.printStackTrace();
System.exit(1);
}
try {
System.out.println("Invoke evaluate((String)null,Object,QName).");
xpath.evaluate((String)null, node, XPathConstants.STRING);
System.out.println("NPE not thrown.");
} catch (NullPointerException e) {
System.out.println("OK: NPE");
} catch (Exception e) {
e.printStackTrace();
System.err.println("");
}
try {
System.out.println("Invoke evaluate((String)null,Object).");
xpath.evaluate((String)null, node);
System.out.println("NPE not thrown.");
} catch (NullPointerException e) {
System.out.println("OK: NPE");
} catch (Exception e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------------------
% java -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b28)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b28, mixed mode)
Invoke evaluate((String)null,Object,QName).
javax.xml.xpath.XPathException: XPath expression is null
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:179)
at test.main(test.java:25)
Invoke evaluate((String)null,Object).
javax.xml.xpath.XPathException: XPath expression is null
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:179)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:233)
at test.main(test.java:36)
--------------------------------------------------------------------------
======================================================================
- backported by
-
JDK-2077296 XPath.evaluate() methods throw XPathException instead of NPE
- Closed