Bug 58747 - NullPointerException parsing XLSX files generated by openpyxl library
Summary: NullPointerException parsing XLSX files generated by openpyxl library
Status: RESOLVED WORKSFORME
Alias: None
Product: POI
Classification: Unclassified
Component: XSSF (show other bugs)
Version: 3.13-FINAL
Hardware: All All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-12-17 09:59 UTC by Sergio Nalin
Modified: 2016-10-19 08:51 UTC (History)
0 users



Attachments
incriminated XLSX file (8.35 KB, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet)
2015-12-17 09:59 UTC, Sergio Nalin
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Sergio Nalin 2015-12-17 09:59:35 UTC
Created attachment 33356 [details]
incriminated XLSX file

Stacktrace:

java.lang.NullPointerException
	at org.apache.poi.xssf.eventusermodel.XSSFReader$SheetIterator.<init>(XSSFReader.java:202)
	at org.apache.poi.xssf.eventusermodel.XSSFReader$SheetIterator.<init>(XSSFReader.java:170)
	at org.apache.poi.xssf.eventusermodel.XSSFReader.getSheetsData(XSSFReader.java:164)
	at org.apache.poi.xssf.eventusermodel.XSSFReader$getSheetsData$0.call(Unknown Source)


Triggered by getSheetsData() in this code (Groovy):

def container = OPCPackage.open(file)
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container)
XSSFReader reader = new XSSFReader(container)
StylesTable styles = reader.getStylesTable()
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData()

Curious thing is: invoking getStylesTable() *after* getSheetsData() like this below does not trigger the NPE:

def container = OPCPackage.open(file)
ReadOnlySharedStringsTable strings = new ReadOnlySharedStringsTable(container)
XSSFReader reader = new XSSFReader(container)
XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator) reader.getSheetsData()
StylesTable styles = reader.getStylesTable()


Example XLSX file is attached
Comment 1 Nick Burch 2015-12-17 15:05:33 UTC
I've had a go at converting your groovy code into a unit test in r1720588.

One issue - on trunk the unit test passes as-is!

Any chance you could grab release candidate 2 of 3.14 beta 1, and see if it's already fixed for you in that? If not, please let us know what we need to tweak with the unit test to reproduce your issue
Comment 2 Sergio Nalin 2015-12-18 13:33:39 UTC
Tested with 3.14-beta2-20151217.
Still happens.

Here is the stacktrace when using the latest version:

java.lang.NullPointerException
	at org.apache.poi.xssf.eventusermodel.XSSFReader$SheetIterator.<init>(XSSFReader.java:204)
	at org.apache.poi.xssf.eventusermodel.XSSFReader$SheetIterator.<init>(XSSFReader.java:172)
	at org.apache.poi.xssf.eventusermodel.XSSFReader.getSheetsData(XSSFReader.java:166)
	at org.apache.poi.xssf.eventusermodel.XSSFReader$getSheetsData$0.call(Unknown Source)
Comment 3 Sergio Nalin 2015-12-18 13:37:53 UTC
Forgot to add: I'm a bit tied up now, but I'll try to extract the failing code into a simpler unit-test-friendly package
Comment 4 Javen O'Neal 2016-10-19 08:25:38 UTC
The unit test added in r1720588 has been passing on every nightly build since. Please re-open this bug with a failing unit test if you are still getting NPE's from openpyxl-generated files.
Comment 5 Javen O'Neal 2016-10-19 08:51:04 UTC
(In reply to Sergio Nalin from comment #2)
> Tested with 3.14-beta2-20151217.
> java.lang.NullPointerException
> 	at
> org.apache.poi.xssf.eventusermodel.XSSFReader$SheetIterator.
> <init>(XSSFReader.java:204)

Based on the date and line number, either wb is null or wb.getRelationships() is null. Make sure you aren't mixing versions of poi, poi-ooxml, and poi-ooxml-schemas (or the full ooxml-schemas), as that might cause unexpected behavior.

Line 204:  for(PackageRelationship rel : wb.getRelationships()){

https://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java?revision=1715555&view=markup#l196