]> source.dussan.org Git - poi.git/commitdiff
Bug 50681 - Avoid exception in HSSFDataFormat.getDataFormatString()
authorYegor Kozlov <yegor@apache.org>
Thu, 16 Jun 2011 10:13:16 +0000 (10:13 +0000)
committerYegor Kozlov <yegor@apache.org>
Thu, 16 Jun 2011 10:13:16 +0000 (10:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1136352 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/usermodel/HSSFDataFormat.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormat.java

index c54e3d0db8e7e3549cc8536c4d8bd7ff7d8f4a69..b3a8f4f966ddb76e14099ecb685aeff42915c9a1 100644 (file)
 
     <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>
index 382452ca97d15026f3b114e6edeab2a1f734c93f..e2a87a4639b374e2dc897e998d0e44aab9e13513 100644 (file)
@@ -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) {
index 6eb9b8dbbbc64c075312642909f49bddc8a755c6..74116219f5036d5c07bcfc8dfb1f8d223e83b21e 100644 (file)
@@ -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);
+                }
+            }
+        }
+    }
+
 }