https://bz.apache.org/bugzilla/show_bug.cgi?id=60337

            Bug ID: 60337
           Summary: XWPFTableRow.isRepeatHeader throws
                    NullPointerException, setRepeatHeader does not
                    overwrite old value
           Product: POI
           Version: 3.16-dev
          Hardware: Macintosh
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XWPF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

Created attachment 34418
  --> https://bz.apache.org/bugzilla/attachment.cgi?id=34418&action=edit
A simple Word 2007 document that contains a table with a repeating header row

This bug report relates to the repeating header logic in XWPFTableRow.

When doing a .isRepeatHeader call on the provided Word document an NPE is
thrown on line 229 (repeat = rpt.getVal().equals(STOnOff.ON);). It looks like
.getVal() can be null, even though the repeating header is enabled in the
document. I Generated this document in Microsoft Word for Mac v15.25 (160817).

Related to this, setRepeatHeader seems to append values rather than replace
them. When you check whether the header is a repeating table header after a
setRepeatHeader call you will always get the initial value as (CTOnOff rpt =
trpr.getTblHeaderArray(0);) is used. I'm not sure whether that's according to
the spec or not but I thought I'd mention it in the report nonetheless.

Below is a diff [1] that includes test cases for both bugs.

Let me know if you need any extra information.

Thanks!
Simon


diff --git
a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
index b22f1a0..2f1242f 100644
--- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
+++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFTableRow.java
@@ -18,6 +18,8 @@
 package org.apache.poi.xwpf.usermodel;

 import junit.framework.TestCase;
+
+import org.apache.poi.xwpf.XWPFTestDataSamples;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTRow;
 import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTTbl;

@@ -60,8 +62,29 @@ public class TestXWPFTableRow extends TestCase {
         XWPFTableRow tr = table.getRow(0);
         assertNotNull(tr);

+        // Assert the repeat header is false by default
+        boolean isRpt = tr.isRepeatHeader();
+        assertFalse(isRpt);
+
+        // Repeat the header
         tr.setRepeatHeader(true);
+        isRpt = tr.isRepeatHeader();
+        assertTrue(isRpt);
+
+        // Make the header no longer repeating
+        tr.setRepeatHeader(false);
+        isRpt = tr.isRepeatHeader();
+        assertFalse(isRpt);
+    }
+
+    // Test that validates the table header value can be parsed from a
document generated in Word
+    public void testIsRepeatHeader() throws Exception {
+        XWPFDocument doc =
XWPFTestDataSamples.openSampleDocument("Word2007TableWithHeader.docx");
+        XWPFTable table = doc.getTables().get(0);
+        assertNotNull(table);
+        XWPFTableRow tr = table.getRow(0);
+        assertNotNull(tr);
         boolean isRpt = tr.isRepeatHeader();
-        assert (isRpt);
+        assertTrue(isRpt);
     }
 }

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to