]> source.dussan.org Git - poi.git/commitdiff
[bug-62929] add null check for blip fill. Thanks to Mate Borcsok
authorPJ Fanning <fanningpj@apache.org>
Tue, 20 Nov 2018 14:15:14 +0000 (14:15 +0000)
committerPJ Fanning <fanningpj@apache.org>
Tue, 20 Nov 2018 14:15:14 +0000 (14:15 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1847004 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xslf/usermodel/XSLFPictureShape.java
src/ooxml/testcases/org/apache/poi/xslf/TestXSLFBugs.java
test-data/slideshow/missing-blip-fill.pptx [new file with mode: 0644]

index 97b4ab8cb026ad604a37d6b907bd488bd92d1e28..95a8f0bc23a3e4735a56724f507795caa71af7fe 100644 (file)
@@ -170,16 +170,25 @@ public class XSLFPictureShape extends XSLFSimpleShape
     
     @SuppressWarnings("WeakerAccess")
     protected String getBlipLink(){
-        String link = getBlip().getLink();
-        if (link.isEmpty()) return null;
-        return link;
+        CTBlip blip = getBlip();
+        if (blip != null) {
+            String link = blip.getLink();
+            if (link.isEmpty()) return null;
+        return link;} else {
+            return null;
+        }
     }
 
     @SuppressWarnings("WeakerAccess")
     protected String getBlipId(){
-        String id = getBlip().getEmbed();
-        if (id.isEmpty()) return null;
-        return id;
+        CTBlip blip = getBlip();
+        if (blip != null) {
+            String id = getBlip().getEmbed();
+            if (id.isEmpty()) return null;
+            return id;
+        } else {
+            return null;
+        }
     }
 
     @Override
index 48b08169938a49f81bc5d6af7825a185309ac3c9..8dbc8ca23e187667d75b9c4fd9488459eff7f8c8 100644 (file)
 package org.apache.poi.xslf;
 
 import static org.apache.poi.POITestCase.assertContains;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 import java.awt.Color;
 import java.awt.Dimension;
@@ -93,6 +88,25 @@ import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
 public class TestXSLFBugs {
     private static final POIDataSamples slTests = POIDataSamples.getSlideShowInstance();
 
+    @Test
+    public void bug62929() throws Exception {
+        try(XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("missing-blip-fill.pptx")) {
+            assertEquals(1, ss1.getSlides().size());
+
+            XSLFSlide slide = ss1.getSlides().get(0);
+
+            assertEquals(slide.getShapes().size(), 1);
+
+            XSLFPictureShape picture = (XSLFPictureShape)slide.getShapes().get(0);
+
+            assertEquals(picture.getShapeId(), 662);
+            assertFalse(picture.isExternalLinkedPicture());
+            assertNull(picture.getPictureData());
+            assertNull(picture.getPictureLink());
+            assertNull(picture.getClipping());
+        }
+    }
+
     @Test
     public void bug62736() throws Exception {
         XMLSlideShow ss1 = XSLFTestDataSamples.openSampleDocument("bug62736.pptx");
diff --git a/test-data/slideshow/missing-blip-fill.pptx b/test-data/slideshow/missing-blip-fill.pptx
new file mode 100644 (file)
index 0000000..62e5f67
Binary files /dev/null and b/test-data/slideshow/missing-blip-fill.pptx differ