File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Testing and the fly likes XMLUnit ignoreWhitespace(true) NPE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Testing
Bookmark "XMLUnit ignoreWhitespace(true) NPE" Watch "XMLUnit ignoreWhitespace(true) NPE" New topic

XMLUnit ignoreWhitespace(true) NPE

Mark Dexter
Ranch Hand

Joined: Jun 03, 2007
Posts: 34
I'm using XMLUnit to do unit testing of XML output files. (Charles, thanks very much for the suggestion!) I've got it working pretty well, and the documentation is pretty good.

However, I have one problem that I can't find the answer to. I posted a question on the XMLUnit SourceForge forum a few days ago and haven't gotten any responses. (That forum is not very active.) So I thought I'd try here.

I am using Eclipse and have a small test project and my live project, build my Maven, that incorporates lots of third-party libraries. On my test project, I can set XMLUnit.setIgnoreWhitespace(true) and it works as advertised.

However, on my live project, I get a NullPointerException when I try to use this option. It works ok if this is set to false. Here is a partial stack trace of the NPE:

at net.sf.saxon.Controller.prepareInputTree(
at net.sf.saxon.Controller.transform(
at org.custommonkey.xmlunit.Transform.transformTo(
at org.custommonkey.xmlunit.Transform.getResultDocument(
at org.custommonkey.xmlunit.Diff.getWhitespaceManipulatedDocument(
at org.custommonkey.xmlunit.Diff.getManipulatedDocument(
at org.custommonkey.xmlunit.Diff.<init>(
at org.custommonkey.xmlunit.Diff.<init>(
at org.custommonkey.xmlunit.Diff.<init>(
at org.custommonkey.xmlunit.Diff.<init>(
at org.custommonkey.xmlunit.Diff.<init>(

One difference in the two projects is that they are using different control parsers. If I do


on each system, I get this on the test project that works:

and this on the live project that NPE's:


I'm not really sure what this means of if it's significant. I've tried using


but I think I've got the syntax wrong. This gives me the error:

avax.xml.parsers.FactoryConfigurationError: Provider could not be instantiated: java.lang.InstantiationException:
at javax.xml.parsers.DocumentBuilderFactory.newInstance(
at org.custommonkey.xmlunit.XMLUnit.getControlDocumentBuilderFactory(
at org.custommonkey.xmlunit.XMLUnit.setControlParser(

Any ideas on how to fix this -- or perhaps where else to ask -- will be greatly appreciated. Thanks!
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
It seems like your "live" and "test" projects have a different XML parser implementation. Are the Java versions identical? What about the classpaths?

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Mark Dexter
Ranch Hand

Joined: Jun 03, 2007
Posts: 34
Lasse, thank you very much for the tip. I resolved the issue as follows:

1. I discovered through trial and error that the problem arose because the live project had "saxon-8.7.jar" in the build path. When I added this to the test project, I got the same failure.
2. In the XMLUnit documentation, there is an example command to change the transformer factory used by XMLUnit as follows:


In order for this to work, I had to add the "xalan.jar" file to the project. With this change, the setIgnoreWhitespace(true) works as advertised.

So, if I understand this correctly, it appears that the Transformer Factory provided by the saxon-8.7.jar is not compatible with XMLUnit but nevertheless becomes the default when available.

In any case, I've got a workable solution. Thanks for the tip on the classpath. Mark
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33102

Thanks for sharing the solution for anyone who reads this in the future.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: XMLUnit ignoreWhitespace(true) NPE
It's not a secret anymore!