]> source.dussan.org Git - poi.git/commitdiff
fixed unable to read comments with pictures
authorSayi <sayi@apache.org>
Thu, 20 May 2021 08:52:30 +0000 (08:52 +0000)
committerSayi <sayi@apache.org>
Thu, 20 May 2021 08:52:30 +0000 (08:52 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1890040 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/xwpf/usermodel/XWPFComments.java
poi-ooxml/src/test/java/org/apache/poi/xwpf/usermodel/TestXWPFComments.java
test-data/document/testComment.docx [new file with mode: 0644]

index 3cf82b680cf077eba53a0b94f93ca609d71e4b4b..49cbb08976a3e0c1ae84d6604d49ec6dda397691 100644 (file)
@@ -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();
+        }
     }
 
     /**
index dad5ab877b6e7f72025ac7e63db305a05cdf8083..cefbab0ef4a1f274e8ac3bebf267ec2794fa2925 100644 (file)
@@ -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<XWPFPictureData> 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 (file)
index 0000000..d27bb7e
Binary files /dev/null and b/test-data/document/testComment.docx differ