From: Yegor Kozlov Date: Mon, 3 Nov 2008 17:54:01 +0000 (+0000) Subject: fixed #46122: Picture#getEscherBSERecord threw NullPointerException if EscherContaine... X-Git-Tag: trunk_20081106~13 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d99149477c5455104cf9fc892b03157d338d12c4;p=poi.git fixed #46122: Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER was not found git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@710114 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index c84244ecc8..ea02f6f303 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 46122 - fixed Picture.draw to skip rendering if picture data was not found 15716 - memory usage optimisation - converted Ptg arrays into Formula objects 46065 - added implementation for VALUE function 45966 - added implementation for FIND function diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index fb8903f7d4..5a2cbf6481 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 46122 - fixed Picture.draw to skip rendering if picture data was not found 15716 - memory usage optimisation - converted Ptg arrays into Formula objects 46065 - added implementation for VALUE function 45966 - added implementation for FIND function diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java b/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java index 34b1fd89bc..db86f28811 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Picture.java @@ -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); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java index cec4f19585..b4a362ae8d 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestPicture.java @@ -20,9 +20,12 @@ import junit.framework.*; import java.io.FileOutputStream; import java.io.File; +import java.io.IOException; import java.awt.*; +import java.awt.image.BufferedImage; import org.apache.poi.hslf.usermodel.SlideShow; +import org.apache.poi.hslf.usermodel.PictureData; import org.apache.poi.hslf.HSLFSlideShow; import org.apache.poi.ddf.EscherBSERecord; @@ -70,4 +73,24 @@ public class TestPicture extends TestCase { } + /** + * Picture#getEscherBSERecord threw NullPointerException if EscherContainerRecord.BSTORE_CONTAINER + * was not found. The correct behaviour is to return null. + */ + public void test46122() throws IOException { + SlideShow ppt = new SlideShow(); + Slide slide = ppt.createSlide(); + + Picture pict = new Picture(-1); //index to non-existing picture data + pict.setSheet(slide); + PictureData data = pict.getPictureData(); + assertNull(data); + + BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB); + Graphics2D graphics = img.createGraphics(); + pict.draw(graphics); + + assertTrue("no errors rendering Picture with null data", true); + } + }