Bug 43086

Summary: OutOfBoundsException in autoSizeColumn
Product: POI Reporter: PiterBoss <komisarskip>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED WONTFIX    
Severity: normal CC: wim.deblauwe
Priority: P1    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: Other   
OS: Windows XP   
Attachments: Testcase for this bug
Improved version of the test case by Wim Deblauwe

Description PiterBoss 2007-08-10 06:21:05 UTC
this is my code

for(int i=0;i<30;i++)
    sheet.autoSizeColumn((short)i);



and this is stacktrace:

java.lang.ArrayIndexOutOfBoundsException: -32721
	at java.util.ArrayList.get(ArrayList.java:323)
	at 
org.apache.poi.hssf.model.WorkbookRecordList.get(WorkbookRecordList.java:54)
	at org.apache.poi.hssf.model.Workbook.getExFormatAt(Workbook.java:624)
	at 
org.apache.poi.hssf.usermodel.HSSFCell.getCellStyle(HSSFCell.java:856)
	at 
org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1424)
Comment 1 Nick Burch 2007-08-23 10:46:49 UTC
Your document probably contains some sort of invalid styling. It looks like the
autoSizing code is trying to fetch the font details for the cell, and is failing
when it can't find it.

If you upload the problem file, we can look at throwing a more helpful error
Comment 2 PiterBoss 2007-08-24 04:29:43 UTC
i have no file.
I'm trying to generate one....
Comment 3 Yegor Kozlov 2007-08-24 11:04:55 UTC
please post a full test case. 
I can't reproduce it. 

Regards,
Yegor
Comment 4 Wim Deblauwe 2007-10-31 09:18:50 UTC
Created attachment 21072 [details]
Testcase for this bug

The attached test program reproduces the bug. I also get the same stacktrace
and ArrayIndexOutOfBoundsException.

regards,

Wim
Comment 5 Yegor Kozlov 2007-11-05 22:36:31 UTC
thanks for the test case. 
I will find time to look into it.

Yegor
Comment 6 Yegor Kozlov 2007-11-06 05:28:01 UTC
Improper usage. 

The maximum number of fonts in a workbook is 32767 ( the maximum positive short).   
You are creating a new font for each cell in a loop and finally the font index
becomes negative. 
The subsequent call of HSSFSheet.autoSizeColumn results in
ArrayIndexOutOfBoundsException.

See how I suggest rewriting your sample code. It should work fine. 

P.S. I'm going to change HSSFWorkbook.createFont and throw an exception if the
font index becomes greater than 32767. 
This way users will get a clearer indication of the problem. I will commit the
fix in a little while.

Regards,
Yegor
Comment 7 Yegor Kozlov 2007-11-06 05:29:50 UTC
Created attachment 21091 [details]
Improved version of the test case by Wim Deblauwe
Comment 8 Wim Deblauwe 2007-11-06 06:13:24 UTC
Thank you for looking into this. You might want to add a note to the busy
developers guide (http://poi.apache.org/hssf/quick-guide.html#WorkingWithFonts)
for this.