summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2019-06-12 17:30:52 +0000
committerPJ Fanning <fanningpj@apache.org>2019-06-12 17:30:52 +0000
commitd20bc98f70e62e2468d72d86b874b3ac23da0f0e (patch)
tree66cbeb7e2d71204bb2ea5e3d6f4405f7d5d83a2b /src
parent3e061ca74c0dc49a3e9639d02429c935e0cf58bf (diff)
downloadpoi-d20bc98f70e62e2468d72d86b874b3ac23da0f0e.tar.gz
poi-d20bc98f70e62e2468d72d86b874b3ac23da0f0e.zip
[bug-63498] NPE when calling getShapeName on XSLFTableCell. Thanks to Mate Borcsok.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1861172 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src')
-rw-r--r--src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java11
-rw-r--r--src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java31
2 files changed, 33 insertions, 9 deletions
diff --git a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
index 3df55edbaa..8227b46460 100644
--- a/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
+++ b/src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFShape.java
@@ -98,13 +98,18 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
}
@Override
- public String getShapeName(){
- return getCNvPr().getName();
+ public String getShapeName() {
+ CTNonVisualDrawingProps nonVisualDrawingProps = getCNvPr();
+ return nonVisualDrawingProps == null ? null : nonVisualDrawingProps.getName();
}
@Override
public int getShapeId() {
- return (int)getCNvPr().getId();
+ CTNonVisualDrawingProps nonVisualDrawingProps = getCNvPr();
+ if (nonVisualDrawingProps == null) {
+ throw new IllegalStateException("no underlying shape exists");
+ }
+ return Math.toIntExact(nonVisualDrawingProps.getId());
}
/**
diff --git a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java
index 8a08928193..47345133b8 100644
--- a/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java
+++ b/src/ooxml/testcases/org/apache/poi/xslf/usermodel/TestXSLFTableRow.java
@@ -16,12 +16,7 @@
==================================================================== */
package org.apache.poi.xslf.usermodel;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
import java.io.IOException;
import java.util.List;
@@ -128,4 +123,28 @@ public class TestXSLFTableRow {
assertNotNull(ctrow);
}
+
+ @Test
+ public void getShapeNameOfCells() throws Exception {
+ try(XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("table_test.pptx")) {
+ for (XSLFSlide slide : ss1.getSlides()) {
+ for (XSLFShape shape : slide.getShapes()) {
+ assertEquals("Table 3", shape.getShapeName());
+ if (shape instanceof XSLFTable) {
+ for (XSLFTableRow row : ((XSLFTable) shape).getRows()) {
+ for (XSLFTableCell cell : row.getCells()) {
+ assertNull(cell.getShapeName()); // Do not throw NPE
+ try {
+ cell.getShapeId();
+ fail("expected getShapeId to fail");
+ } catch (IllegalStateException ise) {
+ // expected
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}