[bug-69554] XWPFRun: getters must not add empty highlight/vertAlign/em elements - #1302
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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>, butgetTextHighlightColor(),getVerticalAlignment()andgetEmphasisMark()still didsizeOfXArray() > 0 ? getXArray(0) : addNewX()aftergetRunProperties(false). That is harmless on a bare run (pr == nullreturns the default), but once the run already has<w:rPr>- aftersetBold(true), or for any run read from an existing document - the getter inserts an empty<w:highlight/>,<w:vertAlign/>or<w:em/>. All three requirew:valin 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 inXWPFRunare all in setters.Tests
TestXWPFRun.testGettersDoNotAddEmptyRunProperties: run withsetBold(true), call the getters (including the underline ones from r1923440), assert no highlight/vertAlign/em/u elements were added and that theCTRPrpassesvalidate(). Fails on trunk (expected: <0> but was: <1>), passes with the fix. Allorg.apache.poi.xwpf.*tests pass.🤖 Generated with Claude Code