diff --git a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java index 3cf82b680c..49cbb08976 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java @@ -56,8 +56,13 @@ public class XWPFComments extends POIXMLDocumentPart { * * @param part the package part holding the data of the footnotes, */ - public XWPFComments(PackagePart part) { - super(part); + public XWPFComments(POIXMLDocumentPart parent, PackagePart part) { + super(parent, part); + this.document = (XWPFDocument) getParent(); + + if (this.document == null) { + throw new NullPointerException(); + } } /** diff --git a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFComments.java b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFComments.java index dad5ab877b..cefbab0ef4 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFComments.java +++ b/poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFComments.java @@ -21,6 +21,7 @@ import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigInteger; +import java.util.List; import static org.junit.jupiter.api.Assertions.*; @@ -59,4 +60,17 @@ class TestXWPFComments { } } + @Test + void testReadComments() throws IOException { + try (XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("testComment.docx")) { + XWPFComments docComments = doc.getDocComments(); + assertNotNull(docComments); + XWPFComment[] comments = doc.getComments(); + assertEquals(1, comments.length); + + List allPictures = docComments.getAllPictures(); + assertEquals(1, allPictures.size()); + } + } + } diff --git a/test-data/document/testComment.docx b/test-data/document/testComment.docx new file mode 100644 index 0000000000..d27bb7e9b9 Binary files /dev/null and b/test-data/document/testComment.docx differ