You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ye...@apache.org on 2011/06/16 12:13:16 UTC
svn commit: r1136352 - in /poi/trunk/src:
documentation/content/xdocs/status.xml
java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
Author: yegor
Date: Thu Jun 16 10:13:16 2011
New Revision: 1136352
URL: http://svn.apache.org/viewvc?rev=1136352&view=rev
Log:
Bug 50681 - Avoid exception in HSSFDataFormat.getDataFormatString()
Modified:
poi/trunk/src/documentation/content/xdocs/status.xml
poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
Modified: poi/trunk/src/documentation/content/xdocs/status.xml
URL: http://svn.apache.org/viewvc/poi/trunk/src/documentation/content/xdocs/status.xml?rev=1136352&r1=1136351&r2=1136352&view=diff
==============================================================================
--- poi/trunk/src/documentation/content/xdocs/status.xml (original)
+++ poi/trunk/src/documentation/content/xdocs/status.xml Thu Jun 16 10:13:16 2011
@@ -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>
Modified: poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java?rev=1136352&r1=1136351&r2=1136352&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java Thu Jun 16 10:13:16 2011
@@ -142,8 +142,14 @@ public final class HSSFDataFormat implem
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) {
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java?rev=1136352&r1=1136351&r2=1136352&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java Thu Jun 16 10:13:16 2011
@@ -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 ex
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);
+ }
+ }
+ }
+ }
+
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org