This is an automated email from the ASF dual-hosted git repository.

fanningpj pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/poi.git


The following commit(s) were added to refs/heads/trunk by this push:
     new fa573c72da add xwpf test
fa573c72da is described below

commit fa573c72dab03a6196f12159c810b26244bcef95
Author: PJ Fanning <[email protected]>
AuthorDate: Wed Jul 30 21:40:21 2025 +0100

    add xwpf test
---
 .../java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java     | 11 +++++++++--
 .../java/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java |  2 ++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git 
a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java 
b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
index 27f7dbfaf9..6e590e5f9e 100644
--- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
+++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFTableCell.java
@@ -79,10 +79,16 @@ public class XWPFTableCell implements IBody, ICell {
      * If a table cell does not include at least one block-level element, then 
this document shall be considered corrupt
      */
     public XWPFTableCell(CTTc cell, XWPFTableRow tableRow, IBody part) {
+        if (cell == null) {
+            throw new IllegalArgumentException("CTTc cannot be null");
+        }
+        if (tableRow == null) {
+            throw new IllegalArgumentException("tableRow cannot be null");
+        }
         this.ctTc = cell;
         this.part = part;
         this.tableRow = tableRow;
-        this.xwpfDocument = part.getXWPFDocument();
+        this.xwpfDocument = part == null ? null : part.getXWPFDocument();
 
         bodyElements = new ArrayList<>();
         paragraphs = new ArrayList<>();
@@ -530,9 +536,10 @@ public class XWPFTableCell implements IBody, ICell {
             return xwpfDocument;
         } else if (part instanceof XWPFTableCell) {
             return getCellDocument((XWPFTableCell) part, 0);
-        } else {
+        } else if (part != null) {
             return part.getXWPFDocument();
         }
+        return null;
     }
 
     private static final int MAX_RECURSION_DEPTH = 1000;
diff --git 
a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java 
b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
index 9d29cb8247..688133d772 100644
--- 
a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
+++ 
b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFTableCell.java
@@ -271,6 +271,7 @@ class TestXWPFTableCell {
         XWPFDocument doc = new XWPFDocument();
         XWPFTable table = doc.createTable(1, 1);
         XWPFTableCell cell = table.getRow(0).getCell(0);
+        assertEquals(doc, cell.getXWPFDocument());
 
         // cell have at least one paragraph by default when creating a cell
         assertEquals(1, cell.getParagraphs().size());
@@ -282,6 +283,7 @@ class TestXWPFTableCell {
         XWPFDocument readDoc = XWPFTestDataSamples.writeOutAndReadBack(doc);
         XWPFTableCell readCell = readDoc.getTableArray(0).getRow(0).getCell(0);
         assertEquals(0, readCell.getParagraphs().size());
+        assertEquals(readDoc, readCell.getXWPFDocument());
     }
 
     @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to