From commits-return-2746-apmail-poi-commits-archive=poi.apache.org@poi.apache.org Thu Jun 16 10:13:41 2011 Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 403826493 for ; Thu, 16 Jun 2011 10:13:41 +0000 (UTC) Received: (qmail 44937 invoked by uid 500); 16 Jun 2011 10:13:41 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 44904 invoked by uid 500); 16 Jun 2011 10:13:41 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 44897 invoked by uid 99); 16 Jun 2011 10:13:41 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2011 10:13:41 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Jun 2011 10:13:38 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id DD92D23888DD; Thu, 16 Jun 2011 10:13:16 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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 Date: Thu, 16 Jun 2011 10:13:16 -0000 To: commits@poi.apache.org From: yegor@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110616101316.DD92D23888DD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ - 50681 - Fixed autosizing columns beyond 255 character limit - 51374 - Fixed incorrect setting of lastPrinted OOXML core property + 50681 - Avoid exceptions in HSSFDataFormat.getDataFormatString() + 50681 - Fixed autosizing columns beyond 255 character limit + 51374 - Fixed incorrect setting of lastPrinted OOXML core property 51351 - Word to XSL-FO converter - 50458 - Fixed missing shapeId in XSSF drawings - 51339 - Fixed arithmetic rounding in formula evaluation + 50458 - Fixed missing shapeId in XSSF drawings + 51339 - Fixed arithmetic rounding in formula evaluation 51356 - Support autoSizeColumn in SXSSF 51335 - Parse picture goal and crop sizes in HWPF 51305 - Add sprmTCellPaddingDefault support in HWPF 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