Page 1 of 1

NPE on BoxBuilder.createChildren

PostPosted: Tue Apr 23, 2013 9:57 pm
by mothergoose
I'm getting a NPE on docx4j 2.8.1

Code: Select all
Caused by: java.lang.NullPointerException
   at org.docx4j.org.xhtmlrenderer.layout.BoxBuilder.createChildren(BoxBuilder.java:205)
   at org.docx4j.org.xhtmlrenderer.layout.BoxBuilder.createChildren(BoxBuilder.java:312)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.ensureChildren(BlockBox.java:919)
   at org.docx4j.org.xhtmlrenderer.layout.BoxBuilder.createChildren(BoxBuilder.java:173)
   at org.docx4j.org.xhtmlrenderer.layout.BoxBuilder.createChildren(BoxBuilder.java:312)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.ensureChildren(BlockBox.java:919)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.isVerticalMarginsAdjoin(BlockBox.java:1260)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.collapseMargins(BlockBox.java:1087)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:780)
   at org.docx4j.org.xhtmlrenderer.render.BlockBox.layout(BlockBox.java:735)
   at org.docx4j.org.xhtmlrenderer.docx.DocxRenderer.layout(DocxRenderer.java:187)
   at org.docx4j.convert.in.xhtml.XHTMLImporter.convert(XHTMLImporter.java:413)
   ....


The problem is the statement

Code: Select all
parent.getLocalName().equals("script")


is not null-safe, it should be the opposite:
Code: Select all
"script".equals(parent.getLocalName())
(best programmer award drifting away)

By the way i guess this is hiding a more insidious library issue.

At runtime
Code: Select all
parent.getLocalName()
method has been implemented by class org.apache.xerces.dom.NodeImpl of xercesImpl 2.7.1, which returns statically null and always will.

This is why I think docx4j is relying on the wrong library, moreover xercesImpl is not among its dependencies, so my question is: how did it happen to use such library?

Since none on the googlable web has encountered such problem, I guess there's something really trivial I'm missing maybe has not even anything to do with the library (best programmer award drifting away from me too)

Any hint?

Re: NPE on BoxBuilder.createChildren

PostPosted: Wed Apr 24, 2013 10:19 am
by jason
https://github.com/plutext/flyingsaucer is due for a good dose of TLC, but its not going to get it (from me at least, I'm afraid) any time soon.

Longer term vision is to get to the point where we are using standard flyingsaucer (including using its proper namespace), plus docx4j contributed docx input processing, instead of repackaged and somewhat altered code.

In the meantime, any contributed improvements (via pull request) would be happily received (eg the improvement you suggest). Now is a good time for them, prior to docx4j 3.0 release.

As to how you get the 'real' Xerces on your classpath (as opposed to the repackaged Xerces in Java 6) - probably pulled in by some other library you are using? When I was playing with that code, some other DOM implementation (with different getLocalName()) was being used in my dev environment.

Re: NPE on BoxBuilder.createChildren

PostPosted: Thu Apr 25, 2013 11:23 pm
by mothergoose
Yes I have an Xerces.jar around, maybe there is something wrong with the order the libraries are imported at runtime, since when launching unit tests the right implementation is used although the same libraries are involved.

Thank you