mirror of https://github.com/apache/poi.git
When removing one MergedRegion, the record was removed before it was ready,
causing a IndexOutOfBoundsException. Shifted the remove after the get to fix this. TestCase should verify old functionality hasn't been broken. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353164 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
efec23662f
commit
992f457092
|
@ -469,11 +469,12 @@ public class Sheet implements Model
|
||||||
numMergedRegions--;
|
numMergedRegions--;
|
||||||
if (rec.getNumAreas() == 0)
|
if (rec.getNumAreas() == 0)
|
||||||
{
|
{
|
||||||
mergedRecords.remove(pos);
|
|
||||||
if (merged == rec)
|
if (merged == rec)
|
||||||
merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1);
|
merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1);
|
||||||
int removePos = ((Integer) mergedLocs.get(pos)).intValue();
|
int removePos = ((Integer) mergedLocs.get(pos)).intValue();
|
||||||
records.remove(removePos);
|
records.remove(removePos);
|
||||||
|
mergedRecords.remove(pos);
|
||||||
mergedLocs.remove(pos);
|
mergedLocs.remove(pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,18 +54,20 @@
|
||||||
|
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
import org.apache.poi.hssf.model.Sheet;
|
|
||||||
import org.apache.poi.hssf.record.HCenterRecord;
|
|
||||||
import org.apache.poi.hssf.record.VCenterRecord;
|
|
||||||
import org.apache.poi.hssf.record.WSBoolRecord;
|
|
||||||
import org.apache.poi.hssf.record.SCLRecord;
|
|
||||||
import org.apache.poi.hssf.record.WindowTwoRecord;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import org.apache.poi.hssf.model.Sheet;
|
||||||
|
import org.apache.poi.hssf.record.HCenterRecord;
|
||||||
|
import org.apache.poi.hssf.record.SCLRecord;
|
||||||
|
import org.apache.poi.hssf.record.VCenterRecord;
|
||||||
|
import org.apache.poi.hssf.record.WSBoolRecord;
|
||||||
|
import org.apache.poi.hssf.record.WindowTwoRecord;
|
||||||
|
import org.apache.poi.hssf.util.Region;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests HSSFSheet. This test case is very incomplete at the moment.
|
* Tests HSSFSheet. This test case is very incomplete at the moment.
|
||||||
*
|
*
|
||||||
|
@ -254,4 +256,30 @@ public class TestHSSFSheet
|
||||||
assertTrue(sclLoc == window2Loc + 1);
|
assertTrue(sclLoc == window2Loc + 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When removing one merged region, it would break
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public void testRemoveMerged() {
|
||||||
|
HSSFWorkbook wb = new HSSFWorkbook();
|
||||||
|
HSSFSheet sheet = wb.createSheet();
|
||||||
|
Region region = new Region(0, (short)0, 1, (short)1);
|
||||||
|
sheet.addMergedRegion(region);
|
||||||
|
region = new Region(1, (short)0, 2, (short)1);
|
||||||
|
sheet.addMergedRegion(region);
|
||||||
|
|
||||||
|
sheet.removeMergedRegion(0);
|
||||||
|
|
||||||
|
region = sheet.getMergedRegionAt(0);
|
||||||
|
assertEquals("Left over region should be starting at row 1", 1, region.getRowFrom());
|
||||||
|
|
||||||
|
sheet.removeMergedRegion(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(java.lang.String[] args) {
|
||||||
|
junit.textui.TestRunner.run(TestHSSFSheet.class);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue