XMLDog 2.2.2 NPE
KR-Neo opened this issue · 5 comments
KR-Neo commented
When upgrading XMLDog from 2.1 to 2.2.2, I am getting a NPE in Event.fireEndAttributes()
Checking id.onEndAttributes() throws as id is null.
santhosh-tekuri commented
steps to reproduce ?
KR-Neo commented
What would continue after sniff is to get get a list of items from the results using the expression object results.getResult(expression)
and work on the resulting list. In this case the list would only be one long but this example is enough to cause the NPE at sniff. Is this still correct usage?
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.xpath.XPathException;
import org.jaxen.saxpath.SAXPathException;
import org.xml.sax.InputSource;
import jlibs.xml.DefaultNamespaceContext;
import jlibs.xml.sax.dog.XMLDog;
import jlibs.xml.sax.dog.XPathResults;
import jlibs.xml.sax.dog.expr.Expression;
import jlibs.xml.sax.dog.sniff.DOMBuilder;
import jlibs.xml.sax.dog.sniff.Event;
public class XMLDogTest {
public static void main(String[] args) {
try {
String xml = """
<?xml version="1.0" encoding="UTF-8"?>
<bookstore>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
</bookstore>
""";
ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes());
BufferedInputStream bis = new BufferedInputStream(bais);
DefaultNamespaceContext nsContext = new DefaultNamespaceContext();
XMLDog dog = new XMLDog(nsContext);
Expression expression = dog.addXPath("/bookstore/book[1]");
Event event = dog.createEvent();
XPathResults results = new XPathResults(event);
event.setListener(results);
event.setXMLBuilder(new DOMBuilder());
InputSource source = new InputSource(bis);
source.setEncoding("UTF-8");
dog.sniff(event, source, true);
bis.close();
} catch (SAXPathException | IOException | XPathException e) {
e.printStackTrace();
}
}
}
santhosh-tekuri commented
able to reproduce following NPE:
java.lang.NullPointerException
at jlibs.xml.sax.dog.sniff.Event.fireEndAttributes(Event.java:233)
at jlibs.xml.sax.dog.sniff.Event.onAttributes(Event.java:686)
at jlibs.xml.sax.dog.sniff.SAXHandler.startElement(SAXHandler.java:57)
at jlibs.xml.sax.SAXDelegate.startElement(SAXDelegate.java:105)
at jlibs.xml.stream.STAXXMLReader.fire(STAXXMLReader.java:128)
at jlibs.xml.stream.STAXXMLReader.parse(STAXXMLReader.java:76)
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:189)
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:174)
at jlibs.examples.xml.sax.dog.BugTest.main(BugTest.java:59)
--------------- linked to ------------------
javax.xml.xpath.XPathException: java.lang.NullPointerException
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:192)
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:174)
at jlibs.examples.xml.sax.dog.BugTest.main(BugTest.java:59)
Caused by: java.lang.NullPointerException
at jlibs.xml.sax.dog.sniff.Event.fireEndAttributes(Event.java:233)
at jlibs.xml.sax.dog.sniff.Event.onAttributes(Event.java:686)
at jlibs.xml.sax.dog.sniff.SAXHandler.startElement(SAXHandler.java:57)
at jlibs.xml.sax.SAXDelegate.startElement(SAXDelegate.java:105)
at jlibs.xml.stream.STAXXMLReader.fire(STAXXMLReader.java:128)
at jlibs.xml.stream.STAXXMLReader.parse(STAXXMLReader.java:76)
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:189)
... 2 more
--------------- linked to ------------------
javax.xml.xpath.XPathException: javax.xml.xpath.XPathException: java.lang.NullPointerException
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:176)
at jlibs.examples.xml.sax.dog.BugTest.main(BugTest.java:59)
Caused by: javax.xml.xpath.XPathException: java.lang.NullPointerException
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:192)
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:174)
... 1 more
Caused by: java.lang.NullPointerException
at jlibs.xml.sax.dog.sniff.Event.fireEndAttributes(Event.java:233)
at jlibs.xml.sax.dog.sniff.Event.onAttributes(Event.java:686)
at jlibs.xml.sax.dog.sniff.SAXHandler.startElement(SAXHandler.java:57)
at jlibs.xml.sax.SAXDelegate.startElement(SAXDelegate.java:105)
at jlibs.xml.stream.STAXXMLReader.fire(STAXXMLReader.java:128)
at jlibs.xml.stream.STAXXMLReader.parse(STAXXMLReader.java:76)
at jlibs.xml.sax.dog.XMLDog.sniff(XMLDog.java:189)
... 2 more
santhosh-tekuri commented
fixed in 5a3c9bd
santhosh-tekuri commented
the fix is available in 3.0.0-SNAPSHOT
you have to add sonatype snapshot repository to your pom:
<repositories>
<repository>
<id>oss.sonatype.org-snapshot</id>
<url>http://oss.sonatype.org/content/repositories/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>