Details
-
Bug
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.1 Final
-
None
-
None
-
Operating System: Linux
Platform: All
-
26899
Description
It seems that for certain XPaths, JXPathContext.getValue(String xpath) does not
through a JXPathException when the expression does not match any nodes, even if
lenient is set to false, and returns null instead.
An example: if the XPath is
/root/foo[@name='attrName']/*
for XML document
<root><foo name="attrName"><value>blahblah</value></foo></root>
Then JXPathContext.newContext( dom ).getValue() returns "blahblah".
If the node <foo name="attrName">...</foo> does not exist, then getValue()
returns null, instead of throwin a JXPathException.
However, if the expression is
/root/foo[@name='attrName'] ( lacking the ending /* )
then getValue() does throw a JXPathException if the node does not exist; and
the correct value if the node does exist.
The fact that expression "/root/foo[@name='attrName']/*" works when the node
exists leads me to believe it is a valid xpath expression?
Tracing through the JXPath code a bit, in
JXPathContextReferenceImpl.getValue(xpath, expr), line 287,
expr.computeValue(getEvalContext()) is returning null for the case above where
the node doesn't exist. Since null is not an instanceof EvalContext or
NodePointer, it is just returned as-is.
The DOM parser being used is Apache Xerces.
Thanks,
Matias