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:
parent
5ca35be087
commit
142e4a9f92
@ -29,13 +29,6 @@ import java.util.Map;
|
|||||||
* Factory class for producing Excel Shapes from Escher records
|
* Factory class for producing Excel Shapes from Escher records
|
||||||
*/
|
*/
|
||||||
public class HSSFShapeFactory {
|
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
|
* build shape tree from escher container
|
||||||
* @param container root escher container from which escher records must be taken
|
* @param container root escher container from which escher records must be taken
|
||||||
@ -81,7 +74,7 @@ public class HSSFShapeFactory {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);
|
CommonObjectDataSubRecord cmo = (CommonObjectDataSubRecord) objRecord.getSubRecords().get(0);
|
||||||
HSSFShape shape;
|
final HSSFShape shape;
|
||||||
switch (cmo.getObjectType()) {
|
switch (cmo.getObjectType()) {
|
||||||
case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:
|
case CommonObjectDataSubRecord.OBJECT_TYPE_PICTURE:
|
||||||
shape = new HSSFPicture(container, objRecord);
|
shape = new HSSFPicture(container, objRecord);
|
||||||
@ -97,12 +90,16 @@ public class HSSFShapeFactory {
|
|||||||
break;
|
break;
|
||||||
case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:
|
case CommonObjectDataSubRecord.OBJECT_TYPE_MICROSOFT_OFFICE_DRAWING:
|
||||||
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
|
EscherOptRecord optRecord = container.getChildById(EscherOptRecord.RECORD_ID);
|
||||||
|
if(optRecord == null) {
|
||||||
|
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
|
||||||
|
} else {
|
||||||
EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
|
EscherProperty property = optRecord.lookup(EscherProperties.GEOMETRY__VERTICES);
|
||||||
if (null != property) {
|
if (null != property) {
|
||||||
shape = new HSSFPolygon(container, objRecord, txtRecord);
|
shape = new HSSFPolygon(container, objRecord, txtRecord);
|
||||||
} else {
|
} else {
|
||||||
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
|
shape = new HSSFSimpleShape(container, objRecord, txtRecord);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT:
|
case CommonObjectDataSubRecord.OBJECT_TYPE_TEXT:
|
||||||
shape = new HSSFTextbox(container, objRecord, txtRecord);
|
shape = new HSSFTextbox(container, objRecord, txtRecord);
|
||||||
|
@ -363,4 +363,10 @@ public final class TestExcelExtractor extends TestCase {
|
|||||||
|
|
||||||
assertTrue(text.contains("ZIP"));
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
package org.apache.poi.hssf.model;
|
package org.apache.poi.hssf.model;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
|
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
|
||||||
import org.apache.poi.hssf.usermodel.HSSFComment;
|
import org.apache.poi.hssf.usermodel.HSSFComment;
|
||||||
@ -37,6 +38,7 @@ public final class TestShapes extends TestCase {
|
|||||||
*
|
*
|
||||||
* See Bug 51332
|
* See Bug 51332
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public void testShapeId(){
|
public void testShapeId(){
|
||||||
|
|
||||||
HSSFClientAnchor anchor = new HSSFClientAnchor();
|
HSSFClientAnchor anchor = new HSSFClientAnchor();
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user