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()); + } + } }