Apache POI, .getRuns() not returning all Runs
<p>I am developing a software, which is reading in a Word document (XWPF), changing the grammar according to the prior configuration of the user, and writing the modified text back into the document.</p>

<p>To achieve this, I am using Apache POI (3.10). In most cases it works like expected, but there are some rare cases, where it doesn't. </p>

<p>To be more specific, the code is going through the whole document, paragraph by paragraph. My code is changing the content of the paragraphs by setting the text of their runs.</p>

<p>To have a better picture of what I am talking about:</p>

<pre><code>    XWPFDocument oldDoc = document;
    Iterator&lt;XWPFParagraph&gt; iterator = document.getParagraphsIterator();
    int length = title.length();
    int counter = 0;

    while(iterator.hasNext())
    {
        XWPFParagraph paragraph = iterator.next();
        List&lt;XWPFRun&gt; runs = paragraph.getRuns();
        for(int i = 0; i &lt; runs.size(); i++)
        {
            String text = runs.get(i).toString();
            if(text.contains(title)) {
                runs.get(i).setText(StringFunctions.fromMultiFemaleToSingleMale(text, title, length), 0); 
            }
        }

        document.setParagraph(paragraph, counter);
        counter++;
    }
</code></pre>

<p>AS you can see, I take every run of a paragraph, and throw it into my transformation method, and overwrite the text of the run. There is no problem at this point (I think).</p>

<p>My problem is, that there are two or three sentences (or paragraphs), which do not return the whole text in their runs. Below is an example.</p>

<p>paragraph.getText() returns:
<em>Alle Beteiligten weisen daher den Notar gem. § 53 BeurkG an, die Umschreibung gemäß dieser Vollmacht durch Eigenurkunde erst zu veranlassen, nachdem der Verkäufer den Eingang des geschuldeten Betrages originalschriftlich bestätigt haben oder hilfsweise die Käuferinnen die Zahlung des vereinbarten Kaufpreises (jeweils ohne Zinsen) durch</em> <strong>Bankbestätigung nachgewiesen hat.</strong></p>

<p>while the concatenation of paragraph.getRuns() returns: <em>Alle Beteiligten weisen daher den Notar gem. § 53 BeurkG an, die Umschreibung gemäß dieser Vollmacht durch Eigenurkunde erst zu veranlassen, nachdem die Verkäufer den Eingang des geschuldeten Betrages originalschriftlich bestätigt haben oder hilfsweise die Käuferinnen die Zahlung des vereinbarten Kaufpreises (jeweils ohne Zinsen) durch</em></p>

<p>You can see here, that the last three words are missing. Since I am accessing the runs, the last part will just be ignored and never transformed by my method. But in this case I need to transform the last word to make it grammatically correct.</p>

<p>Has anyone experienced something similar?</p>

<p>I tried to find a workaround, but I didn't find one. 
One of my coworkers talked with me about that and mentioned that he experienced something similar, and that sometimes there is something like a flaw in that XML-like structure of Word-documents, with which Word can still work with, but POI not so well. This does not sound very unlikely, since the document, which I am using, was once the old Word format (.doc), and was saved as a .docx with Word 2007.</p>