From 1b65bb839a01ed8f830a475f8c668ff5b2a51e24 Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Mon, 19 Dec 2011 09:06:10 +0000 Subject: [PATCH] Bugzilla 52348: Avoid exception when creating cell style in a workbook that has an empty xf table git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1220659 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/xssf/usermodel/XSSFCellStyle.java | 6 +++--- .../poi/xssf/usermodel/TestXSSFCellStyle.java | 15 +++++++++++++++ test-data/spreadsheet/52348.xlsx | Bin 0 -> 5292 bytes 4 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 test-data/spreadsheet/52348.xlsx diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index f9609297ca..735eedfbae 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 52348 - Avoid exception when creating cell style in a workbook that has an empty xf table 52219 - fixed XSSFSimpleShape to set rich text attributes from XSSFRichtextString 52314 - enhanced SheetUtil.getColumnWidth diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java index 51ffe6e06e..d633300ae6 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFCellStyle.java @@ -68,15 +68,15 @@ public class XSSFCellStyle implements CellStyle { /** * Creates a Cell Style from the supplied parts - * @param cellXfId The main XF for the cell - * @param cellStyleXfId Optional, style xf + * @param cellXfId The main XF for the cell. Must be a valid 0-based index into the XF table + * @param cellStyleXfId Optional, style xf. A value of -1 means no xf. * @param stylesSource Styles Source to work off */ public XSSFCellStyle(int cellXfId, int cellStyleXfId, StylesTable stylesSource, ThemesTable theme) { _cellXfId = cellXfId; _stylesSource = stylesSource; _cellXf = stylesSource.getCellXfAt(this._cellXfId); - _cellStyleXf = stylesSource.getCellStyleXfAt(cellStyleXfId); + _cellStyleXf = cellStyleXfId == -1 ? null : stylesSource.getCellStyleXfAt(cellStyleXfId); _theme = theme; } diff --git a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java index a9c968c7e3..11b724f4ab 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFCellStyle.java @@ -691,4 +691,19 @@ public class TestXSSFCellStyle extends TestCase { assertEquals(fmtClone.getFormat("Test##"), reload.getDataFormat()); assertFalse(fmtClone.getFormat("Test##") == fmt.getFormat("Test##")); } + + /** + * Avoid ArrayIndexOutOfBoundsException when creating cell style + * in a workbook that has an empty xf table. + */ + public void testBug52348() { + XSSFWorkbook workbook = XSSFTestDataSamples.openSampleWorkbook("52348.xlsx"); + StylesTable st = workbook.getStylesSource(); + assertEquals(0, st._getStyleXfsSize()); + + + XSSFCellStyle style = workbook.createCellStyle(); // no exception at this point + assertNull(style.getStyleXf()); + } + } diff --git a/test-data/spreadsheet/52348.xlsx b/test-data/spreadsheet/52348.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..356490d8da7c7dac39a21d0778c487bad68ddbf9 GIT binary patch literal 5292 zcma)A2UL?=vxQKDAP7haAkw6V-XjEvNGJ3nRRQTiLJ{dLV2OmFARPoj5TuF%(tEx1 z-V_i-dPfvq@ZSFyeeb&7d@F0^WS!YLv)6oQ_6%HufRGlC6!$#0z*oRKW0bh>cU^>h z5FXAq5eR4ST~`;hjuxUpn7n%5*rZ0elBL(+&4Q@b#}=D!!I(;M_F{f+;e-9oC5-pv z>ezbYU#oj`1m0h<{-IwEKkdYW&h6kH_ouB^fX21&CA&r<87) zqoCLw8B;&4af4*&`_=N?AE@umbW?AZ{)bqZR@HXjt*V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