]> source.dussan.org Git - poi.git/commitdiff
Bug 57925: Add unit test and a simple fix to at least avoid the NPE when Workbooks...
authorDominik Stadler <centic@apache.org>
Sat, 19 Sep 2015 12:22:42 +0000 (12:22 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 19 Sep 2015 12:22:42 +0000 (12:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1703999 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/OperationEvaluationContext.java
src/testcases/org/apache/poi/hssf/usermodel/TestBugs.java
test-data/spreadsheet/57925.xls [new file with mode: 0644]

index ce918926caa726b89ea7ef41973f3dc306749784..cc590772de5841ae14ac73e8b28c1dd12677aef9 100644 (file)
@@ -94,7 +94,11 @@ public final class OperationEvaluationContext {
                if (externalSheet == null || externalSheet.getWorkbookName() == null) {
                        // sheet is in same workbook
                        targetEvaluator = _bookEvaluator;
-                       otherFirstSheetIndex = _workbook.getSheetIndex(externalSheet.getSheetName());
+                       if(externalSheet == null) {
+                           otherFirstSheetIndex = 0;
+                       } else {
+                           otherFirstSheetIndex = _workbook.getSheetIndex(externalSheet.getSheetName());
+                       }
                        
                        if (externalSheet instanceof ExternalSheetRange) {
                            String lastSheetName = ((ExternalSheetRange)externalSheet).getLastSheetName();
index f472e3d1d4546d7833ba3d5e60fa18975bc4bc57..92661f8aeeb574efb46f5faaf9f7c069e0b03efc 100644 (file)
@@ -2846,4 +2846,22 @@ public final class TestBugs extends BaseTestBugzillaIssues {
 
         wb.close();
     }
+    
+    @Test
+    public void test57925() throws IOException {
+        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("57925.xls");
+        
+        wb.getCreationHelper().createFormulaEvaluator().evaluateAll();
+        
+        for(int i = 0;i < wb.getNumberOfSheets();i++) {
+            Sheet sheet = wb.getSheetAt(i);
+            for(Row row : sheet) {
+                for(Cell cell : row) {
+                    new DataFormatter().formatCellValue(cell);
+                }
+            }
+        }
+        
+        wb.close();
+    }
 }
diff --git a/test-data/spreadsheet/57925.xls b/test-data/spreadsheet/57925.xls
new file mode 100644 (file)
index 0000000..ef13551
Binary files /dev/null and b/test-data/spreadsheet/57925.xls differ