mirror of https://github.com/apache/poi.git
[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
This commit is contained in:
parent
3e061ca74c
commit
d20bc98f70
|
@ -98,13 +98,18 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getShapeName(){
|
public String getShapeName() {
|
||||||
return getCNvPr().getName();
|
CTNonVisualDrawingProps nonVisualDrawingProps = getCNvPr();
|
||||||
|
return nonVisualDrawingProps == null ? null : nonVisualDrawingProps.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getShapeId() {
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -16,12 +16,7 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.xslf.usermodel;
|
package org.apache.poi.xslf.usermodel;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
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 java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -128,4 +123,28 @@ public class TestXSLFTableRow {
|
||||||
assertNotNull(ctrow);
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue