drmacro / wordinator

Generate high-quality DOCX files using a simplified XML format (simple word processing XML).
Apache License 2.0
38 stars 8 forks source link

NPE in `DocxGenerator.makeTable` #114

Open larsga opened 1 year ago

larsga commented 1 year ago

This is the traceback:

java.lang.NullPointerException
    at org.apache.poi.xwpf.usermodel.XWPFTable.setWidthPercentage(XWPFTable.java:1244)
    at org.apache.poi.xwpf.usermodel.XWPFTable.setWidthValue(XWPFTable.java:1228)
    at org.apache.poi.xwpf.usermodel.XWPFTable.setWidth(XWPFTable.java:1211)
    at org.wordinator.xml2docx.generator.DocxGenerator.makeTable(DocxGenerator.java:2234)
    at org.wordinator.xml2docx.generator.DocxGenerator.makeTableRow(DocxGenerator.java:2906)
    at org.wordinator.xml2docx.generator.DocxGenerator.makeTable(DocxGenerator.java:2350)
    at org.wordinator.xml2docx.generator.DocxGenerator.handleBody(DocxGenerator.java:485)
    at org.wordinator.xml2docx.generator.DocxGenerator.handleSectionContent(DocxGenerator.java:730)
    at org.wordinator.xml2docx.generator.DocxGenerator.handleSection(DocxGenerator.java:695)
    at org.wordinator.xml2docx.generator.DocxGenerator.handleBody(DocxGenerator.java:482)
    at org.wordinator.xml2docx.generator.DocxGenerator.constructDoc(DocxGenerator.java:436)
    at org.wordinator.xml2docx.generator.DocxGenerator.generate(DocxGenerator.java:418)
    at org.wordinator.xml2docx.MakeDocx.handleSingleSwpxDoc(MakeDocx.java:329)
    at org.wordinator.xml2docx.MakeDocx.handleDirectory(MakeDocx.java:350)
    at org.wordinator.xml2docx.MakeDocx.handleCommandLine(MakeDocx.java:200)
    at org.wordinator.xml2docx.MakeDocx.main(MakeDocx.java:86)
larsga commented 1 year ago

This minimal example will trigger the bug. Removing the width attribute makes the problem go away. So it looks like the trigger for the bug is a nested table with a width attribute.

<wp:document xmlns:wp="urn:ns:wordinator:simplewpml">
  <wp:body>
    <wp:table>
      <wp:tbody>
        <wp:tr>
          <wp:td>
            <wp:table width="100%">

            </wp:table>
          </wp:td>
        </wp:tr>
      </wp:tbody>
    </wp:table>
  </wp:body>
</wp:document>