aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSergey Vladimirov <sergey@apache.org>2011-08-22 08:55:21 +0000
committerSergey Vladimirov <sergey@apache.org>2011-08-22 08:55:21 +0000
commit12e99187591d76bf3e47bc2848fec136d9087c22 (patch)
tree3f24e44f0256a7bd2fcfb7c20728c48aa1a2ee1e
parentfff84f00eedabad5c2d168f29cf954f94ed36982 (diff)
downloadpoi-12e99187591d76bf3e47bc2848fec136d9087c22.tar.gz
poi-12e99187591d76bf3e47bc2848fec136d9087c22.zip
refix 51686 - fix possible NPE, add writeTo() to ObjectPoolImpl.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1160152 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java14
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java6
-rw-r--r--src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java9
-rw-r--r--src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java2
4 files changed, 27 insertions, 4 deletions
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
index fc979f46d9..99ab39c9ac 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocument.java
@@ -69,6 +69,7 @@ import org.apache.poi.poifs.filesystem.DocumentEntry;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.POIUtils;
/**
@@ -947,6 +948,7 @@ public final class HWPFDocument extends HWPFDocumentCore
POIFSFileSystem pfs = new POIFSFileSystem();
boolean docWritten = false;
boolean dataWritten = false;
+ boolean objectPoolWritten = false;
boolean tableWritten = false;
boolean propertiesWritten = false;
for ( Iterator<Entry> iter = directory.getEntries(); iter.hasNext(); )
@@ -961,6 +963,14 @@ public final class HWPFDocument extends HWPFDocumentCore
docWritten = true;
}
}
+ else if ( entry.getName().equals( STREAM_OBJECT_POOL ) )
+ {
+ if ( !objectPoolWritten )
+ {
+ _objectPool.writeTo( pfs.getRoot() );
+ objectPoolWritten = true;
+ }
+ }
else if ( entry.getName().equals( STREAM_TABLE_0 )
|| entry.getName().equals( STREAM_TABLE_1 ) )
{
@@ -993,7 +1003,7 @@ public final class HWPFDocument extends HWPFDocumentCore
}
else
{
- copyNodeRecursively( entry, pfs.getRoot() );
+ POIUtils.copyNodeRecursively( entry, pfs.getRoot() );
}
}
@@ -1008,6 +1018,8 @@ public final class HWPFDocument extends HWPFDocumentCore
if ( !dataWritten )
pfs.createDocument( new ByteArrayInputStream( dataBuf ),
STREAM_DATA );
+ if ( !objectPoolWritten )
+ _objectPool.writeTo( pfs.getRoot() );
pfs.writeFilesystem( out );
this.directory = pfs.getRoot();
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
index d67588dc08..4779cad53e 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
@@ -158,12 +158,14 @@ public abstract class HWPFDocumentCore extends POIDocument
throw new EncryptedDocumentException("Cannot process encrypted word files!");
}
+ DirectoryEntry objectPoolEntry;
try {
- DirectoryEntry objectPoolEntry = (DirectoryEntry) directory
+ objectPoolEntry = (DirectoryEntry) directory
.getEntry(STREAM_OBJECT_POOL);
- _objectPool = new ObjectPoolImpl(objectPoolEntry);
} catch (FileNotFoundException exc) {
+ objectPoolEntry = null;
}
+ _objectPool = new ObjectPoolImpl(objectPoolEntry);
}
/**
diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java
index 2241f9644b..aa33fd504c 100644
--- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java
+++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/ObjectPoolImpl.java
@@ -17,10 +17,12 @@
package org.apache.poi.hwpf.usermodel;
import java.io.FileNotFoundException;
+import java.io.IOException;
import org.apache.poi.poifs.filesystem.DirectoryEntry;
import org.apache.poi.poifs.filesystem.Entry;
import org.apache.poi.util.Internal;
+import org.apache.poi.util.POIUtils;
@Internal
public class ObjectPoolImpl implements ObjectsPool
@@ -47,4 +49,11 @@ public class ObjectPoolImpl implements ObjectsPool
return null;
}
}
+
+ @Internal
+ public void writeTo( DirectoryEntry directoryEntry ) throws IOException
+ {
+ if ( _objectPool != null )
+ POIUtils.copyNodeRecursively( _objectPool, directoryEntry );
+ }
}
diff --git a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
index 2f7a2d5771..b10076c815 100644
--- a/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
+++ b/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
@@ -362,7 +362,7 @@ public final class TestWordExtractor extends TestCase {
* [RESOLVED FIXED] Bug 51686 - Update to POI 3.8 beta 4 causes
* ConcurrentModificationException in Tika's OfficeParser
*/
- public void testRootEntiesNavigation() throws IOException
+ public void testBug51686() throws IOException
{
InputStream is = POIDataSamples.getDocumentInstance()
.openResourceAsStream( "Bug51686.doc" );