`NullPointerException` in `DTDValidator.validateElementEnd()` for element undefined in DTD
See original GitHub issueThe DTDValidator class is throwing a NullPointerException when processing invalid XML. To reproduce, use this catalog: https://github.com/oasis-tcs/dita/tree/v1.3/doctypes
test.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map>
<topicref>
<ditavalref>
<val><!-- This is invalid -->
<prop att="product" val="win" action="flag" color="black"/>
</val>
</ditavalref>
</topicref>
</map>
WstxValidatorTest.java
import com.ctc.wstx.stax.WstxInputFactory;
import java.io.File;
import java.nio.file.Paths;
import javax.xml.catalog.CatalogFeatures;
import javax.xml.catalog.CatalogManager;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
public class WstxValidatorTest {
public static void main(String[] args) throws XMLStreamException {
var catalog =
CatalogManager.catalogResolver(
CatalogFeatures.defaults(), Paths.get("path/to/catalog.xml").toUri());
var factory = new WstxInputFactory();
factory.setProperty(XMLInputFactory.IS_VALIDATING, true);
factory.setProperty(XMLInputFactory.RESOLVER, catalog);
var reader = factory.createXMLStreamReader(new File("path/to/test.xml"));
reader.setValidationProblemHandler(p -> System.out.println(p.getMessage()));
while (reader.hasNext()) {
reader.next();
}
}
}
Undefined element <val> encountered
Undefined element <prop> encountered
Exception in thread "main" java.lang.NullPointerException
at com.ctc.wstx.dtd.DTDValidator.validateElementEnd(DTDValidator.java:362)
at com.ctc.wstx.sr.InputElementStack.validateEndElement(InputElementStack.java:560)
at com.ctc.wstx.sr.BasicStreamReader.nextFromTree(BasicStreamReader.java:2730)
at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1122)
at WstxValidatorTest.main(WstxValidatorTest.java:22)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (8 by maintainers)
Top Results From Across the Web
java - What is a NullPointerException, and how do I fix it?
Using a for (element : iterable) loop to loop through a null collection/array. ... foo.new SomeInnerClass() throws a NullPointerException when foo is null....
Read more >How to Fix and Avoid NullPointerException in Java - Rollbar
NullPointerException in Java occurs when a variable is accessed which is not pointing to any object and refers to nothing or null.
Read more >Java NullPointerException - Detect, Fix, and Best Practices
The below code snippet shows the example where the valueOf() method is used instead of toString(). Object mutex = null; //prints null System.out ......
Read more >NullPointerException (Java SE 16 & JDK 16)
Class NullPointerException · Constructor Details. NullPointerException. public NullPointerException(). Constructs a NullPointerException with no detail message.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Fixed for next release (either 6.1.2 or 6.2.0, depending a bit on if #103 fix is included and needs minor version bump); also backported in 5.3 branch just in case there’s need for release there.
Thank you! Now I can reproduce this locally, and it seems to be due to undefined element, for which
validateElementStart()
does not add matchingStructValidator
(since it is undefined). Should now be able to create simpler test to reproduce, then see what is the best way to resolve.