Bug 47169

Summary: HSSFSheet.shiftRows() causes record inconsistency: Specified rowIndex 30 is outside the allowable range (0..30)
Product: POI Reporter: Volker Bergmann <info>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 3.2-FINAL   
Target Milestone: ---   
Hardware: All   
OS: All   

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.