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
This commit is contained in:
Javen O'Neal 2016-03-23 16:42:04 +00:00
parent 0d543621ea
commit a1b9cb221e
2 changed files with 8 additions and 0 deletions

View File

@ -778,6 +778,9 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
*/
@Override
public Map<CellAddress, XSSFComment> getCellComments() {
if (sheetComments == null) {
return Collections.emptyMap();
}
return sheetComments.getCellComments();
}

View File

@ -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();