Handle missing numbering level values safely, NPE in ListLevel.java - #689
Handle missing numbering level values safely, NPE in ListLevel.java#689zyplayer wants to merge 1 commit into
Conversation
Normalize missing abstract numbering level IDs without overwriting existing levels. Centralize paragraph numbering level resolution and default omitted or malformed values to level 0 across HTML and FO conversion paths. Add regression tests for direct construction, malformed paragraph levels, and linked numbering styles.
|
One change I'd like before merging: Please don't mutate the JAXB objects. Both ListLevel and AbstractListNumberingDefinition call setIlvl(...) on the caller's Lvl. That makes a read path write to the document model: converting to HTML or PDF would silently add w:ilvl attributes the user never authored, and if they save the package afterwards those end up in their docx. It isn't needed, either. ListLevel:143 is the only place that requires Lvl.getIlvl() to be non-null — MainDocumentPart:340 only logs it, and ListNumberingDefinition:216 is LvlOverride.getIlvl(), which is already guarded. So deriving the id locally is enough: if (levelNode.getIlvl() == null) { and similarly in readListLevelsFromAbsNode, where you can pass the level number you worked out to readLevel/ListLevel rather than stamping it onto the Lvl. The tests would need the corresponding change, since at the moment they assert the mutation. A minor thing: Level assignment for a malformed abstractNum. Lowest-unused is arbitrary: for [lvl-without-ilvl, lvl0] it makes the first element level 1. Positional index (level n is the nth w:lvl) seems more natural, and I'd expect it to match what Word does with such a file? |
|
@dcoapp recheck |
Normalize missing abstract numbering level IDs without overwriting existing levels.
Centralize paragraph numbering level resolution and default omitted or malformed values to level 0 across HTML and FO conversion paths.
Add regression tests for direct construction, malformed paragraph levels, and linked numbering styles.
What does this PR do?
#593
This PR improves the handling of missing or malformed numbering level values and prevents
NullPointerExceptions during HTML and FO conversion.It:
w:lvl/@w:ilvlvalues when abstract numbering definitions are loaded.Emulator.w:numPr/w:ilvlvalues to level0when the level is consumed.ListLevelconstruction with a missing level ID.val.0is already occupied.Checklist
Signed-off-by:line added by me (DCO — seeCONTRIBUTING.md), certifying I have the right to submit this under the
Apache License v2.
(
Assisted-by:/Generated-by:/Co-Authored-By:), and I havepersonally reviewed, understood, and can explain all of the code.
mvn test -pl docx4j-core-tests -am), and I addedor extended a test where practical.
CHANGELOG.mdis updated if the change is user-visible.