Bug 35565 - HSSFCell.java: NullPtrExc in getColumnBreaks() when HSSFWorkbook is created from file
Summary: HSSFCell.java: NullPtrExc in getColumnBreaks() when HSSFWorkbook is created f...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 2.5-FINAL
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-30 17:50 UTC by Szilard barany
Modified: 2007-01-16 01:43 UTC (History)
0 users



Attachments
Test Excel file (56.50 KB, application/vnd.ms-excel)
2005-06-30 18:05 UTC, Szilard barany
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Szilard barany 2005-06-30 17:50:37 UTC
The following error occured
  ---------------------------
  Exception in thread main
  java.lang.NullPointerException
        at org.apache.poi.hssf.model.Sheet.getNumColumnBreaks(Sheet.java:2721)
  ---------------------------

in the following code

  ---------------------------
  import java.io.FileInputStream;
  import java.io.IOException;

  import org.apache.poi.hssf.usermodel.HSSFSheet;
  import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  import org.apache.poi.poifs.filesystem.POIFSFileSystem;

  public class GridSetError  {
    public GridSetError( String fileName ) {

      System.out.println( "fileName : " + fileName );
      try {
        POIFSFileSystem pfs = new POIFSFileSystem( new FileInputStream( fileName
) );
        HSSFWorkbook sourceWorkbook = new HSSFWorkbook( pfs );
        HSSFSheet sourceSheet = sourceWorkbook.getSheetAt( 0 );
        System.out.println( sourceSheet.getColumnBreaks() );
      }
      catch( IOException ioE ) {}
    }

    public static void main(String[] args) {
      if( args.length > 0 ) {
        GridSetError gridSetError = new GridSetError( args[0] );
      }
    }
  }
  ---------------------------

Source XLS DOES NOT contain [VERTICALPAGEBREAK] record.

I think, Sheet.getNumColumnBreaks() ( and Sheet.getNumRowBreaks() ) should first
test if Sheet.colBreaks (and Sheet.rowBreaks) is not null and if it is, then
return 0 to HSSFSheet.getColumnBreaks() which would then return empty short[] to
the caller. This would not result in exception.
Comment 1 Avik Sengupta 2005-06-30 17:53:02 UTC
Could you please attach a (stripped down) copy of the sheet that is causing you
this problem?
Comment 2 Szilard barany 2005-06-30 18:05:43 UTC
Created attachment 15564 [details]
Test Excel file
Comment 3 Avik Sengupta 2007-01-16 01:43:16 UTC
Works as of 12Jan2007, Testcase added. 
http://issues.apache.org/bugzilla/show_bug.cgi?id=41366