From 78d8fcc80beda14747b49d52bf1670ce2d8ebbcd Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 3 Nov 2008 17:54:01 +0000 Subject: [PATCH] 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 --- src/documentation/content/xdocs/changes.xml | 1 + src/documentation/content/xdocs/status.xml | 1 + .../org/apache/poi/hslf/model/Picture.java | 8 +++++-- .../apache/poi/hslf/model/TestPicture.java | 23 +++++++++++++++++++ 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index c84244ecc..ea02f6f30 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 fb8903f7d..5a2cbf648 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 34b1fd89b..db86f2881 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 cec4f1958..b4a362ae8 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); + } + }