From: Tim Allison Date: Thu, 13 Aug 2020 18:21:28 +0000 (+0000) Subject: Bug 64667.xlsx prevent NPE loading styles table X-Git-Tag: before_ooxml_3rd_edition~156 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=ab2dc71a955d72faae3a0cd8df2ca89c1eaf9015;p=poi.git Bug 64667.xlsx prevent NPE loading styles table git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1880834 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java index 2c89c2fae3..bfc24db6d0 100644 --- a/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java +++ b/src/ooxml/java/org/apache/poi/xssf/model/StylesTable.java @@ -239,7 +239,7 @@ public class StylesTable extends POIXMLDocumentPart implements Styles { if(styleDxfs != null) dxfs.addAll(Arrays.asList(styleDxfs.getDxfArray())); CTTableStyles ctTableStyles = styleSheet.getTableStyles(); - if (ctTableStyles != null) { + if (ctTableStyles != null && styleDxfs != null) { int idx = 0; for (CTTableStyle style : ctTableStyles.getTableStyleArray()) { tableStyles.put(style.getName(), new XSSFTableStyle(idx, styleDxfs, style, indexedColors)); diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java index b456d91aa6..22cf3f3a7a 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFBugs.java @@ -3560,4 +3560,12 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues { Assert.assertEquals("", aCell.getStringCellValue()); } } + + @Test + public void testBug64667() throws IOException { + //test that an NPE isn't thrown on opening + try (Workbook wb = XSSFTestDataSamples.openSampleWorkbook("64667.xlsx")) { + int activeSheet = wb.getActiveSheetIndex(); + } + } } diff --git a/test-data/spreadsheet/64667.xlsx b/test-data/spreadsheet/64667.xlsx new file mode 100644 index 0000000000..0541985d11 Binary files /dev/null and b/test-data/spreadsheet/64667.xlsx differ