Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NullPointerException in DTDValidator.validateElementEnd() for element undefined in DTD #104

Closed
ChrisTrenkamp opened this issue Apr 20, 2020 · 8 comments
Milestone

Comments

@ChrisTrenkamp
Copy link
Contributor

ChrisTrenkamp commented Apr 20, 2020

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)
@cowtowncoder
Copy link
Member

Thank you for reporting the issue; sounds like a bug.

@cowtowncoder
Copy link
Member

Hmmh. One problem: javax.xml.catalog is JDK 9 only... need to figure out how to test that; Woodstox itself only requires JDK 6 (although I am ok with JDK 8 for build, just not versions beyond that).
Will try to see if this might be part of some additional library before JDK 9.

@cowtowncoder
Copy link
Member

Ok can probably just implement XMLResolver directly, use code otherwise as-is.

@cowtowncoder
Copy link
Member

Except... this requires catalog resolution. Will try to see if I can temporarily use different JDK and see if I can at least temporarily reproduce the issue.

@cowtowncoder
Copy link
Member

cowtowncoder commented Apr 22, 2020

Ok no. I just can't make the test work as described. Catalog resolves throws

javax.xml.catalog.CatalogException: JAXP09040001: No match found for publicId '-//OASIS//DTD DITA Map//EN' and systemId 'map.dtd'.

regardless of how I try to initialize it.

So unfortunately I can not replicate the problem at this point.

Would it be possible to somehow get a flattened version of map.dtd to use, to avoid use of catalog & catalog resolver?

@ChrisTrenkamp
Copy link
Contributor Author

I get that error when the path to the catalog is incorrect in the test case. Here's a new catalog to try.

doctypes.zip

@cowtowncoder
Copy link
Member

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.

@cowtowncoder cowtowncoder changed the title NullPointerException in DTDValidator.validateElementEnd NullPointerException in DTDValidator.validateElementEnd() for element undefined in DTD Apr 23, 2020
@cowtowncoder cowtowncoder added this to the 6.1.2 milestone Apr 23, 2020
@cowtowncoder
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants