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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to