From 48ac6b4d028e441e1cb9d617cab364365e750fbc Mon Sep 17 00:00:00 2001 From: Greg Woolsey Date: Sun, 31 Mar 2019 03:49:16 +0000 Subject: [PATCH] fix a condition not seen until a recent expansion of the stress test. Gracefully ignore missing/invalid external sheet references in one more path (there were several already with comments like "this seems to be what Excel does in this case") git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1856655 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/poi/ss/formula/SheetNameFormatter.java | 2 +- .../hssf/usermodel/TestHSSFEvaluationSheet.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java b/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java index 37daee5165..d71436dc47 100644 --- a/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java +++ b/src/java/org/apache/poi/ss/formula/SheetNameFormatter.java @@ -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 diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java index 81700ae56a..c53e01b4aa 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFEvaluationSheet.java @@ -17,9 +17,12 @@ 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(); + } + } + } } -- 2.39.5