]> source.dussan.org Git - poi.git/commitdiff
Bug 57163: Fix possible NullPointerException when a spreadsheet has no LinkTable...
authorDominik Stadler <centic@apache.org>
Mon, 13 Apr 2015 12:19:11 +0000 (12:19 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 13 Apr 2015 12:19:11 +0000 (12:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1673168 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/57163.xls [new file with mode: 0644]

index 3c3b91b148efbc783e5fc4b6e71302d40c2d4720..a2670978eaf6b6798ab7e65e5edfb6995ba78260 100644 (file)
@@ -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);
+            }
         }
     }
 
index 73256b6897a1140738899441313f4858b061fd91..0bb1de24b48cef7f69f78040202bf8c759c8fe33 100644 (file)
@@ -2716,4 +2716,14 @@ public final class TestBugs extends BaseTestBugzillaIssues {
         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();
+    }
 }
diff --git a/test-data/spreadsheet/57163.xls b/test-data/spreadsheet/57163.xls
new file mode 100644 (file)
index 0000000..402c954
Binary files /dev/null and b/test-data/spreadsheet/57163.xls differ