简体   繁体   中英

XMLUnit throws NullPointerException when creating Diff object for valid xml

I am using org.custommonkey.xmlunit; (version 1.2) org.custommonkey.xmlunit; (version 1.2) . While building Diff object: Diff diff = new Diff(expected, generated);

I always have NullPointerException as it's failing on this.controlDoc = this.getManipulatedDocument(controlDoc);. While debugging I found that in first constructor:

public Diff(String control, String test) throws SAXException, IOException {
        this((Reader)(new StringReader(control)), (Reader)(new StringReader(test)));
    }

there are proper xmls however when:

public Diff(Reader control, Reader test) throws SAXException, IOException {
        this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control), XMLUnit.buildDocument(XMLUnit.newTestParser(), test));
    }

is called I see in debugger [#document: null] . Why is that so? I tried with many xmls, even really easy and small which I found in internet but nothing works.

Oh, I just have found that XMLUnit.setIgnoreWhitespace(true); cause this problem because in project I am using Saxon library in ancient version and it was fixed in version 8.9 however this:

XMLUnit.setTransformerFactory("org.apache.xalan.processor.TransformerFactoryImpl");

helps a lot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM