]> source.dussan.org Git - poi.git/commitdiff
Fix for bug 45367 - fixed boundary case when row zero is the last row removed from...
authorJosh Micich <josh@apache.org>
Wed, 9 Jul 2008 14:58:06 +0000 (14:58 +0000)
committerJosh Micich <josh@apache.org>
Wed, 9 Jul 2008 14:58:06 +0000 (14:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@675218 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/changes.xml
src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFSheet.java

index 2507fafbeaaec8dadb7e047fa838c48bc6ebe210..6756dcc360ace1c11eb516b7a0b0637644da8055 100644 (file)
@@ -37,6 +37,7 @@
 
                <!-- Don't forget to update status.xml too! -->
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45367 - Fixed bug when last row removed from sheet is row zero</action>
            <action dev="POI-DEVELOPERS" type="fix">45348 - Tweaks to RVA formula logic</action>
            <action dev="POI-DEVELOPERS" type="fix">45354 - Fixed recognition of named ranges within formulas</action>
            <action dev="POI-DEVELOPERS" type="fix">45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts</action>
index 013b3b3bd1a8f6f3beae65b7ab974dda863e4bda..bbf536e73cc60975c3d1021e10efddd455b69e6e 100644 (file)
@@ -34,6 +34,7 @@
        <!-- Don't forget to update changes.xml too! -->
     <changes>
         <release version="3.1.1-alpha1" date="2008-??-??">
+           <action dev="POI-DEVELOPERS" type="fix">45367 - Fixed bug when last row removed from sheet is row zero</action>
            <action dev="POI-DEVELOPERS" type="fix">45348 - Tweaks to RVA formula logic</action>
            <action dev="POI-DEVELOPERS" type="fix">45354 - Fixed recognition of named ranges within formulas</action>
            <action dev="POI-DEVELOPERS" type="fix">45338 - Fix HSSFWorkbook to give you the same HSSFFont every time, and then fix it to find newly added fonts</action>
index cf4cff86d74cc4f0f9fd7e4d274d68a028c5f151..ea2b8132d05619a5e92261c0413ac309b1610c8f 100644 (file)
@@ -262,18 +262,19 @@ public final class HSSFSheet {
     /**
      * used internally to refresh the "last row" when the last row is removed.
      */
-
-    private int findLastRow(int lastrow)
-    {
+    private int findLastRow(int lastrow) {
+        if (lastrow < 1) {
+            return -1;
+        }
         int rownum = lastrow - 1;
         HSSFRow r = getRow(rownum);
 
-        while (r == null && rownum > 0)
-        {
+        while (r == null && rownum > 0) {
             r = getRow(--rownum);
         }
-        if (r == null)
-          return -1;
+        if (r == null) {
+            return -1;
+        }
         return rownum;
     }
 
index 4a5f33c4b9120d36570eac54bbe61a9805ee5eac..7fa84b853aec390be6ecac6756a9509a2523aebb 100644 (file)
@@ -169,6 +169,20 @@ public final class TestHSSFSheet extends TestCase {
                sheet.removeRow(row);
        }
 
+       public void testRemoveZeroRow() {
+               HSSFWorkbook workbook = new HSSFWorkbook();
+               HSSFSheet sheet = workbook.createSheet("Sheet1");
+               HSSFRow row = sheet.createRow(0);
+               try {
+                       sheet.removeRow(row);
+               } catch (IllegalArgumentException e) {
+                       if (e.getMessage().equals("Invalid row number (-1) outside allowable range (0..65535)")) {
+                               throw new AssertionFailedError("Identified bug 45367");
+                       }
+                       throw e;
+               }
+       }
+
        public void testCloneSheet() {
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("Test Clone");