You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2015/04/13 14:19:11 UTC

svn commit: r1673168 - in /poi/trunk: src/java/org/apache/poi/hssf/model/InternalWorkbook.java src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java test-data/spreadsheet/57163.xls

Author: centic
Date: Mon Apr 13 12:19:11 2015
New Revision: 1673168

URL: http://svn.apache.org/r1673168
Log:
Bug 57163: Fix possible NullPointerException when a spreadsheet has no LinkTable and we try to adjust it during sheet removal.

Added:
    poi/trunk/test-data/spreadsheet/57163.xls   (with props)
Modified:
    poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java

Modified: poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java?rev=1673168&r1=1673167&r2=1673168&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/model/InternalWorkbook.java Mon Apr 13 12:19:11 2015
@@ -774,11 +774,12 @@ public final class InternalWorkbook {
             }
         }
         
-        // also tell the LinkTable about the removed sheet
-        // +1 because we already removed it from the count of sheets!
-        for(int i = sheetIndex+1;i < getNumSheets()+1;i++) {
-            // also update the link-table as otherwise references might point at invalid sheets
-            linkTable.removeSheet(i);
+        if (linkTable != null) {
+            // also tell the LinkTable about the removed sheet
+            // +1 because we already removed it from the count of sheets!
+            for(int i = sheetIndex+1;i < getNumSheets()+1;i++) {
+                linkTable.removeSheet(i);
+            }
         }
     }
 

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java?rev=1673168&r1=1673167&r2=1673168&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java Mon Apr 13 12:19:11 2015
@@ -2716,4 +2716,14 @@ public final class TestBugs extends Base
         Workbook wb = openSample("57456.xls");
         wb.close();
     }
+    
+    @Test
+    public void test57163() throws IOException {
+        Workbook wb = openSample("57163.xls");
+        
+        while (wb.getNumberOfSheets() > 1) {
+            wb.removeSheetAt(1);
+        }
+        wb.close();
+    }
 }

Added: poi/trunk/test-data/spreadsheet/57163.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/57163.xls?rev=1673168&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/spreadsheet/57163.xls
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org