Bug 45322 - POI reportSheet.autoSizeColumn java.lang.ArrayIndexOutOfBoundsException: -1 HSSFDataFormat.getFormat
Summary: POI reportSheet.autoSizeColumn java.lang.ArrayIndexOutOfBoundsException: -1 H...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: PC Windows XP
: P2 minor (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords: ErrorMessage
Depends on:
Blocks:
 
Reported: 2008-07-01 17:09 UTC by Partha
Modified: 2009-10-28 12:25 UTC (History)
1 user (show)



Attachments
Sample report generated without calling autoSizeColumn (84.50 KB, application/vnd.ms-excel)
2008-07-01 17:10 UTC, Partha
Details
Excel Report Generator which is used to create the attached sample excel file (29.08 KB, text/java)
2008-07-01 17:11 UTC, Partha
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Partha 2008-07-01 17:09:21 UTC
Attached the ExcelReportGenerator.java
1) If I do NOT call the autoSizeColumn method, then I am able to get the excel report. Attached the excel report without calling autoSizeColumn method.

2) When I call the autoSizeColumn method, I get the below output and exception.

formatFontCount =5
columnValueStyles.length =25
column Count = 25
called autoSizeColumn for the following values of i
 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.Vector.get(Vector.java:712)
	at org.apache.poi.hssf.usermodel.HSSFDataFormat.getFormat(HSSFDataFormat.java:266)
	at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1815)
	at com.jbhunt.report.generator.ExcelReportGenerator.setAutoColumnWidths(ExcelReportGenerator.java:457)
	at com.jbhunt.report.generator.ExcelReportGenerator.generateHSSFWorkbook(ExcelReportGenerator.java:110)
	at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:65) 	at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:59)
	at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635)
	at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338)
	at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29)
14540 [main] ERROR service.GenerateReportSvc  - Error in generate Excel report.
com.jbhunt.report.exception.ReportServiceException: Error in generate Excel report.
	at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:70)
	at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:59)
	at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635)
	at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338)
	at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.Vector.get(Vector.java:712)
	at org.apache.poi.hssf.usermodel.HSSFDataFormat.getFormat(HSSFDataFormat.java:266)
	at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1815)
	at com.jbhunt.report.generator.ExcelReportGenerator.setAutoColumnWidths(ExcelReportGenerator.java:457)
	at com.jbhunt.report.generator.ExcelReportGenerator.generateHSSFWorkbook(ExcelReportGenerator.java:110)
	at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:65)
	... 4 more
com.jbhunt.report.exception.ReportServiceException: Error in generate Excel report.
	at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:70)
	at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:59)
	at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635)
	at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338)
	at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29)
Caused by: java.lang.ArrayIndexOutOfBoundsException: -1
	at java.util.Vector.get(Vector.java:712)
	at org.apache.poi.hssf.usermodel.HSSFDataFormat.getFormat(HSSFDataFormat.java:266)
	at org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1815)
	at com.jbhunt.report.generator.ExcelReportGenerator.setAutoColumnWidths(ExcelReportGenerator.java:457)
	at com.jbhunt.report.generator.ExcelReportGenerator.generateHSSFWorkbook(ExcelReportGenerator.java:110)
	at com.jbhunt.report.generator.ExcelReportGenerator.generateReport(ExcelReportGenerator.java:65)
	... 4 more
Exception in thread "main" com.jbhunt.report.exception.ReportServiceException: Error in generate Excel report.
	at com.jbhunt.report.service.GenerateReportSvc.generateReport(GenerateReportSvc.java:65)
	at com.jbhunt.pace.biz.reports.ReportHandler.getReportUsingCustomJavaAPI(ReportHandler.java:635)
	at com.jbhunt.pace.biz.reports.ejb.ReportsBean.getReportUsingCustomJavaAPI(ReportsBean.java:338)
	at com.jbhunt.pace.biz.reports.test.CustomJavaReportTest.main(CustomJavaReportTest.java:29)
Comment 1 Partha 2008-07-01 17:10:46 UTC
Created attachment 22205 [details]
Sample report generated without calling autoSizeColumn
Comment 2 Partha 2008-07-01 17:11:39 UTC
Created attachment 22206 [details]
Excel Report Generator which is used to create the attached sample excel file
Comment 3 Partha 2008-07-01 17:18:13 UTC
First, I was using POI-3.1 beta-2 version.
Then, tried with POI-3.1 Final Version.
I get the same ArrayIndexOutOfBoundException: -1 in both the versions.

I sent the code to Production. It is working fine for some scenario and not working for some other scenarios.
Comment 4 Yegor Kozlov 2008-07-15 11:16:57 UTC
Fixed in r676995.

The method threw ArrayIndexOutOfBoundsException when style.getDataFormat() returned -1. 

Yegor
Comment 5 michael.ramirez 2009-10-28 12:25:46 UTC
FYI: The following line of code was added to bypass the exception:

if ( null != row.getCell(i) && null != row.getCell(i).getCellStyle() && row.getCell(i).getCellStyle().getDataFormat() > -1 )

With that line removed, the exception occurs at:

sheet.autoSizeColumn((short)i);