Avoid possible NPE found via CommonCrawl files

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678811 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-05-11 20:00:18 +00:00
parent 5ca35be087
commit 142e4a9f92
4 changed files with 18 additions and 13 deletions

View File

@ -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:

View 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());
}
}

View 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;