Skip to content

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

Merged
pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:bug-69554-xwpfrun-getters
Sep 18, 2026
Merged

pjfanning merged 1 commit into
apache:trunkfrom
pjfanning:bug-69554-xwpfrun-getters

Conversation

@pjfanning

Copy link
Copy Markdown
Member

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

…m elements

getTextHighlightColor(), getVerticalAlignment() and getEmphasisMark()
added an empty <w:highlight/>, <w:vertAlign/> or <w:em/> to an existing
<w:rPr> when the element was missing. All three require w:val, so Word
reports the document as invalid and strips them on repair.

Return the documented default when the element is absent instead.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@pjfanning
pjfanning merged commit 6aafe8d into apache:trunk Sep 18, 2026
4 checks passed
@pjfanning
pjfanning deleted the bug-69554-xwpfrun-getters branch September 18, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant