]> source.dussan.org Git - poi.git/commitdiff
fixed #46122: Picture#getEscherBSERecord threw NullPointerException if EscherContaine...
authorYegor Kozlov <yegor@apache.org>
Mon, 3 Nov 2008 17:54:01 +0000 (17:54 +0000)
committerYegor Kozlov <yegor@apache.org>
Mon, 3 Nov 2008 17:54:01 +0000 (17:54 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@710114 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/scratchpad/src/org/apache/poi/hslf/model/Picture.java
src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java

index c84244ecc846811a9937050d72d1885428b7a818..ea02f6f303e5e114ddbc78c096ec72458161fe88 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.5-beta4" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46122 - fixed Picture.draw to skip rendering if picture data was not found</action>
            <action dev="POI-DEVELOPERS" type="fix">15716 - memory usage optimisation - converted Ptg arrays into Formula objects</action>
            <action dev="POI-DEVELOPERS" type="add">46065 - added implementation for VALUE function</action>
            <action dev="POI-DEVELOPERS" type="add">45966 - added implementation for FIND function</action>
index fb8903f7d45efb33f980e8dea9b57be76d2f910c..5a2cbf648135ae7fb4a1298951df501be082d15f 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.5-beta4" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">46122 - fixed Picture.draw to skip rendering if picture data was not found</action>
            <action dev="POI-DEVELOPERS" type="fix">15716 - memory usage optimisation - converted Ptg arrays into Formula objects</action>
            <action dev="POI-DEVELOPERS" type="add">46065 - added implementation for VALUE function</action>
            <action dev="POI-DEVELOPERS" type="add">45966 - added implementation for FIND function</action>
index 34b1fd89bcf2e1875143d49047f2308b07c6ded8..db86f288115979d558d2632a44d1824cdb936d5e 100644 (file)
@@ -196,10 +196,14 @@ public class Picture extends SimpleShape {
         Document doc = ppt.getDocumentRecord();
         EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
         EscherContainerRecord bstore = (EscherContainerRecord)Shape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
-
+        if(bstore == null) {
+            logger.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
+            return null;
+        }
         List lst = bstore.getChildRecords();
         int idx = getPictureIndex();
         if (idx == 0){
+            logger.log(POILogger.DEBUG, "picture index was not found, returning ");
             return null;
         } else {
             return (EscherBSERecord)lst.get(idx-1);
@@ -263,7 +267,7 @@ public class Picture extends SimpleShape {
         ShapePainter.paint(this, graphics);
 
         PictureData data = getPictureData();
-        data.draw(graphics, this);
+        if(data != null) data.draw(graphics, this);
 
         graphics.setTransform(at);
     }
index cec4f19585fd9868de908027806955cae62b1cd1..b4a362ae8dced821e36ae1817b46df838bb6d0a1 100755 (executable)
@@ -20,9 +20,12 @@ import junit.framework.*;
 \r
 import java.io.FileOutputStream;\r
 import java.io.File;\r
+import java.io.IOException;\r
 import java.awt.*;\r
+import java.awt.image.BufferedImage;\r
 \r
 import org.apache.poi.hslf.usermodel.SlideShow;\r
+import org.apache.poi.hslf.usermodel.PictureData;\r
 import org.apache.poi.hslf.HSLFSlideShow;\r
 import org.apache.poi.ddf.EscherBSERecord;\r
 \r
@@ -70,4 +73,24 @@ public class TestPicture extends TestCase {
 \r
     }\r
 \r
+    /**\r
+     * Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER\r
+     * was not found. The correct behaviour is to return null.\r
+     */\r
+    public void test46122() throws IOException {\r
+        SlideShow ppt = new SlideShow();\r
+        Slide slide = ppt.createSlide();\r
+\r
+        Picture pict = new Picture(-1); //index to non-existing picture data\r
+        pict.setSheet(slide);\r
+        PictureData data = pict.getPictureData();\r
+        assertNull(data);\r
+\r
+        BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);\r
+        Graphics2D graphics = img.createGraphics();\r
+        pict.draw(graphics);\r
+\r
+        assertTrue("no errors rendering Picture with null data", true);\r
+    }\r
+\r
 }\r