From f970e15d282ae09cd0a00f04745d237e3fa71ac4 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Thu, 18 May 2006 15:54:17 +0000 Subject: [PATCH] Bugzilla #39533: Bugfix: NullPointerException in RTF output when a table does not contain table-columns. The code now informs the user that he should explicitely define the table-columns. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@407576 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/render/rtf/RTFHandler.java | 10 ++++++-- .../rtf/rtflib/rtfdoc/ITableColumnsInfo.java | 2 +- .../render/rtf/rtflib/tools/TableContext.java | 24 +++++++++++-------- .../testdocs/DummyTableColumnsInfo.java | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/java/org/apache/fop/render/rtf/RTFHandler.java b/src/java/org/apache/fop/render/rtf/RTFHandler.java index ed33cf9df..d50cd7a61 100644 --- a/src/java/org/apache/fop/render/rtf/RTFHandler.java +++ b/src/java/org/apache/fop/render/rtf/RTFHandler.java @@ -1585,8 +1585,14 @@ public class RTFHandler extends FOEventHandler { Table table = (Table) foNode; //recurse all table-columns - for (Iterator it = table.getColumns().iterator(); it.hasNext();) { - recurseFONode( (FONode) it.next() ); + if (table.getColumns() != null) { + for (Iterator it = table.getColumns().iterator(); it.hasNext();) { + recurseFONode( (FONode) it.next() ); + } + } else { + //TODO Implement implicit column setup handling! + log.warn("No table-columns found on table. RTF output requires that all" + + " table-columns for a table are defined. Output will be incorrect."); } //recurse table-header diff --git a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java index f744ec7ec..2f624fa7d 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/rtfdoc/ITableColumnsInfo.java @@ -31,7 +31,7 @@ package org.apache.fop.render.rtf.rtflib.rtfdoc; public interface ITableColumnsInfo { /** value for invalid column width */ - float INVALID_COLUM_WIDTH = 200f; + float INVALID_COLUMN_WIDTH = 200f; /** reset the column iteration index, meant to be called when creating a new row */ void selectFirstColumn(); diff --git a/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java b/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java index 0f5f67635..176e173de 100644 --- a/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java +++ b/src/java/org/apache/fop/render/rtf/rtflib/tools/TableContext.java @@ -94,12 +94,10 @@ public class TableContext implements ITableColumnsInfo { } /** - * + * Adds a column and sets its width. * @param width Width of next column - * @throws Exception */ - public void setNextColumnWidth(Float width) - throws Exception { + public void setNextColumnWidth(Float width) { colWidths.add(width); } @@ -165,6 +163,9 @@ public class TableContext implements ITableColumnsInfo { boolean bFirstSpanningCol) { if (colIndex < colRowSpanningNumber.size()) { + while (colIndex >= colFirstSpanningCol.size()) { + setNextFirstSpanningCol(false); + } colFirstSpanningCol.set(colIndex, new Boolean(bFirstSpanningCol)); } else { colFirstSpanningCol.add(new Boolean(bFirstSpanningCol)); @@ -229,13 +230,16 @@ public class TableContext implements ITableColumnsInfo { * 'number-columns-spanned' processing */ public float getColumnWidth() { - try { - return ((Float)colWidths.get(colIndex)).floatValue(); - } catch (IndexOutOfBoundsException ex) { - // this code contributed by Trembicki-Guy, Ed - log.warn("fo:table-column width not defined, using " + INVALID_COLUM_WIDTH); - return INVALID_COLUM_WIDTH; + if (colIndex < 0) { + throw new IllegalStateException("colIndex must not be negative!"); + } else if (colIndex >= getNumberOfColumns()) { + log.warn("Column width for column " + (colIndex + 1) + " is not defined, using " + + INVALID_COLUMN_WIDTH); + while (colIndex >= getNumberOfColumns()) { + setNextColumnWidth(new Float(INVALID_COLUMN_WIDTH)); + } } + return ((Float)colWidths.get(colIndex)).floatValue(); } /** diff --git a/test/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java b/test/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java index 49f40b471..15a60f6f3 100644 --- a/test/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java +++ b/test/java/org/apache/fop/render/rtf/rtflib/testdocs/DummyTableColumnsInfo.java @@ -39,7 +39,7 @@ import org.apache.fop.render.rtf.rtflib.rtfdoc.ITableColumnsInfo; class DummyTableColumnsInfo implements ITableColumnsInfo { public float getColumnWidth() { - return INVALID_COLUM_WIDTH; + return INVALID_COLUMN_WIDTH; } public void selectFirstColumn() { -- 2.39.5