From 43710ae5f2895a268437520ed76ff1c293e452b3 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Mon, 11 May 2015 20:00:18 +0000 Subject: [PATCH] Avoid possible NPE found via CommonCrawl files git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1678811 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/usermodel/HSSFShapeFactory.java | 21 ++++++++---------- .../hssf/extractor/TestExcelExtractor.java | 6 +++++ .../org/apache/poi/hssf/model/TestShapes.java | 4 +++- ...rm%20Inscripcion%20Curso%20NO%20Socios.xls | Bin 0 -> 31233 bytes 4 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 test-data/spreadsheet/ar.org.apsme.www_Form%20Inscripcion%20Curso%20NO%20Socios.xls 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; 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 index 0000000000000000000000000000000000000000..5554ab9f9f6ba51adde3ff6f1345054c98c6c66c GIT binary patch literal 31233 zcmeHQ4Rjn=b$+ue$&&mh$v<%%|BU26$&pqoS--XuNtWbTj%*3ZP6C+N7ceoDy0{3!#lUO-o8RD512_1E}A3 z-^}jJ?8u2zLId45o}HO*-n;L<`|iE(cjT}CZS`{>{q)*%$`>wIVfD-T3RUL94czZ? zo~snz&(HJGx$eY0pknw9l0Zc{DzdCpy|D3Xi@tgmw_&BusgOET@&taB`X0_BYDz6u zYI1TWV;!B0$I>bDbq{-l2g@K2XQ6nP86~P*8R}l(%hbifTaEm#kl%+S=A-g^nW|B9 zYJ=L)^!YViNWPL-;Ql&afYcf{P( zxM@>#m)ss{l7|f?weYFyJn!E+7N2;VH&UHiq}ID5MWS9hc-~O54JJ|Nk5xcTqF$!9 zt1hLEnv&0U&Dl|NR}QfGb3=7ab@JGI)Z9=KQ4Kgiz@2ux=}xxY^rRR>#r68L1T*d| z?BqTaWO{n?S$C*QQ78GVo!GhD^MEhqI(4627b5(l4ZDuiLjdw{q=9wuF}p6D_aZ%S zq&oF+yDlUWGjr3yGf8bzpRnt~70XA>j@qg2SFI=yS#hM6d7J?yIfqHU0V4 zFOV--JcG`+>P2o2|2CZxKoT^*NbbS^=c=pS^fkUF04D*&f7Ba4&wovgn@%3DUI4H4 z;CX&(7T~8g04M)7weEaf{0HDtULT$-mk+0aD2G}PULkTbmAXT2@ROIb$mfr|c%?iF zodW(v-+Xj5{n`TkgeTPcQ16w$f_D`=&cC-MlbzEk}vFQ zw-?XXyHV%1Bi4)1Dd69>3sj8`jy&!7CY6o`<;J1sQ7^s}k%T@Okf7t|@cN+mpws2W znN;YQLIghr`PwfE=m+3J--GkPP>@^HhCTG_3vkUp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