You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2026/09/18 18:38:05 UTC

[PR] [bug-69554] XWPFRun: getters must not add empty highlight/vertAlign/em elements [poi]

pjfanning opened a new pull request, #1302:
URL: https://github.com/apache/poi/pull/1302

   Fixes the remaining case in https://bz.apache.org/bugzilla/show_bug.cgi?id=69554 (comment 5).
   
   ### Problem
   
   r1923440 stopped `getUnderline()` from creating `<w:rPr>`, but `getTextHighlightColor()`, `getVerticalAlignment()` and `getEmphasisMark()` still did `sizeOfXArray() > 0 ? getXArray(0) : addNewX()` after `getRunProperties(false)`. That is harmless on a bare run (`pr == null` returns the default), but once the run already has `<w:rPr>` - after `setBold(true)`, or for any run read from an existing document - the getter inserts an empty `<w:highlight/>`, `<w:vertAlign/>` or `<w:em/>`. All three require `w:val` in the schema, so Word reports the file as corrupt and strips them on repair. This is why the reporter could only reproduce it in a "more complex" document.
   
   ### Fix
   
   The three getters return their documented default when the element is absent instead of adding it. The other `addNew*` calls in `XWPFRun` are all in setters.
   
   ### Tests
   
   `TestXWPFRun.testGettersDoNotAddEmptyRunProperties`: run with `setBold(true)`, call the getters (including the underline ones from r1923440), assert no highlight/vertAlign/em/u elements were added and that the `CTRPr` passes `validate()`. Fails on trunk (`expected: <0> but was: <1>`), passes with the fix. All `org.apache.poi.xwpf.*` tests pass.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] [bug-69554] XWPFRun: getters must not add empty highlight/vertAlign/em elements [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1302:
URL: https://github.com/apache/poi/pull/1302


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org