poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1595127 - in /poi/trunk: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java test-data/spreadsheet/56514.xlsx
Date Fri, 16 May 2014 07:09:56 GMT
Author: centic
Date: Fri May 16 07:09:55 2014
New Revision: 1595127

URL: http://svn.apache.org/r1595127
Log:
Fix Bug 56514, add missing null-check if simple shape does not have any text

Added:
    poi/trunk/test-data/spreadsheet/56514.xlsx   (with props)
Modified:
    poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java?rev=1595127&r1=1595126&r2=1595127&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSimpleShape.java Fri May 16
07:09:55 2014
@@ -25,28 +25,7 @@ import org.apache.poi.hssf.util.HSSFColo
 import org.apache.poi.ss.usermodel.VerticalAlignment;
 import org.apache.poi.util.Internal;
 import org.apache.poi.util.Units;
-import org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps;
-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.main.*;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape;
 import org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual;
 import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTRElt;
@@ -81,8 +60,10 @@ public class XSSFSimpleShape extends XSS
         // 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
         CTTextBody body = ctShape.getTxBody();
-        for(int i = 0; i < body.sizeOfPArray(); i++) {
-            _paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape));        	
+        if(body != null) {
+            for(int i = 0; i < body.sizeOfPArray(); i++) {
+                _paragraphs.add(new XSSFTextParagraph(body.getPArray(i), ctShape));     
  	
+            }
         }
     }
 

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java?rev=1595127&r1=1595126&r2=1595127&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFDrawing.java Fri May
16 07:09:55 2014
@@ -17,6 +17,7 @@
 package org.apache.poi.xssf.usermodel;
 
 import java.awt.Color;
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.List;
 
@@ -141,7 +142,7 @@ public class TestXSSFDrawing extends Tes
         assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
     }
     
-    public void testMultipleDrawings(){
+    public void testMultipleDrawings() throws IOException{
         XSSFWorkbook wb = new XSSFWorkbook();
         for (int i = 0; i < 3; i++) {
             XSSFSheet sheet = wb.createSheet();
@@ -149,9 +150,13 @@ public class TestXSSFDrawing extends Tes
             assertNotNull(drawing);
         }
         OPCPackage pkg = wb.getPackage();
-        assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
+        try {
+            assertEquals(3, pkg.getPartsByContentType(XSSFRelation.DRAWINGS.getContentType()).size());
         
-        assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
+            assertNotNull(XSSFTestDataSamples.writeOutAndReadBack(wb));
+        } finally {
+            pkg.close();
+        }
     }
 
     public void testClone() throws Exception{
@@ -693,4 +698,24 @@ public class TestXSSFDrawing extends Tes
         
         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();
+        }*/
+    }
 }

Added: poi/trunk/test-data/spreadsheet/56514.xlsx
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/56514.xlsx?rev=1595127&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/56514.xlsx
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message