Bug 54607 - NPE in XSSFSheet.getTopRow() when the top row is 1
Summary: NPE in XSSFSheet.getTopRow() when the top row is 1
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.9-FINAL
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-25 08:45 UTC by Nikola Štohanzl
Modified: 2013-06-17 11:45 UTC (History)
1 user (show)



Attachments
trivial test case, created in Excel 2010 (8.33 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2013-02-25 08:45 UTC, Nikola Štohanzl
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nikola Štohanzl 2013-02-25 08:45:08 UTC
Created attachment 29988 [details]
trivial test case, created in Excel 2010

Exception in thread "main" java.lang.NullPointerException
	at org.apache.poi.ss.util.CellReference.<init>(CellReference.java:88)
	at org.apache.poi.xssf.usermodel.XSSFSheet.getTopRow(XSSFSheet.java:1181)
	at poi.ReadTest.main(ReadTest.java:22)

for the second sheet (note the first visible row of first sheet is 2). File is created in Excel 2010, saving it in xls format (Excel 97-2003) solves the issue.

To reproduce:

Workbook wb = WorkbookFactory.create(new File("c:/0/xxx.xlsx"));
for (int si = 0; si < wb.getNumberOfSheets(); si++) {
	Sheet sh = wb.getSheetAt(si);
	System.out.println(sh.getSheetName() + "/" + sh.getTopRow());
}
Comment 1 Dominik Stadler 2013-05-30 08:44:45 UTC
It seems POI expects that sheets do have an attribute like this in sheetX.xml:
    topLeftCell="A2" 

However for your test-example, there is no such entry in sheet2.xml, seems the attribute is only there if a non-default top-row is set, but poi does not expect that. Other test-examples also don't have the attribute, seems a simple null check is missing.

BTW, the same applies for getLeftCol() for XSSF/SXSSF.
Comment 2 Dominik Stadler 2013-06-17 11:45:44 UTC
Fixed with SVN r1493686

        M       src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java
        M       src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFSheet.java
        A       test-data/spreadsheet/54607.xlsx

Added a null-check as well as test-cases covering these changes.