Bug 26100

Summary: 128-character message in IF statement cell causes HSSFWorkbook open failure
Product: POI Reporter: Jun Zuo <jun.zuo>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: blocker CC: yukafai
Priority: P3    
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: Sample Excel file (version Excel 2000)

Description Jun Zuo 2004-01-13 15:31:48 UTC
In version 2.0 (2.0-RC2) but not 1.5.1, if a cell contains an IF statement that 
has a message longer than 127 characters, the following error occurs:

java.lang.reflect.InvocationTargetException: 
java.lang.IllegalArgumentException: Illegal length
	at org.apache.poi.util.StringUtil.getFromUnicode(StringUtil.java:170)
	at org.apache.poi.hssf.record.formula.StringPtg.<init>
(StringPtg.java:92)
	at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:272)
	at org.apache.poi.hssf.record.FormulaRecord.getParsedExpressionTokens
(FormulaRecord.java:181)
	at org.apache.poi.hssf.record.FormulaRecord.fillFields
(FormulaRecord.java:157)
	at org.apache.poi.hssf.record.Record.fillFields(Record.java:127)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:92)
	at org.apache.poi.hssf.record.FormulaRecord.<init>
(FormulaRecord.java:122)
	at java.lang.reflect.Constructor.newInstance(Native Method)
	at org.apache.poi.hssf.record.RecordFactory.createRecord
(RecordFactory.java:257)
	at org.apache.poi.hssf.record.RecordFactory.createRecords
(RecordFactory.java:193)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:207)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:254)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:235)
Comment 1 Avik Sengupta 2004-01-13 15:38:43 UTC
I vaguely remember there was a good reason for this limitation in POI .. I
thought excel had issues with long strings in formulas in some situations.. You
are trying to read an existing excel file, i presume??

Is it possible for you to attach the file to this bug? What version of Excel did
u save the file with?
Comment 2 Jun Zuo 2004-01-13 16:11:29 UTC
Created attachment 9937 [details]
Sample Excel file (version Excel 2000)
Comment 3 Jun Zuo 2004-01-13 16:13:15 UTC
With the attached Excel, the error is:

java.lang.reflect.InvocationTargetException: 
java.lang.StringIndexOutOfBoundsException: length must be >= 0
	at java.lang.String.<init>(Unknown Source)
	at java.lang.String.<init>(Unknown Source)
	at org.apache.poi.util.StringUtil.getFromCompressedUnicode
(StringUtil.java:212)
	at org.apache.poi.hssf.record.formula.StringPtg.<init>
(StringPtg.java:94)
	at org.apache.poi.hssf.record.formula.Ptg.createPtg(Ptg.java:272)
	at org.apache.poi.hssf.record.FormulaRecord.getParsedExpressionTokens
(FormulaRecord.java:181)
	at org.apache.poi.hssf.record.FormulaRecord.fillFields
(FormulaRecord.java:157)
	at org.apache.poi.hssf.record.Record.fillFields(Record.java:127)
	at org.apache.poi.hssf.record.Record.<init>(Record.java:92)
	at org.apache.poi.hssf.record.FormulaRecord.<init>
(FormulaRecord.java:122)
	at java.lang.reflect.Constructor.newInstance(Native Method)
	at org.apache.poi.hssf.record.RecordFactory.createRecord
(RecordFactory.java:257)
	at org.apache.poi.hssf.record.RecordFactory.createRecords
(RecordFactory.java:193)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:207)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:254)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>
(HSSFWorkbook.java:235)
	
Comment 4 Avik Sengupta 2005-05-20 12:11:36 UTC
*** Bug 26894 has been marked as a duplicate of this bug. ***
Comment 5 Avik Sengupta 2007-01-16 01:34:03 UTC
Works as of 12Jan2007, Testcase added. 
http://issues.apache.org/bugzilla/show_bug.cgi?id=41366