Bug 36956 - NullPointerException trying to place a page break
Summary: NullPointerException trying to place a page break
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: PC Windows XP
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2005-10-06 21:45 UTC by Alex Savitsky
Modified: 2006-01-12 18:24 UTC (History)
0 users


Note You need to log in before you can comment on or make changes to this bug.
Description Alex Savitsky 2005-10-06 21:45:04 UTC
This error only happens when trying to insert page break in an existing 
workbook, like in

HSSFWorkbook book = new HSSFWorkbook(new FileInputStream(existingFileName));
HSSFSheet sheet = book.getSheetAt(0);

When doing same thing with a new workbook, it works:

HSSFWorkbook book = new HSSFWorkbook();
HSSFSheet sheet = book.createSheet("Test");

The reason is that the rowBreaks property of Sheet is only initialized for new 
sheets (the createSheet() call). If an existing sheet (createSheet(List, int, 
int) call) doesn't have any records for page breaks, then rowBreaks doesn't 
get initialized, resulting in an NPE.

Possible resolution: either initialize rowBreaks during createSheet call, or 
do a null check in setRowBreak()
Comment 1 Jason Height 2006-01-13 03:24:00 UTC
This appears to be fixed in the code in SVN. see code block below from Sheet:

			else if (rec.getSid() == PageBreakRecord.HORIZONTAL_SID) 
				retval.rowBreaks = (PageBreakRecord)rec;				
			else if (rec.getSid() == PageBreakRecord.VERTICAL_SID) 
				retval.colBreaks = (PageBreakRecord)rec;