Bug 47169 - HSSFSheet.shiftRows() causes record inconsistency: Specified rowIndex 30 is outside the allowable range (0..30)
Summary: HSSFSheet.shiftRows() causes record inconsistency: Specified rowIndex 30 is o...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.2-FINAL
Hardware: All All
: P2 major (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-05-08 10:57 UTC by Volker Bergmann
Modified: 2015-05-18 20:32 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Bergmann 2009-05-08 10:57:21 UTC
When using HSSFSheet.shiftRows(), the RowRecordsAggregate seems to get inconsistent with the ValueRecordsAggregate, resulting in the following exception:

Exception in thread "main" java.lang.IllegalArgumentException: Specified rowIndex 30 is outside the allowable range (0..30)
	at org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.removeAllCellsValuesForRow(ValueRecordsAggregate.java:111)
	at org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.removeRow(RowRecordsAggregate.java:120)
	at org.apache.poi.hssf.model.Sheet.addRow(Sheet.java:677)
	at org.apache.poi.hssf.usermodel.HSSFSheet.addRow(HSSFSheet.java:303)
	at org.apache.poi.hssf.usermodel.HSSFSheet.createRow(HSSFSheet.java:206)

Code to reproduce:

HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
sheet.createRow(30);
sheet.shiftRows(29, 29, 1, true, true);
sheet.createRow(30);

The first createRow() succeeds, the second fails. The first call can be left out, leading to the same result.

As workaroud is not enough to create the target explicitely before shifting the source row (as the reproducer code does), but you need to create a cell in this row. The following code works:

        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet sheet = workbook.createSheet();
        sheet.createRow(30).createCell(0);
        sheet.shiftRows(29, 29, 1, true, true);
        sheet.createRow(30);
Comment 1 Dominik Stadler 2015-05-18 20:32:58 UTC
This works with the latest version of POI, 3.12 and likely was fixed some time ago already.