]> source.dussan.org Git - poi.git/commitdiff
Avoid possible NPE found via CommonCrawl files
authorDominik Stadler <centic@apache.org>
Mon, 11 May 2015 20:00:18 +0000 (20:00 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 11 May 2015 20:00:18 +0000 (20:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678811 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java
src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
src/testcases/org/apache/poi/hssf/model/TestShapes.java
test-data/spreadsheet/ar.org.apsme.www_Form%20Inscripcion%20Curso%20NO%20Socios.xls [new file with mode: 0644]

index 3e82fbe1810a32a1add33a0b9af24814c2c69827..ef1b13b22d8b54cd40458e104dff93952b7a946b 100644 (file)
@@ -29,13 +29,6 @@ import java.util.Map;
  * Factory class for producing Excel Shapes from Escher records\r
  */\r
 public class HSSFShapeFactory {\r
-\r
-    private final static short       OBJECT_TYPE_LINE               = 1;\r
-    private final static short       OBJECT_TYPE_RECTANGLE          = 2;\r
-    private final static short       OBJECT_TYPE_OVAL               = 3;\r
-    private final static short       OBJECT_TYPE_ARC                = 4;\r
-    private final static short       OBJECT_TYPE_PICTURE            = 8;\r
-\r
     /**\r
      * build shape tree from escher container\r
      * @param container root escher container from which escher records must be taken\r
@@ -81,7 +74,7 @@ public class HSSFShapeFactory {
                 return;\r
             }\r
             CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);\r
-            HSSFShape shape;\r
+            final HSSFShape shape;\r
             switch (cmo.getObjectType()) {\r
                 case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:\r
                     shape = new HSSFPicture(container, objRecord);\r
@@ -97,11 +90,15 @@ public class HSSFShapeFactory {
                     break;\r
                 case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:\r
                     EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);\r
-                    EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);\r
-                    if (null != property) {\r
-                        shape = new HSSFPolygon(container, objRecord, txtRecord);\r
+                    if(optRecord == null) {\r
+                       shape = new HSSFSimpleShape(container, objRecord, txtRecord);\r
                     } else {\r
-                        shape = new HSSFSimpleShape(container, objRecord, txtRecord);\r
+                        EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);\r
+                        if (null != property) {\r
+                            shape = new HSSFPolygon(container, objRecord, txtRecord);\r
+                        } else {\r
+                            shape = new HSSFSimpleShape(container, objRecord, txtRecord);\r
+                        }\r
                     }\r
                     break;\r
                 case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT:\r
index f7584ff11be2b4fbceb61c610d068ac78cb89d8a..793215a0281a13850be29c6b93493e77821d5ff7 100644 (file)
@@ -363,4 +363,10 @@ public final class TestExcelExtractor extends TestCase {
 
                assertTrue(text.contains("ZIP"));
        }
+
+       public void testNullPointerException() {
+               ExcelExtractor extractor = createExtractor("ar.org.apsme.www_Form%20Inscripcion%20Curso%20NO%20Socios.xls");
+               assertNotNull(extractor);
+               assertNotNull(extractor.getText());
+       }
 }
index d17178ee7cbdbb05374f1d1086268f87db6c99da..beed4a1d3857169e835413b3a947cba56baa3485 100644 (file)
@@ -20,6 +20,7 @@
 package org.apache.poi.hssf.model;
 
 import junit.framework.TestCase;
+
 import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
 import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
 import org.apache.poi.hssf.usermodel.HSSFComment;
@@ -37,7 +38,8 @@ public final class TestShapes extends TestCase {
      *
      * See Bug 51332
      */
-    public void testShapeId(){
+    @SuppressWarnings("deprecation")
+       public void testShapeId(){
 
         HSSFClientAnchor anchor = new HSSFClientAnchor();
         AbstractShape shape;
diff --git a/test-data/spreadsheet/ar.org.apsme.www_Form%20Inscripcion%20Curso%20NO%20Socios.xls b/test-data/spreadsheet/ar.org.apsme.www_Form%20Inscripcion%20Curso%20NO%20Socios.xls
new file mode 100644 (file)
index 0000000..5554ab9
Binary files /dev/null and b/test-data/spreadsheet/ar.org.apsme.www_Form%20Inscripcion%20Curso%20NO%20Socios.xls differ