Author: maxcom
Date: Mon Aug 22 07:56:43 2011
New Revision: 1160137

URL: http://svn.apache.org/viewvc?rev=1160137&view=rev
Log:
bug#51686 - ConcurrentModificationException in Tika's OfficeParser

Added:
    poi/trunk/test-data/document/testWORD.doc   (with props)
Modified:
    poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
    
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java

Modified: poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java?rev=1160137&r1=1160136&r2=1160137&view=diff
==============================================================================
--- poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java 
(original)
+++ poi/trunk/src/scratchpad/src/org/apache/poi/hwpf/HWPFDocumentCore.java Mon 
Aug 22 07:56:43 2011
@@ -141,41 +141,32 @@ public abstract class HWPFDocumentCore e
    * @throws IOException If there is an unexpected IOException from the passed
    *         in POIFSFileSystem.
    */
-  public HWPFDocumentCore(DirectoryNode directory) throws IOException
-  {
+  public HWPFDocumentCore(DirectoryNode directory) throws IOException {
     // Sort out the hpsf properties
-       super(directory);
+    super(directory);
 
     // read in the main stream.
     DocumentEntry documentProps = (DocumentEntry)
-       directory.getEntry("WordDocument");
+            directory.getEntry("WordDocument");
     _mainStream = new byte[documentProps.getSize()];
 
     
directory.createDocumentInputStream(STREAM_WORD_DOCUMENT).read(_mainStream);
 
     // Create our FIB, and check for the doc being encrypted
     _fib = new FileInformationBlock(_mainStream);
-    if(_fib.isFEncrypted()) {
-       throw new EncryptedDocumentException("Cannot process encrypted word 
files!");
+    if (_fib.isFEncrypted()) {
+      throw new EncryptedDocumentException("Cannot process encrypted word 
files!");
     }
 
-        {
-            DirectoryEntry objectPoolEntry;
-            try
-            {
-                objectPoolEntry = (DirectoryEntry) directory
-                        .getEntry( STREAM_OBJECT_POOL );
-            }
-            catch ( FileNotFoundException exc )
-            {
-                objectPoolEntry = directory
-                        .createDirectory( STREAM_OBJECT_POOL );
-            }
-            _objectPool = new ObjectPoolImpl( objectPoolEntry );
-        }
+    try {
+      DirectoryEntry objectPoolEntry = (DirectoryEntry) directory
+              .getEntry(STREAM_OBJECT_POOL);
+      _objectPool = new ObjectPoolImpl(objectPoolEntry);
+    } catch (FileNotFoundException exc) {
     }
+  }
 
-    /**
+  /**
      * Returns the range which covers the whole of the document, but excludes
      * any headers and footers.
      */

Modified: 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java?rev=1160137&r1=1160136&r2=1160137&view=diff
==============================================================================
--- 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
 (original)
+++ 
poi/trunk/src/scratchpad/testcases/org/apache/poi/hwpf/extractor/TestWordExtractor.java
 Mon Aug 22 07:56:43 2011
@@ -24,9 +24,13 @@ import org.apache.poi.hwpf.HWPFDocument;
 import org.apache.poi.hwpf.HWPFTestDataSamples;
 import org.apache.poi.hwpf.OldWordFileFormatException;
 import org.apache.poi.poifs.filesystem.DirectoryNode;
+import org.apache.poi.poifs.filesystem.Entry;
 import org.apache.poi.poifs.filesystem.NPOIFSFileSystem;
 import org.apache.poi.poifs.filesystem.POIFSFileSystem;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 /**
  * Test the different routes to extracting text
  *
@@ -353,4 +357,21 @@ public final class TestWordExtractor ext
           assertEquals(p_text1_block, extractor.getText());
        }
     }
+
+    public void testRootEntiesNavigation() throws IOException {
+        InputStream is = 
POIDataSamples.getDocumentInstance().openResourceAsStream("testWORD.doc");
+
+        POIFSFileSystem fs = new POIFSFileSystem(is);
+
+        String text = null;
+
+        for (Entry entry : fs.getRoot()) {
+            if ("WordDocument".equals(entry.getName())) {
+                WordExtractor ex = new WordExtractor(fs);
+                text = ex.getText();
+            }
+        }
+
+        assertNotNull(text);
+    }
 }

Added: poi/trunk/test-data/document/testWORD.doc
URL: 
http://svn.apache.org/viewvc/poi/trunk/test-data/document/testWORD.doc?rev=1160137&view=auto
==============================================================================
Binary file - no diff available.

Propchange: poi/trunk/test-data/document/testWORD.doc
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to