Bug 41761 - [PATCH] NullPointerException in Sheet#serializeIndexRecord
Summary: [PATCH] NullPointerException in Sheet#serializeIndexRecord
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: PatchAvailable
Depends on:
Blocks:
 
Reported: 2007-03-05 01:53 UTC by Julien Aymé
Modified: 2007-03-20 08:01 UTC (History)
0 users



Attachments
The test case (475 bytes, text/plain)
2007-03-05 01:55 UTC, Julien Aymé
Details
A patch proposal for the org.apache.poi.hssf.model.Sheet class (718 bytes, patch)
2007-03-05 02:01 UTC, Julien Aymé
Details | Diff
A patch proposal for the org.apache.poi.hssf.model.aggregates.RowRecordsAggregate class (698 bytes, patch)
2007-03-05 02:09 UTC, Julien Aymé
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Aymé 2007-03-05 01:53:56 UTC
When writing a HSSFWorkbook containing a HSSFSheet with an empty HSSFRow (ie. a
row with no cells), a NPE is thrown:

The Sample Code:
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet();
sheet.createRow(0);
workbook.write(new ByteArrayOutputStream());


The StackTrace:
java.lang.NullPointerException
	at org.apache.poi.hssf.model.Sheet.serializeIndexRecord(Sheet.java:787)
	at org.apache.poi.hssf.model.Sheet.serialize(Sheet.java:731)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:963)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:901)
	at org.apache.poi.hssf.model.MyTestSheet.test(MyTestSheet.java:16)
	...
Comment 1 Julien Aymé 2007-03-05 01:55:06 UTC
Created attachment 19662 [details]
The test case

The test case file
Comment 2 Julien Aymé 2007-03-05 02:01:40 UTC
Created attachment 19665 [details]
A patch proposal for the org.apache.poi.hssf.model.Sheet class

I am not sure that 0 for a null cells is a good default value.
Comment 3 Julien Aymé 2007-03-05 02:04:16 UTC
Whoops, it seems that with my patch, another NPE occurs whith the same test
case, but in RowRecordsAggregate.serialize:

The StackTrace
java.lang.NullPointerException
	at
org.apache.poi.hssf.record.aggregates.RowRecordsAggregate.serialize(RowRecordsAggregate.java:216)
	at org.apache.poi.hssf.model.Sheet.serialize(Sheet.java:719)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.getBytes(HSSFWorkbook.java:963)
	at org.apache.poi.hssf.usermodel.HSSFWorkbook.write(HSSFWorkbook.java:901)
	at org.apache.poi.hssf.model.MyTestSheet.test(MyTestSheet.java:16)
	...
Comment 4 Julien Aymé 2007-03-05 02:09:10 UTC
Created attachment 19666 [details]
A patch proposal for the org.apache.poi.hssf.model.aggregates.RowRecordsAggregate class

I just added a check for null value.
Comment 5 Julien Aymé 2007-03-05 02:18:16 UTC
Apparently, the binary file generated is "good", ie. I can open it without any
error being thrown in Excel.
Comment 6 Yegor Kozlov 2007-03-20 08:01:13 UTC
Julien,

patch applied.
Thanks a lot for it.

Regards,
Yegor