From fb6c7e85de3e95dff97a2a7fb1a8ed2a4f11a02e Mon Sep 17 00:00:00 2001 From: Danny Muid Date: Fri, 27 Jun 2003 23:04:28 +0000 Subject: [PATCH] Round 2 with removing merged regions. The MergedRecords array would be emptied when removing all the regions but the merged pointer was still being preserved. Kill the pointer if the record is removed from the list so things are golden again. git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353166 13f79535-47bb-0310-9956-ffa450edef68 --- src/java/org/apache/poi/hssf/model/Sheet.java | 4 ++++ .../poi/hssf/usermodel/TestHSSFSheet.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/java/org/apache/poi/hssf/model/Sheet.java b/src/java/org/apache/poi/hssf/model/Sheet.java index 1dbafd7bc..1c87da87b 100644 --- a/src/java/org/apache/poi/hssf/model/Sheet.java +++ b/src/java/org/apache/poi/hssf/model/Sheet.java @@ -476,6 +476,10 @@ public class Sheet implements Model records.remove(removePos); mergedRecords.remove(pos); mergedLocs.remove(pos); + + //if we're not tracking merged records, kill the pointer to reset the state + if (mergedRecords.size() == 0) merged = null; + } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java index 66d475edc..f021c5439 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java @@ -276,6 +276,25 @@ public class TestHSSFSheet assertEquals("Left over region should be starting at row 1", 1, region.getRowFrom()); sheet.removeMergedRegion(0); + + assertEquals("there should be no merged regions left!", 0, sheet.getNumMergedRegions()); + + //an, add, remove, get(0) would null pointer + sheet.addMergedRegion(region); + assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions()); + sheet.removeMergedRegion(0); + assertEquals("there should now be zero merged regions!", 0, sheet.getNumMergedRegions()); + //add it again! + region.setRowTo(4); + + sheet.addMergedRegion(region); + assertEquals("there should now be one merged region!", 1, sheet.getNumMergedRegions()); + + //should exist now! + assertTrue("there isn't more than one merged region in there", 1 <= sheet.getNumMergedRegions()); + region = sheet.getMergedRegionAt(0); + assertEquals("the merged row to doesnt match the one we put in ", 4, region.getRowTo()); + } public static void main(java.lang.String[] args) {