Page 1 of 1

Half a bug and a missing feature with NULL-relationships

PostPosted: Fri Mar 13, 2015 12:19 am
by ccudennec
Hi everyone!

First of all: Thanks for DOCX4J! It's really a cool project! :)

We're processing XLSX documents using DOCX4J and ran into one and a half problems. We got one document from our customer that can't be opened with DOCX4J but it can be opened with Excel. The reason seems to be that there are some Relationships that have a Target attribute with value NULL. I can't tell you how they got there because XLSX removes them if you open the document and save it again. I can only tell that they are there ;).

Using the latest docx4j release 3.2.1 I get the following exceptions:

Code: Select all
java.lang.NullPointerException
   at org.docx4j.openpackaging.io3.Load3.getRawPart(Load3.java:443)
   at org.docx4j.openpackaging.io3.Load3.getPart(Load3.java:342)
   at org.docx4j.openpackaging.io3.Load3.addPartsFromRelationships(Load3.java:250)
   at org.docx4j.openpackaging.io3.Load3.getPart(Load3.java:370)
   at org.docx4j.openpackaging.io3.Load3.addPartsFromRelationships(Load3.java:250)
   at org.docx4j.openpackaging.io3.Load3.getPart(Load3.java:370)
   at org.docx4j.openpackaging.io3.Load3.addPartsFromRelationships(Load3.java:250)
   at org.docx4j.openpackaging.io3.Load3.get(Load3.java:169)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:454)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:371)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:337)
   at org.docx4j.openpackaging.packages.OpcPackage.load(OpcPackage.java:302)
   at net._24t.xliff.okapi.filters.xlsx.XlsxFilter.open(XlsxFilter.java:134)
   at net._24t.xliff.okapi.filters.xlsx.XlsxFilter.open(XlsxFilter.java:124)
   at net._24t.xliff.okapi.filters.xlsx.XlsxFilter.open(XlsxFilter.java:94)


The NPE is caused by the following line of code in Load3:
Code: Select all
log.debug("ctm returned " + part.getClass().getName() );


That's half a bug in my opinion because there is some part in the code further below that handles the "part" being "null":

Code: Select all
if (part == null) {
            throw new Docx4JException("cannot find part " + resolvedPartUri + " from rel "+ rel.getId() + "=" + rel.getTarget());
        }


Actually I neither want to code to run into a NPE nor throw an exception but it should load the package. If Excel can open it, DOCX4J should be able to open it, shouldn't it?

I attached the document to reproduce the problem.

What do you think?

Cheers,

Christopher