Fix Bug 56514, add missing null-check if simple shape does not have any text
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1595127 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8e6c459d83
commit
8f04bf295e
@ -25,28 +25,7 @@ import org.apache.poi.hssf.util.HSSFColor;
|
|||||||
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
import org.apache.poi.ss.usermodel.VerticalAlignment;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
import org.apache.poi.util.Units;
|
import org.apache.poi.util.Units;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
|
import org.openxmlformats.schemas.drawingml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTPositiveSize2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTRegularTextRun;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTSRgbColor;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTSolidColorFillProperties;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextBodyProperties;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextCharacterProperties;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextFont;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTextParagraph;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAlignType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextAnchoringType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextHorzOverflowType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextUnderlineType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextVertOverflowType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextVerticalType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.main.STTextWrappingType;
|
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
|
||||||
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual;
|
import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
|
||||||
@ -81,10 +60,12 @@ public class XSSFSimpleShape extends XSSFShape implements Iterable<XSSFTextParag
|
|||||||
// initialize any existing paragraphs - this will be the default body paragraph in a new shape,
|
// initialize any existing paragraphs - this will be the default body paragraph in a new shape,
|
||||||
// or existing paragraphs that have been loaded from the file
|
// or existing paragraphs that have been loaded from the file
|
||||||
CTTextBody body = ctShape.getTxBody();
|
CTTextBody body = ctShape.getTxBody();
|
||||||
|
if(body != null) {
|
||||||
for(int i = 0; i < body.sizeOfPArray(); i++) {
|
for(int i = 0; i < body.sizeOfPArray(); i++) {
|
||||||
_paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape));
|
_paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prototype with the default structure of a new auto-shape.
|
* Prototype with the default structure of a new auto-shape.
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
package org.apache.poi.xssf.usermodel;
|
package org.apache.poi.xssf.usermodel;
|
||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -141,7 +142,7 @@ public class TestXSSFDrawing extends TestCase {
|
|||||||
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleDrawings(){
|
public void testMultipleDrawings() throws IOException{
|
||||||
XSSFWorkbook wb = new XSSFWorkbook();
|
XSSFWorkbook wb = new XSSFWorkbook();
|
||||||
for (int i = 0; i < 3; i++) {
|
for (int i = 0; i < 3; i++) {
|
||||||
XSSFSheet sheet = wb.createSheet();
|
XSSFSheet sheet = wb.createSheet();
|
||||||
@ -149,9 +150,13 @@ public class TestXSSFDrawing extends TestCase {
|
|||||||
assertNotNull(drawing);
|
assertNotNull(drawing);
|
||||||
}
|
}
|
||||||
OPCPackage pkg = wb.getPackage();
|
OPCPackage pkg = wb.getPackage();
|
||||||
|
try {
|
||||||
assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
|
assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
|
||||||
|
|
||||||
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
||||||
|
} finally {
|
||||||
|
pkg.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testClone() throws Exception{
|
public void testClone() throws Exception{
|
||||||
@ -693,4 +698,24 @@ public class TestXSSFDrawing extends TestCase {
|
|||||||
|
|
||||||
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testXSSFSimpleShapeCausesNPE56514() throws Exception {
|
||||||
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("56514.xlsx");
|
||||||
|
XSSFSheet sheet = wb.getSheetAt(0);
|
||||||
|
XSSFDrawing drawing = sheet.createDrawingPatriarch();
|
||||||
|
List<XSSFShape> shapes = drawing.getShapes();
|
||||||
|
assertEquals(4, shapes.size());
|
||||||
|
|
||||||
|
wb = XSSFTestDataSamples.writeOutAndReadBack(wb);
|
||||||
|
|
||||||
|
shapes = drawing.getShapes();
|
||||||
|
assertEquals(4, shapes.size());
|
||||||
|
|
||||||
|
/* OutputStream stream = new FileOutputStream(new File("C:\\temp\\56514.xlsx"));
|
||||||
|
try {
|
||||||
|
wb.write(stream);
|
||||||
|
} finally {
|
||||||
|
stream.close();
|
||||||
|
}*/
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
BIN
test-data/spreadsheet/56514.xlsx
Normal file
BIN
test-data/spreadsheet/56514.xlsx
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user