From: Nick Burch Date: Fri, 24 Apr 2015 01:29:10 +0000 (+0000) Subject: #57829 Avoid XmlValueDisconnectedException when removing a XWPFRun from a XWPFParagra... X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=a5846f0f660b70cb1bfd88a7a50820ec3779f51c;p=poi.git #57829 Avoid XmlValueDisconnectedException when removing a XWPFRun from a XWPFParagraph by removing from IRuns as well git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1675738 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java index 7ed629c10a..c98143a5ae 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFParagraph.java @@ -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; diff --git a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java index 053b611e3c..8fd7f97e04 100644 --- a/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java +++ b/src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFBugs.java @@ -88,4 +88,19 @@ public class TestXWPFBugs { XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("56392.docx"); assertNotNull(doc); } + + /** + * Removing a run needs to remove it from both Runs and IRuns + */ + @Test + public void test57829() throws Exception { + XWPFDocument doc = XWPFTestDataSamples.openSampleDocument("sample.docx"); + assertNotNull(doc); + assertEquals(3, doc.getParagraphs().size()); + + for (XWPFParagraph paragraph : doc.getParagraphs()) { + paragraph.removeRun(0); + assertNotNull(paragraph.getText()); + } + } }