From 43710ae5f2895a268437520ed76ff1c293e452b3 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 11 May 2015 20:00:18 +0000 Subject: Avoid possible NPE found via CommonCrawl files git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678811 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/hssf/usermodel/HSSFShapeFactory.java | 21 +++++++++------------ .../poi/hssf/extractor/TestExcelExtractor.java | 6 ++++++ .../org/apache/poi/hssf/model/TestShapes.java | 4 +++- 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java index 3e82fbe181..ef1b13b22d 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFShapeFactory.java @@ -29,13 +29,6 @@ import java.util.Map; * Factory class for producing Excel Shapes from Escher records */ public class HSSFShapeFactory { - - private final static short OBJECT_TYPE_LINE = 1; - private final static short OBJECT_TYPE_RECTANGLE = 2; - private final static short OBJECT_TYPE_OVAL = 3; - private final static short OBJECT_TYPE_ARC = 4; - private final static short OBJECT_TYPE_PICTURE = 8; - /** * build shape tree from escher container * @param container root escher container from which escher records must be taken @@ -81,7 +74,7 @@ public class HSSFShapeFactory { return; } CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0); - HSSFShape shape; + final HSSFShape shape; switch (cmo.getObjectType()) { case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE: shape = new HSSFPicture(container, objRecord); @@ -97,11 +90,15 @@ public class HSSFShapeFactory { break; case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING: EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID); - EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES); - if (null != property) { - shape = new HSSFPolygon(container, objRecord, txtRecord); + if(optRecord == null) { + shape = new HSSFSimpleShape(container, objRecord, txtRecord); } else { - shape = new HSSFSimpleShape(container, objRecord, txtRecord); + EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES); + if (null != property) { + shape = new HSSFPolygon(container, objRecord, txtRecord); + } else { + shape = new HSSFSimpleShape(container, objRecord, txtRecord); + } } break; case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT: diff --git a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java index f7584ff11b..793215a028 100644 --- a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java +++ b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java @@ -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()); + } } diff --git a/src/testcases/org/apache/poi/hssf/model/TestShapes.java b/src/testcases/org/apache/poi/hssf/model/TestShapes.java index d17178ee7c..beed4a1d38 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestShapes.java +++ b/src/testcases/org/apache/poi/hssf/model/TestShapes.java @@ -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; -- cgit v1.2.3