From 5bd3bb8e2892d0645201b37b36d519ad74a95d27 Mon Sep 17 00:00:00 2001 From: Jason Height Date: Sun, 21 Sep 2003 22:11:56 +0000 Subject: [PATCH] Small fix for when the start row didnt contain any cells. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353364 13f79535-47bb-0310-9956-ffa450edef68 --- .../record/aggregates/ValueRecordsAggregate.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java index e16d39510..d788abd68 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/ValueRecordsAggregate.java @@ -136,7 +136,15 @@ public class ValueRecordsAggregate * that are attached to the rows in the range specified. */ public int getRowCellBlockSize(int startRow, int endRow) { - Iterator cellRec = new VRAIterator(this, startRow, endRow);; + //Make sure that the row has cells + while (!rowHasCells(startRow) && (startRow <= endRow)) + startRow++; + if (startRow > endRow) { + //Couldnt find any cells between the row range provided. + return 0; + } + + Iterator cellRec = new VRAIterator(this, startRow, endRow); int size = 0; while (cellRec.hasNext()) { CellValueRecordInterface cell = (CellValueRecordInterface)cellRec.next(); @@ -149,6 +157,8 @@ public class ValueRecordsAggregate /** Returns true if the row has cells attached to it */ public boolean rowHasCells(int row) { + if (row >= celltype.size()) + return false; IntList ctRow = (IntList) celltype.get(row); return ((ctRow != null) && (ctRow.size() > 0)); } @@ -553,7 +563,9 @@ class VRAIterator implements Iterator { this.row = startRow; this.rowlimit = endRow; this.popindex = vra.populatedRows.indexOf(row); - if (vra.getPhysicalNumberOfCells() > 0) { + if (this.popindex == -1) { + hasNext = false; + } else if (vra.getPhysicalNumberOfCells() > 0) { next = findNextCell(null); hasNext = (next != null); }