Bug 65282 - XWPFParagraph's addRun method only adds to run collection, missing iRun collection
Summary: XWPFParagraph's addRun method only adds to run collection, missing iRun colle...
Status: NEEDINFO
Alias: None
Product: POI
Classification: Unclassified
Component: XWPF (show other bugs)
Version: 5.0.0-FINAL
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-30 21:05 UTC by Szemere
Modified: 2021-05-06 06:38 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Szemere 2021-04-30 21:05:54 UTC
I am copying a run in the current paragraph into a prior paragraph (priorP).

XmlObject newRunXml = run.getCTR().copy();
XWPFRun newRun = new XWPFRun((CTR) newRunXml, (IRunBody) priorP);
priorP.addRun(newRun);

This last method call only adds the run to the run collection, not the iRun collection and is never written on write to file (possible as a result).

A workaround is to write my own addRun method, based on the protected addRun method in XWPFParagraph:

private static void addRun(XWPFParagraph p, CTR run) {
  CTP ctp = p.getCTP();
  int pos = ctp.sizeOfRArray();
  ctp.addNewR();
  ctp.setRArray(pos, run);
}
Comment 1 Sayi 2021-05-06 06:38:33 UTC
Just use public methods, if you write your own addRun method, you should always update runs and iruns.

The issue is fixed via r1889551.