HSSFSheet.removeMergedRegion() throws an IndexOutOfBoundsException. The document I'm testing contains 2 merged regions. The following code is supposed to remove them all. However, when trying to remove the second region it throw the exception. This is the test program: ----------------------------------- import java.io.*; import org.apache.poi.poifs.filesystem.*; import org.apache.poi.hssf.usermodel.*; public class Test { public static void main(String[] args) throws Exception { FileInputStream in = new FileInputStream("example.xls"); POIFSFileSystem fs = new POIFSFileSystem(in); HSSFWorkbook wb = new HSSFWorkbook(fs); HSSFSheet sheet = wb.getSheetAt(0); int numRegions = sheet.getNumMergedRegions(); for (int i = 0; i < numRegions; i++) { System.out.println("removing region " + sheet.getMergedRegionAt(0)); sheet.removeMergedRegion(0); } } } ----------------------------------- and here is what happens: ----------------------------------- removing region org.apache.poi.hssf.util.Region@3eca90 removing region org.apache.poi.hssf.util.Region@64dc11 Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 95, Size: 36 at java.util.ArrayList.RangeCheck(ArrayList.java:508) at java.util.ArrayList.remove(ArrayList.java:388) at org.apache.poi.hssf.model.Sheet.removeMergedRegion(Sheet.java:342) at org.apache.poi.hssf.usermodel.HSSFSheet.removeMergedRegion(HSSFSheet.java:502) at Test.main(Test.java:17) ----------------------------------- The problem occured to me with POI versions 1.5.1 and 1.9.0.
Created attachment 4987 [details] Excel document for test case
IIRC this was fixed awhile ago... someone please verify. (like whoever fixed it)
yes i fixed it about 3 weeks ago, please verify with pre2