]> source.dussan.org Git - poi.git/commitdiff
[bug-66319] do not create HSSF patriarch to find comments (only use one that pre...
authorPJ Fanning <fanningpj@apache.org>
Mon, 12 Dec 2022 21:09:09 +0000 (21:09 +0000)
committerPJ Fanning <fanningpj@apache.org>
Mon, 12 Dec 2022 21:09:09 +0000 (21:09 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1905943 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
poi/src/test/java/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/bug66319.xls [new file with mode: 0644]

index c8e3c9bad3de997529a4cdcf6e7a643519298ae1..f50e18edb905abc7e637268535fbd88ad79e9d22 100644 (file)
@@ -2527,10 +2527,7 @@ public final class HSSFSheet implements Sheet {
 
     protected HSSFComment findCellComment(int row, int column) {
         HSSFPatriarch patriarch = getDrawingPatriarch();
-        if (null == patriarch) {
-            patriarch = createDrawingPatriarch();
-        }
-        return lookForComment(patriarch, row, column);
+        return patriarch == null ? null : lookForComment(patriarch, row, column);
     }
 
     private HSSFComment lookForComment(HSSFShapeContainer container, int row, int column) {
index c9cc7c748ad03089f98bc08a758fcc62145111e4..b29c4bc3eeb4004485b03df99e143dc28f4e943b 100644 (file)
@@ -2609,4 +2609,38 @@ final class TestBugs extends BaseTestBugzillaIssues {
             assertNotNull(wb);
         }
     }
+
+    @Test
+    void test66319() throws IOException {
+        try (
+                HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls");
+                UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+        ) {
+            for (Sheet sheet : workbook) {
+                for (Row row : sheet) {
+                    for (Cell cell : row) {
+                        cell.getCellComment();
+                    }
+                }
+            }
+            workbook.write(bos);
+        }
+    }
+
+    @Test
+    void test66319WithRemove() throws IOException {
+        try (
+                HSSFWorkbook workbook = openSampleWorkbook("bug66319.xls");
+                UnsynchronizedByteArrayOutputStream bos = new UnsynchronizedByteArrayOutputStream()
+        ) {
+            for (Sheet sheet : workbook) {
+                for (Row row : sheet) {
+                    for (Cell cell : row) {
+                        cell.removeCellComment();
+                    }
+                }
+            }
+            workbook.write(bos);
+        }
+    }
 }
diff --git a/test-data/spreadsheet/bug66319.xls b/test-data/spreadsheet/bug66319.xls
new file mode 100644 (file)
index 0000000..163ce16
Binary files /dev/null and b/test-data/spreadsheet/bug66319.xls differ