aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYegor Kozlov <yegor@apache.org>2011-06-16 10:13:16 +0000
committerYegor Kozlov <yegor@apache.org>2011-06-16 10:13:16 +0000
commite40d99937e2acd9a2e4a1f759b9522e9919f8fc2 (patch)
tree67561c518e8e7a8f22fe2a199561f9ab733ce373
parent64208474aa8497da8bbb77d722f1becd894324f5 (diff)
downloadpoi-e40d99937e2acd9a2e4a1f759b9522e9919f8fc2.tar.gz
poi-e40d99937e2acd9a2e4a1f759b9522e9919f8fc2.zip
Bug 50681 - Avoid exception in HSSFDataFormat.getDataFormatString()
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1136352 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/documentation/content/xdocs/status.xml9
-rw-r--r--src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java10
-rw-r--r--src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java25
3 files changed, 35 insertions, 9 deletions
diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml
index c54e3d0db8..b3a8f4f966 100644
--- a/src/documentation/content/xdocs/status.xml
+++ b/src/documentation/content/xdocs/status.xml
@@ -34,11 +34,12 @@
<changes>
<release version="3.8-beta4" date="2011-??-??">
- <action dev="poi-developers" type="add">50681 - Fixed autosizing columns beyond 255 character limit </action>
- <action dev="poi-developers" type="add">51374 - Fixed incorrect setting of lastPrinted OOXML core property </action>
+ <action dev="poi-developers" type="fix">50681 - Avoid exceptions in HSSFDataFormat.getDataFormatString() </action>
+ <action dev="poi-developers" type="fix">50681 - Fixed autosizing columns beyond 255 character limit </action>
+ <action dev="poi-developers" type="fix">51374 - Fixed incorrect setting of lastPrinted OOXML core property </action>
<action dev="poi-developers" type="add">51351 - Word to XSL-FO converter</action>
- <action dev="poi-developers" type="add">50458 - Fixed missing shapeId in XSSF drawings </action>
- <action dev="poi-developers" type="add">51339 - Fixed arithmetic rounding in formula evaluation </action>
+ <action dev="poi-developers" type="fix">50458 - Fixed missing shapeId in XSSF drawings </action>
+ <action dev="poi-developers" type="fix">51339 - Fixed arithmetic rounding in formula evaluation </action>
<action dev="poi-developers" type="add">51356 - Support autoSizeColumn in SXSSF</action>
<action dev="poi-developers" type="add">51335 - Parse picture goal and crop sizes in HWPF</action>
<action dev="poi-developers" type="add">51305 - Add sprmTCellPaddingDefault support in HWPF</action>
diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java b/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
index 382452ca97..e2a87a4639 100644
--- a/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
+++ b/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
@@ -142,8 +142,14 @@ public final class HSSFDataFormat implements DataFormat {
if (_movedBuiltins) {
return _formats.get(index);
}
-
- String fmt = _formats.get(index);
+
+ if(index == -1) {
+ // YK: formatIndex can be -1, for example, for cell in column Y in test-data/spreadsheet/45322.xls
+ // return null for those
+ return null;
+ }
+
+ String fmt = _formats.size() > index ? _formats.get(index) : null;
if (_builtinFormats.length > index && _builtinFormats[index] != null) {
// It's in the built in range
if (fmt != null) {
diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
index 6eb9b8dbbb..74116219f5 100644
--- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
+++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
@@ -19,9 +19,8 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.HSSFITestDataProvider;
import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.usermodel.BaseTestDataFormat;
-import org.apache.poi.ss.usermodel.BuiltinFormats;
-import org.apache.poi.ss.usermodel.DataFormat;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.ss.util.CellReference;
/**
* Tests for {@link HSSFDataFormat}
@@ -49,4 +48,24 @@ public final class TestHSSFDataFormat extends BaseTestDataFormat {
assertTrue(customFmtIdx >= BuiltinFormats.FIRST_USER_DEFINED_FORMAT_INDEX );
assertEquals("\u00a3##.00[Yellow]", dataFormat.getFormat(customFmtIdx));
}
+
+ /**
+ * Bug 51378: getDataFormatString method call crashes when reading the test file
+ */
+ public void test51378(){
+ HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("12561-1.xls");
+ for (int i = 0; i < wb.getNumberOfSheets(); i++) {
+ HSSFSheet sheet = wb.getSheetAt(i);
+ for (Row row : sheet) {
+ for (Cell cell : row) {
+ CellStyle style = cell.getCellStyle();
+
+ String fmt = style.getDataFormatString();
+ if(fmt == null)
+ System.out.println(cell + ": " + fmt);
+ }
+ }
+ }
+ }
+
}