Bug 51671 - HWPFDocument.write based on NPOIFSFileSystem throws a NullPointerException
Summary: HWPFDocument.write based on NPOIFSFileSystem throws a NullPointerException
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HWPF (show other bugs)
Version: 3.8-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-17 11:52 UTC by Antoni Mylka
Modified: 2011-08-17 14:54 UTC (History)
0 users



Attachments
A patch which adds the if (pfs==null) check (2.16 KB, patch)
2011-08-17 12:03 UTC, Antoni Mylka
Details | Diff
a test doc, to be placed in test-data/document (71.50 KB, application/msword)
2011-08-17 12:04 UTC, Antoni Mylka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Antoni Mylka 2011-08-17 11:52:39 UTC
I do this:

InputStream st = ... // stream with the doc file
NPOIFSFileSystem fs = new NPOIFSFileSystem(st);
HWPFDocument doc = new HWPFDocument(fs.getRoot());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
doc.write(baos);

I get this:

java.lang.NullPointerException
	at org.apache.poi.hwpf.HWPFDocument.deleteEntrySafe(HWPFDocument.java:980)
	at org.apache.poi.hwpf.HWPFDocument.write(HWPFDocument.java:951)
...

It seems that the HWPFDocument.write relies on the fact that directory.getFileSystem() will return a non-null object. Unfortunately, when using the NPOIFSFileSystem, this is not the case. A workaround would be to add a 
	
if (pfs == null) {
    pfs = new POIFSFileSystem();
}

This seems to work for me.
Comment 1 Antoni Mylka 2011-08-17 12:03:27 UTC
Created attachment 27396 [details]
A patch which adds the if (pfs==null) check
Comment 2 Antoni Mylka 2011-08-17 12:04:02 UTC
Created attachment 27397 [details]
a test doc, to be placed in test-data/document
Comment 3 Sergey Vladimirov 2011-08-17 14:54:06 UTC
Fixed by using new file system, not existing one.