Bug 41761

Summary: [PATCH] NullPointerException in Sheet#serializeIndexRecord
Product: POI Reporter: Julien Aymé <julien.ayme>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: normal Keywords: PatchAvailable
Priority: P2    
Version: 3.0-dev   
Target Milestone: ---   
Hardware: Other   
OS: other   
Attachments: The test case
A patch proposal for the org.apache.poi.hssf.model.Sheet class
A patch proposal for the org.apache.poi.hssf.model.aggregates.RowRecordsAggregate class

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