From 40b3642340e89fe4b7baf5f4d130f8b34b0eaaf7 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Fri, 23 Mar 2007 09:19:04 +0000 Subject: [PATCH] Avoid an IndexOutOfBoundsException when more columns are used than are specified even though this is illegal with fixed table layout. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@521640 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/layoutmgr/table/ColumnSetup.java | 10 ++- .../table-column_missing.xml | 75 +++++++++++++++++++ 2 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 test/layoutengine/standard-testcases/table-column_missing.xml diff --git a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java index b7f29a744..eb91f7175 100644 --- a/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java +++ b/src/java/org/apache/fop/layoutmgr/table/ColumnSetup.java @@ -221,8 +221,14 @@ public class ColumnSetup { public int getXOffset(int col, PercentBaseContext context) { int xoffset = 0; for (int i = col; --i >= 0;) { - if (colWidths.get(i) != null) { - xoffset += ((Length) colWidths.get(i)).getValue(context); + int effCol; + if (i < colWidths.size()) { + effCol = i; + } else { + effCol = colWidths.size() - 1; + } + if (colWidths.get(effCol) != null) { + xoffset += ((Length) colWidths.get(effCol)).getValue(context); } } return xoffset; diff --git a/test/layoutengine/standard-testcases/table-column_missing.xml b/test/layoutengine/standard-testcases/table-column_missing.xml new file mode 100644 index 000000000..01521bf7b --- /dev/null +++ b/test/layoutengine/standard-testcases/table-column_missing.xml @@ -0,0 +1,75 @@ + + + + + +

+ This test checks if FOP can handle the case where more columns are actually used than + specified. +

+

+ Note: This test case is technically wrong since in fixed table layout all + column-widths must be specified. But we don't want to have FOP crash + with an IndexOutOfBoundsException either. +

+
+ + + + + + + + + + + + + + + cell 1/1 + + + + + cell 2/1 + + + cell 2/2 + + + cell 2/3 + + + + + + + + + + + + + + + + + + +
-- 2.39.5