Bug 52348 - XSSFWorkbook#createCellStyle() fails with ArrayIndexOutOfBoundsException
Summary: XSSFWorkbook#createCellStyle() fails with ArrayIndexOutOfBoundsException
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-16 20:42 UTC by nestor.urquiza
Modified: 2012-01-03 18:44 UTC (History)
0 users



Attachments
5 files showing the issue (19.18 KB, application/zip)
2011-12-16 20:42 UTC, nestor.urquiza
Details
two screenshots showing how the second style of the merged sheet gets messed up (42.87 KB, application/zip)
2012-01-03 18:44 UTC, nestor.urquiza
Details

Note You need to log in before you can comment on or make changes to this bug.
Description nestor.urquiza 2011-12-16 20:42:05 UTC
Created attachment 28079 [details]
5 files showing the issue

This is a bug resulting from a discussion on the mailing list http://apache-poi.1045710.n5.nabble.com/XSSFWorkbook-createCellStyle-fails-with-ArrayIndexOutOfBoundsException-td5033683.html

I am attaching 5 files (two input xlsx files with the output xlsx you can obtain yourself if you run the JUnit class that uses the Util class). One is a util class that should allow me to merge two XLSX books and the other a JUnit test that cannot run and creates an output file where the style for the second sheet is missing.

Look for the below lines and uncomment the code in the Util class then run the test again. The Exception will be thrown:

//BUG: The below produces:
                    /*
                    java.lang.ArrayIndexOutOfBoundsException: -1
                    at java.util.ArrayList.get(ArrayList.java:324)
                    at org.apache.poi.xssf.model.StylesTable.getCellStyleXfAt(StylesTable.java:305)
                    at org.apache.poi.xssf.usermodel.XSSFCellStyle.<init>(XSSFCellStyle.java:79)
                    at org.apache.poi.xssf.model.StylesTable.createCellStyle(StylesTable.java:521)
                    at org.apache.poi.xssf.usermodel.XSSFWorkbook.createCellStyle(XSSFWorkbook.java:443)
                    */
                    //newCellStyle = newCell.getSheet().getWorkbook().createCellStyle();
                    //newCellStyle.cloneStyleFrom(oldCell.getCellStyle());
                    //styleMap.put(stHashCode, newCellStyle);

Thanks!
-Nestor
Comment 1 Nick Burch 2011-12-17 10:45:44 UTC
Are you able to unpack one of the problematic files (.xlsx files are a zip of xml files), and see if there's anything obviously different in the styles file between one that works and one that doesn't?

For a problem file, does adding or removing styles in excel fix things?
Comment 2 Yegor Kozlov 2011-12-19 08:47:42 UTC
I confirmed the problem in trunk. 

The simplest failing test case is:

XSSFWorkbook targetWorkbook = new XSSFWorkbook(new FileInputStream("balance.xlsx"));
XSSFCellStyle style = targetWorkbook.createCellStyle();

Somehow appending a new cell style to balance.xlsx results in exception. 

Yegor
Comment 3 Yegor Kozlov 2011-12-19 09:06:38 UTC
Fixed in r1220659, junit added

Yegor
Comment 4 nestor.urquiza 2012-01-03 18:44:16 UTC
Created attachment 28118 [details]
two screenshots showing how the second style of the merged sheet gets messed up

Hi Yegor,

First, Happy and healthy 2012! 

Thanks for looking at this issue. I can confirm the exception is not longer generated however the style for the second document is not respected after the merge. If you run my JUnit test you can confirm so but in any case I am attaching the screenshots for you to have a quick look at what is currently happening.

Thanks!
-Nestor