Bug 17329

Summary: removeMergedRegion() throws IndexOutOfBoundsException
Product: POI Reporter: Stefan Proels <stefan.proels>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: critical    
Priority: P3    
Version: 2.0-pre3   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: Excel document for test case

Description Stefan Proels 2003-02-24 07:17:32 UTC
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.
Comment 1 Stefan Proels 2003-02-24 07:21:48 UTC
Created attachment 4987 [details]
Excel document for test case
Comment 2 Andy Oliver 2003-07-24 15:47:13 UTC
IIRC this was fixed awhile ago... someone please verify.  (like whoever fixed it)
Comment 3 Danny Mui 2003-07-24 15:52:01 UTC
yes i fixed it about 3 weeks ago, please verify with pre2