From a1b9cb221e08dfc5b47cf5f4a105dea409e2e1b3 Mon Sep 17 00:00:00 2001 From: Javen O'Neal Date: Wed, 23 Mar 2016 16:42:04 +0000 Subject: [PATCH] bug 59222: fix NPE thrown by (S)XSSFSheet.getCellComments(). Reported by Vasily Kopytov. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1736347 13f79535-47bb-0310-9956-ffa450edef68 --- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java | 3 +++ src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index f5b531414c..f0103719c1 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -778,6 +778,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet { */ @Override public Map getCellComments() { + if (sheetComments == null) { + return Collections.emptyMap(); + } return sheetComments.getCellComments(); } diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java index 8394bcf583..830298181c 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheet.java @@ -27,6 +27,7 @@ import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import java.io.IOException; +import java.util.Collections; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; @@ -1119,6 +1120,10 @@ public abstract class BaseTestSheet { public void getCellComments() throws IOException { Workbook workbook = _testDataProvider.createWorkbook(); Sheet sheet = workbook.createSheet("TEST"); + + // a sheet with no cell comments should return an empty map (not null or raise NPE). + assertEquals(Collections.emptyMap(), sheet.getCellComments()); + Drawing dg = sheet.createDrawingPatriarch(); ClientAnchor anchor = workbook.getCreationHelper().createClientAnchor();