]> source.dussan.org Git - poi.git/commitdiff
fix a condition not seen until a recent expansion of the stress test. Gracefully...
authorGreg Woolsey <gwoolsey@apache.org>
Sun, 31 Mar 2019 03:49:16 +0000 (03:49 +0000)
committerGreg Woolsey <gwoolsey@apache.org>
Sun, 31 Mar 2019 03:49:16 +0000 (03:49 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1856655 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ss/formula/SheetNameFormatter.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java

index 37daee5165fea3a1e4500e265ac5ebb1c405a307..d71436dc47f2fbb81e47d385d2dbfc3bcab13ef2 100644 (file)
@@ -179,7 +179,7 @@ public final class SheetNameFormatter {
 
                int len = rawSheetName.length();
                if(len < 1) {
-                       throw new RuntimeException("Zero length string is an invalid sheet name");
+                   return false; // some cases we get missing external references, resulting in empty sheet names
                }
                if(Character.isDigit(rawSheetName.charAt(0))) {
                        // sheet name with digit in the first position always requires delimiting
index 81700ae56a9a4f9e47d1f12b9f81583df9b45047..c53e01b4aaa1f1f78a5963f1c2583dee91286d3d 100644 (file)
 
 package org.apache.poi.hssf.usermodel;
 
+import org.apache.poi.hssf.HSSFTestDataSamples;
 import org.apache.poi.ss.formula.EvaluationSheet;
 import org.apache.poi.ss.usermodel.BaseTestXEvaluationSheet;
+import org.apache.poi.ss.usermodel.Name;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.junit.Test;
 
 import java.util.AbstractMap;
 import java.util.Map;
@@ -30,4 +33,15 @@ public class TestHSSFEvaluationSheet extends BaseTestXEvaluationSheet {
         HSSFSheet sheet = new HSSFWorkbook().createSheet();
         return new AbstractMap.SimpleEntry<>(sheet, new HSSFEvaluationSheet(sheet));
     }
+    
+    @Test
+    public void testMissingExternalName() {
+        HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("external_name.xls");
+        for (Name name : wb.getAllNames()) {
+            // this sometimes causes exceptions
+            if(!name.isFunctionName()) {
+                name.getRefersToFormula();
+            }
+        }
+    }
 }