question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`NullPointerException` in `DTDValidator.validateElementEnd()` for element undefined in DTD

See original GitHub issue

The 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:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
cowtowncodercommented, Apr 23, 2020

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.

1reaction
cowtowncodercommented, Apr 22, 2020

Thank you! Now I can reproduce this locally, and it seems to be due to undefined element, for which validateElementStart() does not add matching StructValidator (since it is undefined). Should now be able to create simpler test to reproduce, then see what is the best way to resolve.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found