Bug 17329 - removeMergedRegion() throws IndexOutOfBoundsException
Summary: removeMergedRegion() throws IndexOutOfBoundsException
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-pre3
Hardware: Other other
: P3 critical (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-02-24 07:17 UTC by Stefan Proels
Modified: 2004-11-16 19:05 UTC (History)
0 users



Attachments
Excel document for test case (8.50 KB, application/octet-stream)
2003-02-24 07:21 UTC, Stefan Proels
Details

Note You need to log in before you can comment on or make changes to this bug.
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