Bug 39634 - HSSFWorkbook throwing intermittent exception on write()
Summary: HSSFWorkbook throwing intermittent exception on write()
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.0-dev
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-05-22 23:22 UTC by ck
Modified: 2008-05-17 06:27 UTC (History)
0 users



Attachments
ValueRecordsAggregate.java svn diff (1.34 KB, text/x-patch)
2006-05-22 23:27 UTC, ck
Details
Sample Excel Workbook which leads to error when written. (67.00 KB, application/vnd.ms-excel)
2006-12-12 15:18 UTC, Chris
Details

Note You need to log in before you can comment on or make changes to this bug.
Description ck 2006-05-22 23:22:02 UTC
Here's the stack trace:

java.lang.ArrayIndexOutOfBoundsException: 60
        at
org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate.rowHasCells(ValueRecordsAggregate.java:195)
        at org.apache.poi.hssf.model.Sheet.getSize(Sheet.java:2112)
        at
org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:920)
        at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:875)


Issue seems to be lines 193-194 in
org.apache.poi.hssf.record.aggregates.ValueRecordsAggregate (SVN 408776):

    	if (row > records.length)
    		return false;

Which seems like it should be

    	if (row >= records.length)
    		return false;

That's just a quick guess, from a very cursory look at the code.
Comment 1 ck 2006-05-22 23:23:45 UTC
actually, fixing that threw more null pointers.  Seems a bit odd, since I've run
this code hundreds of times before with no trouble.  In any case, the problems I
ran into after the first fix all had to do with the MyIterator inner class in
the same ValueRecordsAggregator class.  I'll attach a diff that seems to have
resolved the problem.
Comment 2 ck 2006-05-22 23:27:47 UTC
Created attachment 18331 [details]
ValueRecordsAggregate.java svn diff
Comment 3 Jason Height 2006-08-15 01:24:51 UTC
I am very reluctant to apply this patch without further investigation. Can you
provide a sample piece of code or an excel workbook which when written out
displays  the error.

I have never come across this, and since i wrote that piece of code would like
to feel confident that it is the problem ;-) (rather than another related piece
of code)

Jason
Comment 4 ck 2006-08-15 02:44:19 UTC
Your request makes perfect sense, I wish I was prudent enough to include the
test case back when I filed it.  I've been running the patched code in
production now for close to three months, and I can't recall exactly what was
causing it.  I'll have to do some digging around- I'll get back to you...
Comment 5 Chris 2006-12-12 15:15:12 UTC
I also have this problem.  The patch from CK seems to correct it.  Thanks.

I'll attach an excel workbook which when written leads to the error.  I used the
 sample code below for testing.

Chris


import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;

public class ExcelTest
{
    public static void main(String[] args) throws Exception
    {
	InputStream inputStream = new FileInputStream(new File(args[0]));
	OutputStream outputStream = new FileOutputStream(new File(args[1]));
	POIFSFileSystem fileSystem = new POIFSFileSystem(inputStream);
	HSSFWorkbook workbook = new HSSFWorkbook(fileSystem);
	workbook.write(outputStream);
    }
}
Comment 6 Chris 2006-12-12 15:18:24 UTC
Created attachment 19251 [details]
Sample Excel Workbook which leads to error when written.
Comment 7 Yegor Kozlov 2008-05-17 06:27:59 UTC
The problem seems to be fixed in poi-3.1-beta2.

Yegor