From 8c23b343cb37384c5b17b6dafef4bb13a5c7456b Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Fri, 3 Oct 2008 05:27:06 +0000 Subject: [PATCH] fixed bug #45889:rrayIndexOutOfBoundsException when constructing HSLF Table with a single row git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@701302 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/changes.xml | 2 ++ src/documentation/content/xdocs/status.xml | 2 ++ .../src/org/apache/poi/hslf/model/Table.java | 5 ++- .../org/apache/poi/hslf/model/TestTable.java | 36 +++++++++++++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index 76d53e628..643058266 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,8 @@ + 45889 - fixed ArrayIndexOutOfBoundsException when constructing HSLF Table with a single row + Initial support for creating hyperlinks in HSLF 45876 - fixed BoundSheetRecord to allow sheet names longer than 31 chars 45890 - fixed HSSFSheet.shiftRows to also update conditional formats 45865 modified Formula Parser/Evaluator to handle cross-worksheet formulas diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 34a3bc327..c998f61de 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,8 @@ + 45889 - fixed ArrayIndexOutOfBoundsException when constructing HSLF Table with a single row + Initial support for creating hyperlinks in HSLF 45876 - fixed BoundSheetRecord to allow sheet names longer than 31 chars 45890 - fixed HSSFSheet.shiftRows to also update conditional formats 45865 modified Formula Parser/Evaluator to handle cross-worksheet formulas 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 113a2d8f2..bd27969fa 100755 --- a/src/scratchpad/src/org/apache/poi/hslf/model/Table.java +++ b/src/scratchpad/src/org/apache/poi/hslf/model/Table.java @@ -53,6 +53,9 @@ public class Table extends ShapeGroup { public Table(int numrows, int numcols) { super(); + if(numrows < 1) throw new IllegalArgumentException("The number of rows must be greater than 1"); + if(numcols < 1) throw new IllegalArgumentException("The number of columns must be greater than 1"); + int x=0, y=0, tblWidth=0, tblHeight=0; cells = new TableCell[numrows][numcols]; for (int i = 0; i < cells.length; i++) { @@ -165,11 +168,11 @@ public class Table extends ShapeGroup { Rectangle anchor = sh[i].getAnchor(); if(anchor.y != y0){ y0 = anchor.y; - if(row != null) maxrowlen = Math.max(maxrowlen, row.size()); row = new ArrayList(); lst.add(row); } row.add(sh[i]); + maxrowlen = Math.max(maxrowlen, row.size()); } } cells = new TableCell[lst.size()][maxrowlen]; 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 fff6482ec..7202ff345 100755 --- a/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/model/TestTable.java @@ -60,4 +60,40 @@ public class TestTable extends TestCase { assertEquals(tbl.getNumberOfRows(), tbl3.getNumberOfRows()); } + /** + * Error constructing Table when rownum=1 + */ + public void test45889(){ + SlideShow ppt = new SlideShow(); + Slide slide = ppt.createSlide(); + Shape[] shapes; + Table tbl1 = new Table(1, 5); + assertEquals(5, tbl1.getNumberOfColumns()); + assertEquals(1, tbl1.getNumberOfRows()); + slide.addShape(tbl1); + + shapes = slide.getShapes(); + assertEquals(1, shapes.length); + + Table tbl2 = (Table)shapes[0]; + assertSame(tbl1.getSpContainer(), tbl2.getSpContainer()); + + assertEquals(tbl1.getNumberOfColumns(), tbl2.getNumberOfColumns()); + assertEquals(tbl1.getNumberOfRows(), tbl2.getNumberOfRows()); + } + + public void testIllegalCOnstruction(){ + try { + Table tbl = new Table(0, 5); + fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1"); + } catch (IllegalArgumentException e){ + + } + try { + Table tbl = new Table(5, 0); + fail("Table(rownum, colnum) must throw IllegalArgumentException if any of tghe arguments is less than 1"); + } catch (IllegalArgumentException e){ + + } + } }