Bug 56899 - DataFormatter.formatRawCellContents throws IllegalArgumentException when certain parameter is passed in.
Summary: DataFormatter.formatRawCellContents throws IllegalArgumentException when cert...
Status: NEW
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.10-FINAL
Hardware: PC Mac OS X 10.4
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-29 16:26 UTC by Patrick Cheng
Modified: 2014-08-29 16:26 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Patrick Cheng 2014-08-29 16:26:36 UTC
Apologies for not having the actual XLSX file, so the parameter values are made up to reproduce the issue, and might not reflect reality.

DataFormatter formatter = new DataFormatter();
// the following will throw IllegalArgumentException
formatter.formatRawCellContents(formatter, "42", 0xe, "hello", false);

Here is what I found:
The index is one of the internal date format, DateUtil.isInternalDateFormat() returns true. Because if that, the formatString is not validate until it is passed to the constructor of ExcelStyleDateFormatter.

Because the formatString is invalid, when constructing ExcelStyleDateFormatter, the SimpleDateFormat's constructor will throw run time exception, and inside DateFormatter.createDateFormat() returns getDefaultFormat() which is a DecimalFormat.

Because we are trying to format a Date object using a DecimalFormat, an IllegalArgumentException is throw.