Bug 51514 - NullPointerExceptions in HSSFWorkbook
Summary: NullPointerExceptions in HSSFWorkbook
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
Depends on:
Reported: 2011-07-15 14:47 UTC by Antoni Mylka
Modified: 2011-07-15 15:19 UTC (History)
0 users

A ZIP file which combines a patch and a test doc. (51.02 KB, application/zip)
2011-07-15 14:47 UTC, Antoni Mylka

Note You need to log in before you can comment on or make changes to this bug.
Description Antoni Mylka 2011-07-15 14:47:13 UTC
Created attachment 27290 [details]
A ZIP file which combines a patch and a test doc.

I noticed two issues, both related to the fact that the NPOIFSFileSystem instance isn't propagated correctly everywhere it should be.

If I create a HSSFWorkbook from an NPoiFileSystem then

1. I get an NPE in HSSFWorkbook.write(OutputStream stream). It's because it passes a POIFSFileSystem to the copyNodesMethod. The reference is null. The code should check which of the filesystem references is not-null and use the correct one.

2. I get NPEs while working with the HSSFObjectData instances obtained from the HSSFWorkbook.getAllEmbeddedObject. This is because they are all created using a constructor which accepts an POIFSFileSystem. If this is null - problems arise.
Comment 1 Nick Burch 2011-07-15 14:52:03 UTC
NPOIFS doesn't currently support writing. Doesn't matter if you pass the NPOIFS instance along into the write method, it won't help - you can't currently write out

Once we've finished the NPOIFS write support, we'll then need to tweak how HSSF does writing

The object data is reading so should be fixed, will look into that
Comment 2 Nick Burch 2011-07-15 15:19:38 UTC
Looks like we can fix both easily by just using the DirectoryNode roots, rather than passing in the POIFSFileSystem and immediately getting the root

Fixed in r1147179 and r1147183

I've applied your test, with some changes in r1147188, thanks for that!