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
This commit is contained in:
parent
c3235cc745
commit
2ae382b2c9
@ -69,6 +69,7 @@ import org.apache.poi.poifs.filesystem.DocumentEntry;
|
|||||||
import org.apache.poi.poifs.filesystem.Entry;
|
import org.apache.poi.poifs.filesystem.Entry;
|
||||||
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
|
||||||
import org.apache.poi.util.Internal;
|
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();
|
POIFSFileSystem pfs = new POIFSFileSystem();
|
||||||
boolean docWritten = false;
|
boolean docWritten = false;
|
||||||
boolean dataWritten = false;
|
boolean dataWritten = false;
|
||||||
|
boolean objectPoolWritten = false;
|
||||||
boolean tableWritten = false;
|
boolean tableWritten = false;
|
||||||
boolean propertiesWritten = false;
|
boolean propertiesWritten = false;
|
||||||
for ( Iterator<Entry> iter = directory.getEntries(); iter.hasNext(); )
|
for ( Iterator<Entry> iter = directory.getEntries(); iter.hasNext(); )
|
||||||
@ -961,6 +963,14 @@ public final class HWPFDocument extends HWPFDocumentCore
|
|||||||
docWritten = true;
|
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 )
|
else if ( entry.getName().equals( STREAM_TABLE_0 )
|
||||||
|| entry.getName().equals( STREAM_TABLE_1 ) )
|
|| entry.getName().equals( STREAM_TABLE_1 ) )
|
||||||
{
|
{
|
||||||
@ -993,7 +1003,7 @@ public final class HWPFDocument extends HWPFDocumentCore
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
copyNodeRecursively( entry, pfs.getRoot() );
|
POIUtils.copyNodeRecursively( entry, pfs.getRoot() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1008,6 +1018,8 @@ public final class HWPFDocument extends HWPFDocumentCore
|
|||||||
if ( !dataWritten )
|
if ( !dataWritten )
|
||||||
pfs.createDocument( new ByteArrayInputStream( dataBuf ),
|
pfs.createDocument( new ByteArrayInputStream( dataBuf ),
|
||||||
STREAM_DATA );
|
STREAM_DATA );
|
||||||
|
if ( !objectPoolWritten )
|
||||||
|
_objectPool.writeTo( pfs.getRoot() );
|
||||||
|
|
||||||
pfs.writeFilesystem( out );
|
pfs.writeFilesystem( out );
|
||||||
this.directory = pfs.getRoot();
|
this.directory = pfs.getRoot();
|
||||||
|
@ -158,12 +158,14 @@ public abstract class HWPFDocumentCore extends POIDocument
|
|||||||
throw new EncryptedDocumentException("Cannot process encrypted word files!");
|
throw new EncryptedDocumentException("Cannot process encrypted word files!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DirectoryEntry objectPoolEntry;
|
||||||
try {
|
try {
|
||||||
DirectoryEntry objectPoolEntry = (DirectoryEntry) directory
|
objectPoolEntry = (DirectoryEntry) directory
|
||||||
.getEntry(STREAM_OBJECT_POOL);
|
.getEntry(STREAM_OBJECT_POOL);
|
||||||
_objectPool = new ObjectPoolImpl(objectPoolEntry);
|
|
||||||
} catch (FileNotFoundException exc) {
|
} catch (FileNotFoundException exc) {
|
||||||
|
objectPoolEntry = null;
|
||||||
}
|
}
|
||||||
|
_objectPool = new ObjectPoolImpl(objectPoolEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,10 +17,12 @@
|
|||||||
package org.apache.poi.hwpf.usermodel;
|
package org.apache.poi.hwpf.usermodel;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
import org.apache.poi.poifs.filesystem.DirectoryEntry;
|
||||||
import org.apache.poi.poifs.filesystem.Entry;
|
import org.apache.poi.poifs.filesystem.Entry;
|
||||||
import org.apache.poi.util.Internal;
|
import org.apache.poi.util.Internal;
|
||||||
|
import org.apache.poi.util.POIUtils;
|
||||||
|
|
||||||
@Internal
|
@Internal
|
||||||
public class ObjectPoolImpl implements ObjectsPool
|
public class ObjectPoolImpl implements ObjectsPool
|
||||||
@ -47,4 +49,11 @@ public class ObjectPoolImpl implements ObjectsPool
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Internal
|
||||||
|
public void writeTo( DirectoryEntry directoryEntry ) throws IOException
|
||||||
|
{
|
||||||
|
if ( _objectPool != null )
|
||||||
|
POIUtils.copyNodeRecursively( _objectPool, directoryEntry );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ public final class TestWordExtractor extends TestCase {
|
|||||||
* [RESOLVED FIXED] Bug 51686 - Update to POI 3.8 beta 4 causes
|
* [RESOLVED FIXED] Bug 51686 - Update to POI 3.8 beta 4 causes
|
||||||
* ConcurrentModificationException in Tika's OfficeParser
|
* ConcurrentModificationException in Tika's OfficeParser
|
||||||
*/
|
*/
|
||||||
public void testRootEntiesNavigation() throws IOException
|
public void testBug51686() throws IOException
|
||||||
{
|
{
|
||||||
InputStream is = POIDataSamples.getDocumentInstance()
|
InputStream is = POIDataSamples.getDocumentInstance()
|
||||||
.openResourceAsStream( "Bug51686.doc" );
|
.openResourceAsStream( "Bug51686.doc" );
|
||||||
|
Loading…
Reference in New Issue
Block a user