#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
This commit is contained in:
Nick Burch 2015-04-24 01:29:10 +00:00
parent ee6a6d6584
commit 8d0fb1c89d
2 changed files with 20 additions and 1 deletions

View 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;

View File

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