]> source.dussan.org Git - poi.git/commitdiff
fixed WordExtractor to avoid ArrayIndexOutOfBoundsException when encountering empty...
authorYegor Kozlov <yegor@apache.org>
Sat, 18 Jul 2009 10:03:01 +0000 (10:03 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 18 Jul 2009 10:03:01 +0000 (10:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@795333 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hwpf/extractor/WordExtractor.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/Range.java

index 10ac954263e0036a7b61ea565759aac32017c1fc..b4308af39905cf167f69ebdb9c80c6d9d20236f7 100644 (file)
@@ -23,6 +23,7 @@ import java.io.FileInputStream;
 import java.io.UnsupportedEncodingException;
 import java.util.Iterator;
 import java.util.Arrays;
+import java.util.ArrayList;
 
 import org.apache.poi.POIOLE2TextExtractor;
 import org.apache.poi.hwpf.HWPFDocument;
@@ -252,9 +253,13 @@ public final class WordExtractor extends POIOLE2TextExtractor {
 
                ret.append(getHeaderText());
 
-               String[] text = getParagraphText();
-               for(int i=0; i<text.length; i++) {
-                       ret.append(text[i]);
+                ArrayList<String> text = new ArrayList<String>();
+                text.addAll(Arrays.asList(getParagraphText()));
+                text.addAll(Arrays.asList(getFootnoteText()));
+                text.addAll(Arrays.asList(getEndnoteText()));
+
+               for(String p : text) {
+                       ret.append(p);
                }
 
                ret.append(getFooterText());
index eb97077e832effa136713fd0710065daba931d61..a6fe3fdf4af448393cea6ed44d3ec9318209c054 100644 (file)
@@ -978,6 +978,10 @@ public class Range { // TODO -instantiable superclass
       node = (PropertyNode)rpl.get(x);
     }
 
+    if (node.getEnd() <= start) {
+        return new int[] {rpl.size(), rpl.size()};
+    }
+
     int y = x;
     node = (PropertyNode)rpl.get(y);
     while(node.getEnd() < end && y < rpl.size()-1)