Bug 51094 - HWPFDocument.write() does not preserve all embedded documents
Summary: HWPFDocument.write() does not preserve all embedded documents
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
Depends on:
Reported: 2011-04-20 09:35 UTC by Igor Rogov
Modified: 2016-02-14 18:42 UTC (History)
0 users

Test document (37.50 KB, application/msword)
2011-04-20 09:35 UTC, Igor Rogov

Note You need to log in before you can comment on or make changes to this bug.
Description Igor Rogov 2011-04-20 09:35:02 UTC
Created attachment 26916 [details]
Test document

When I'm trying to write a Word document it does not preserve an embedded entries. Attached test document. It's a Word document with another Word document embedded. Here is a code to reproduce the issue:

String testdoc = "881-test-embedded.doc";
String testdocout = "out.doc";
POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(new File(testdoc)));

HWPFDocument doc = new HWPFDocument(fs);
FileOutputStream out = new FileOutputStream(new File(testdocout));

The resulting file "out.doc" does not contain embedded document. Is this a bug or expected behavior?
Comment 1 Nick Burch 2011-04-20 10:14:13 UTC
Looking at the HWPF write code, I can see that there's nothing there to copy the embedded documents over

Short term, the fix would be to do something similar to in HSSF, where we copy the extra entries over if a flag is set

Longer term, if we switch it from POIFSFileSystem to NPOIFSFileSystem then we can just overwrite the word streams with the new data, and keep all the other ones, which'd probably be a cleaner fix
Comment 2 Nick Burch 2011-04-20 10:16:15 UTC
As a workaround for now, you could manually copy the ObjectPool over. A patch to do this properly (along with a unit test) would be very well received!
Comment 3 Sergey Vladimirov 2011-10-30 00:08:11 UTC
Shall be fixed already, please check
Comment 4 Dominik Stadler 2016-02-14 18:42:53 UTC
No update for a long time, therefore I am closing this, please reopen with more information if this is still a problem for you.