Bug 57925: Add unit test and a simple fix to at least avoid the NPE when Workbooks have invalid external references

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1703999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2015-09-19 12:22:42 +00:00
parent e47a129a5b
commit 12ace59f6e
3 changed files with 23 additions and 1 deletions

View File

@ -94,7 +94,11 @@ public final class OperationEvaluationContext {
if (externalSheet == null || externalSheet.getWorkbookName() == null) { if (externalSheet == null || externalSheet.getWorkbookName() == null) {
// sheet is in same workbook // sheet is in same workbook
targetEvaluator = _bookEvaluator; targetEvaluator = _bookEvaluator;
otherFirstSheetIndex = _workbook.getSheetIndex(externalSheet.getSheetName()); if(externalSheet == null) {
otherFirstSheetIndex = 0;
} else {
otherFirstSheetIndex = _workbook.getSheetIndex(externalSheet.getSheetName());
}
if (externalSheet instanceof ExternalSheetRange) { if (externalSheet instanceof ExternalSheetRange) {
String lastSheetName = ((ExternalSheetRange)externalSheet).getLastSheetName(); String lastSheetName = ((ExternalSheetRange)externalSheet).getLastSheetName();

View File

@ -2846,4 +2846,22 @@ public final class TestBugs extends BaseTestBugzillaIssues {
wb.close(); 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();
}
} }

Binary file not shown.