XPath.evaluate() problem with unexpanded entity references
----------------------------------------------------------
Key: XALANJ-2449
URL: https://issues.apache.org/jira/browse/XALANJ-2449
Project: XalanJ2
Issue Type: Bug
Security Level: No security risk; visible to anyone (Ordinary problems in
Xalan projects. Anybody can view the issue.)
Environment: windows xp
java 1.5.0
Reporter: Kevin Froese
XPath.evaluate() throws a NullPointerException when called on a document that
has an unexpanded entity reference node. No problem occurs when the call is
made on the same document with the entity reference expanded. The following
code reproduces the problem:
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;
import org.w3c.dom.Document;
public class XPathTest {
private static final String DOCUMENT_CONTENT =
"<?xml version=\"1.0\"?>" +
"<!DOCTYPE test [<!ENTITY foo SYSTEM \"foo\">]>" +
"<test>&foo;</test>";
private static final String XPATH = "//test";
public static void main(String[] args) {
try {
Document document = createDocument(DOCUMENT_CONTENT);
XPathFactory xpathFactory = XPathFactory.newInstance();
XPath xpath = xpathFactory.newXPath();
xpath.evaluate(XPATH, document, XPathConstants.NODESET);
System.out.println("OK");
} catch(Exception exception) {
System.err.println("Caught exception: " + exception.getMessage());
exception.printStackTrace(System.err);
return;
}
}
public static Document createDocument(String content) throws Exception {
try {
DocumentBuilderFactory documentBuilderFactory =
DocumentBuilderFactory.newInstance();
documentBuilderFactory.setFeature("http://xml.org/sax/features/external-general-entities",
false);
documentBuilderFactory.setFeature("http://apache.org/xml/features/dom/create-entity-ref-nodes",
true);
DocumentBuilder documentBuilder =
documentBuilderFactory.newDocumentBuilder();
byte[] contentBytes = content.getBytes();
ByteArrayInputStream inputStream = new ByteArrayInputStream(contentBytes);
Document document = documentBuilder.parse(inputStream);
return document;
} catch(Exception exception) {
System.err.println("Caught exception: " + exception.getMessage());
exception.printStackTrace(System.err);
System.exit(1);
}
return null;
}
}
The exception has the following stack trace:
java.lang.NullPointerException
at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.nextNode(DOM2DTM.java:347)
at
org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$IndexedDTMAxisTraverser.getNextIndexed(DTMDefaultBaseTraversers.java:572)
at
org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$DescendantTraverser.next(DTMDefaultBaseTraversers.java:740)
at
org.apache.xpath.axes.DescendantIterator.nextNode(DescendantIterator.java:214)
at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:335)
at org.apache.xpath.axes.NodeSequence.runTo(NodeSequence.java:494)
at org.apache.xml.dtm.ref.DTMNodeList.<init>(DTMNodeList.java:81)
at org.apache.xpath.objects.XNodeSet.nodelist(XNodeSet.java:346)
at org.apache.xpath.jaxp.XPathImpl.getResultAsType(XPathImpl.java:329)
at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:282)
at XPathTest.main(XPathTest.java:28)
--------------- linked to ------------------
javax.xml.xpath.XPathExpressionException: java.lang.NullPointerException
at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:287)
at XPathTest.main(XPathTest.java:28)
Caused by: java.lang.NullPointerException
at org.apache.xml.dtm.ref.dom2dtm.DOM2DTM.nextNode(DOM2DTM.java:347)
at
org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$IndexedDTMAxisTraverser.getNextIndexed(DTMDefaultBaseTraversers.java:572)
at
org.apache.xml.dtm.ref.DTMDefaultBaseTraversers$DescendantTraverser.next(DTMDefaultBaseTraversers.java:740)
at
org.apache.xpath.axes.DescendantIterator.nextNode(DescendantIterator.java:214)
at org.apache.xpath.axes.NodeSequence.nextNode(NodeSequence.java:335)
at org.apache.xpath.axes.NodeSequence.runTo(NodeSequence.java:494)
at org.apache.xml.dtm.ref.DTMNodeList.<init>(DTMNodeList.java:81)
at org.apache.xpath.objects.XNodeSet.nodelist(XNodeSet.java:346)
at org.apache.xpath.jaxp.XPathImpl.getResultAsType(XPathImpl.java:329)
at org.apache.xpath.jaxp.XPathImpl.evaluate(XPathImpl.java:282)
... 1 more
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]