Bug 27496 - HSSFSheet#getRowBreaks() raises NPE with a brand-new workbook
Summary: HSSFSheet#getRowBreaks() raises NPE with a brand-new workbook
Status: VERIFIED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.0-dev
Hardware: PC All
: P3 normal with 4 votes (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-03-06 17:13 UTC by IRIE Hironori
Modified: 2007-09-13 07:44 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description IRIE Hironori 2004-03-06 17:13:11 UTC
I tried page break feature of POI-2.5-FINAL, and got trouble.
I create a new workbook file with Excel and call HSSFSheet#getRowBreaks(), then 
it raises NullPointerException.

(1) create a new workbook file (three sheets and no data) with Excel.
I tried with Excel 2000 and XP.
(2) create HSSFWorkbook instance for (1)'s workbook.
(3) call workbook.getSheetAt() to get sheet.
(4) call sheet.getRowBreaks(). It raises NPE.

Environments:
  Windows2000
  J2SE 1.4.2_03
  MS Excel2000
  POI-2.5-FINAL


Here is the stack trace.
---
java.lang.NullPointerException
	at org.apache.poi.hssf.model.Sheet.getNumRowBreaks(Sheet.java:2764)
	at org.apache.poi.hssf.usermodel.HSSFSheet.getRowBreaks(HSSFSheet.java:
1144)
	at POISample.handleSheet(POISample.java:41)
	at POISample.main(POISample.java:26)
Exception in thread "main" 
---

and sample code
---
public class POISample
{

  public static void main(final String[] args)
    throws Exception
  {
    final HSSFWorkbook book = new HSSFWorkbook(new FileInputStream(args[0]));
    POISample.handleSheet(book.getSheetAt(0));
    book.write(new FileOutputStream(args[1]));
  }

  private static void handleSheet(final HSSFSheet sheet)
  {
    for (int i = 0; i < 5; ++i)
    {
      final HSSFRow row = sheet.createRow(i);
      for (short j = 0; j < 5; ++j)
      {
        final HSSFCell cell = row.createCell(j);
        cell.setCellValue(i + ":" + j);
      }
    }
    final int[] breaks = sheet.getRowBreaks();
    sheet.setRowBreak(1);
  }

}
---

Additionally, in some cases i succeeded calling getRowBreaks().
If the sheet already has some page breaks, or the sheet is created with 
HSSFWorkbook#createSheet(), it succeeds.

kind regards.

IRIE Hironori
Comment 1 Jan-Martin Roth 2004-06-03 13:02:34 UTC
I'm getting a very similar problem with POI2.5-final when using
HSSFSheet.setRowBreak(int). NPE if the workbook has not already RowBreaks.
My workaround: As I use a template originally without RowBreaks I introduce a
temporary RowBreaks into the template which I then delete from the application
(using getRowBreaks()) and after this I put the real RowBreaks at the lines they
should go.
Jan-Martin Roth (jmroth@mtg.de)
Comment 2 Jason Height 2006-09-08 21:06:56 UTC
fixed in SVN

Jason
Comment 3 IRIE Hironori 2007-09-13 07:44:09 UTC
I'm so sorry for my late verification.
I checked with POI 3.0.1 and worked collect.