]> source.dussan.org Git - poi.git/commitdiff
#57829 Avoid XmlValueDisconnectedException when removing a XWPFRun from a XWPFParagra...
authorNick Burch <nick@apache.org>
Fri, 24 Apr 2015 01:29:10 +0000 (01:29 +0000)
committerNick Burch <nick@apache.org>
Fri, 24 Apr 2015 01:29:10 +0000 (01:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1675738 13f79535-47bb-0310-9956-ffa450edef68

src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java
src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java

index 7ed629c10a6d1d5b54a41c3aa6ed30ea9b5c456d..c98143a5aec420be47686955e938a345034c3ace 100644 (file)
@@ -1369,8 +1369,12 @@ public class XWPFParagraph implements IBodyElement, IRunBody, ISDTContents, Para
      */
     public boolean removeRun(int pos){
         if (pos >= 0 && pos < paragraph.sizeOfRArray()) {
-            getCTP().removeR(pos);
+            // Remove the run from our high level lists
+            XWPFRun run = runs.get(pos);
             runs.remove(pos);
+            iruns.remove(run);
+            // Remove the run from the low-level XML
+            getCTP().removeR(pos);
             return true;
         }
         return false;
index 053b611e3c12c3b459410f269130a96e61298b6f..8fd7f97e04087bf0998d82488f987549215baa75 100644 (file)
@@ -88,4 +88,19 @@ public class TestXWPFBugs {
         XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("56392.docx");\r
        assertNotNull(doc);\r
     }\r
+    \r
+    /**\r
+     * Removing a run needs to remove it from both Runs and IRuns\r
+     */\r
+    @Test\r
+    public void test57829() throws Exception {\r
+        XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx");\r
+        assertNotNull(doc);\r
+        assertEquals(3, doc.getParagraphs().size());\r
+        \r
+        for (XWPFParagraph paragraph : doc.getParagraphs()) {\r
+            paragraph.removeRun(0);\r
+            assertNotNull(paragraph.getText());\r
+        }\r
+    }\r
 }\r