diff options
author | Nick Burch <nick@apache.org> | 2015-04-18 04:16:28 +0000 |
---|---|---|
committer | Nick Burch <nick@apache.org> | 2015-04-18 04:16:28 +0000 |
commit | facbded856036a978a7874e1b392f74a9baea252 (patch) | |
tree | 63034ae4551a584f8c8ee3f09841001b07deee77 | |
parent | 903b5c91c14b39a9f5c971f24fa0e5886c9e60cd (diff) | |
download | poi-facbded856036a978a7874e1b392f74a9baea252.tar.gz poi-facbded856036a978a7874e1b392f74a9baea252.zip |
Patch from Jon Scharff from bug #57820 - Avoid NPE on HSLF Tables with a top position of -1
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1674441 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | src/scratchpad/src/org/apache/poi/hslf/model/Table.java | 2 | ||||
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java | 32 | ||||
-rw-r--r-- | test-data/slideshow/bug57820-initTableNullRefrenceException.ppt | bin | 0 -> 110592 bytes |
3 files changed, 33 insertions, 1 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hslf/model/Table.java b/src/scratchpad/src/org/apache/poi/hslf/model/Table.java index c494789917..bafc851824 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Table.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Table.java @@ -159,7 +159,7 @@ public final class Table extends ShapeGroup { return delta; } }); - int y0 = -1; + int y0 = (sh.length > 0) ? sh[0].getAnchor().y - 1 : -1; int maxrowlen = 0; ArrayList lst = new ArrayList(); ArrayList row = null; diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java index e8f246bbd6..1740b46b40 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java @@ -19,11 +19,16 @@ package org.apache.poi.hslf.model; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.IOException; import junit.framework.TestCase; +import org.apache.poi.POIDataSamples; +import org.apache.poi.hslf.HSLFSlideShow; +import org.apache.poi.hslf.extractor.PowerPointExtractor; import org.apache.poi.hslf.record.TextHeaderAtom; import org.apache.poi.hslf.usermodel.SlideShow; +import org.junit.Test; /** * Test <code>Table</code> object. @@ -31,6 +36,7 @@ import org.apache.poi.hslf.usermodel.SlideShow; * @author Yegor Kozlov */ public final class TestTable extends TestCase { + private static POIDataSamples _slTests = POIDataSamples.getSlideShowInstance(); /** * Test that ShapeFactory works properly and returns <code>Table</code> @@ -100,4 +106,30 @@ public final class TestTable extends TestCase { } } + + /** + * Bug 57820: initTable throws NullPointerException + * when the table is positioned with its top at -1 + */ + @Test + public void test57820() throws Exception { + SlideShow ppt = new SlideShow(new HSLFSlideShow(_slTests.openResourceAsStream("bug57820-initTableNullRefrenceException.ppt"))); + + Slide[] slides = ppt.getSlides(); + assertEquals(1, slides.length); + + Shape[] shapes = slides[0].getShapes(); //throws NullPointerException + + Table tbl = null; + for(int idx = 0; idx < shapes.length; idx++) { + if(shapes[idx] instanceof Table) { + tbl = (Table)shapes[idx]; + break; + } + } + + assertNotNull(tbl); + + assertEquals(-1, tbl.getAnchor().y); + } } diff --git a/test-data/slideshow/bug57820-initTableNullRefrenceException.ppt b/test-data/slideshow/bug57820-initTableNullRefrenceException.ppt Binary files differnew file mode 100644 index 0000000000..e7525f9456 --- /dev/null +++ b/test-data/slideshow/bug57820-initTableNullRefrenceException.ppt |