]> source.dussan.org Git - poi.git/commitdiff
bug 60584 -- avoid NPE by checking for null/missing image in XSSFReader's getShapes().
authorTim Allison <tallison@apache.org>
Fri, 13 Jan 2017 20:55:04 +0000 (20:55 +0000)
committerTim Allison <tallison@apache.org>
Fri, 13 Jan 2017 20:55:04 +0000 (20:55 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1778664 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java

index 9dfbf2bfc8a97826036dc9c8851853458fb068fb..e5c9cb25b10333e922d7fa51b3c2c7af0e7be1e4 100644 (file)
@@ -37,6 +37,8 @@ import org.apache.poi.openxml4j.opc.PackageRelationship;
 import org.apache.poi.openxml4j.opc.PackageRelationshipCollection;
 import org.apache.poi.openxml4j.opc.PackageRelationshipTypes;
 import org.apache.poi.openxml4j.opc.PackagingURIHelper;
+import org.apache.poi.util.POILogFactory;
+import org.apache.poi.util.POILogger;
 import org.apache.poi.xssf.model.CommentsTable;
 import org.apache.poi.xssf.model.SharedStringsTable;
 import org.apache.poi.xssf.model.StylesTable;
@@ -57,6 +59,9 @@ import org.openxmlformats.schemas.spreadsheetml.x2006.main.WorkbookDocument;
  *  for XSSF.
  */
 public class XSSFReader {
+
+    private static final POILogger LOGGER = POILogFactory.getLogger(XSSFReader.class);
+
     private OPCPackage pkg;
     private PackagePart workbookPart;
 
@@ -318,6 +323,11 @@ public class XSSFReader {
                   PackageRelationship drawings = drawingsList.getRelationship(i);
                   PackagePartName drawingsName = PackagingURIHelper.createPartName(drawings.getTargetURI());
                   PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName);
+                  if (drawingsPart == null) {
+                      //parts can go missing; Excel ignores them silently -- TIKA-2134
+                      LOGGER.log(POILogger.WARN, "Missing drawing: "+drawingsName +". Skipping it.");
+                      continue;
+                  }
                   XSSFDrawing drawing = new XSSFDrawing(drawingsPart);
                   for (XSSFShape shape : drawing.getShapes()){
                       shapes.add(shape);