Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2076574 | 5.0 | Ramesh Mandava | P3 | Closed | Fixed | b32 |
Name: eaR10174 Date: 10/30/2003
The method javax.xml.xpath.XPath.evaluate(String,Object,QName) throws
NullPointerException in case when an expression containing a variable is evaluated and a
variable resolver returns null for that variable (see test.java below). According
to the javadoc:
public Object evaluate(String expression,
Object item,
QName returnType)
throws XPathException
...
If the expression contains a variable reference, its value will be be found through
the variable resolver. An exception is raised if the variable resolver is undefined
or the resolver returns null for the variable.
...
If expression, item or returnType is null, a NullPointerException is thrown.
...
Throws:
XPathException - If expression cannot be evaluated
NullPointerException should not be thrown. In such a case XPathException should be thrown.
The bug appears in jdk1.5.0beta-b25 and affects a new JCK1.5 test:
api/javax_xml/xpath/XPath/index.html#Evaluate[Evaluate031]
------------------------------------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.xpath.XPathException;
import javax.xml.xpath.XPathVariableResolver;
public class test {
public static void main (String[] args) {
try {
String expr = "$v";
XPathFactory xpf = XPathFactory.newInstance(XPathConstants.DOM_OBJECT_MODEL);
XPath xpath = xpf.newXPath();
XPathVariableResolver varResolver = new XPathVariableResolver() {
public Object resolveVariable(QName variableName) {
return null;
}
};
xpath.setVariableResolver(varResolver);
xpath.evaluate(expr, (Object)null, XPathConstants.NUMBER);
System.out.println("XPathException not thrown.");
} catch (XPathException e) {
System.out.println("OK: " + e.getMessage());
} catch (NullPointerException e) {
e.printStackTrace();
}
}
}
--------------------------------------------------------------------------
% java -showversion test
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b25)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b25, mixed mode)
java.lang.NullPointerException
at
com.sun.org.apache.xpath.internal.objects.XObject.getTypeString(XObject.java:256)
at com.sun.org.apache.xpath.internal.objects.XObject.num(XObject.java:269)
at
com.sun.org.apache.xpath.internal.jaxp.XPathImpl.getResultAsType(XPathImpl.java:201)
at com.sun.org.apache.xpath.internal.jaxp.XPathImpl.evaluate(XPathImpl.java:182)
at test.main(test.java:22)
--------------------------------------------------------------------------
======================================================================
- backported by
-
JDK-2076574 NPE is thrown if XPathVariableResolver returns null
- Closed