Skip to content

Xpp3Dom.getValue(): honor @NonNull contract#389

Merged
elharo merged 3 commits into
masterfrom
fix/xpp3dom-value-null
Jul 1, 2026
Merged

Xpp3Dom.getValue(): honor @NonNull contract#389
elharo merged 3 commits into
masterfrom
fix/xpp3dom-value-null

Conversation

@elharo

@elharo elharo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Xpp3Dom.getValue() is annotated @NonNull (line 141) but can return null when the instance was created via new Xpp3Dom(name) (the value field is never initialized in the one-arg constructor).

Fix:

  • getValue() now returns "" when the internal value field is null, upholding the @NonNull contract
  • Added package-private isValueSet() method so Xpp3DomWriter can distinguish between "value was explicitly set to empty string" and "value was never set" — preserving the existing serialization behavior (elements with unset values serialize as self-closing tags)

The builder at Xpp3DomBuilder.java:201 already worked around this with element.setValue(""); // null in xpp3dom, but we don't do that around here.

Fixes #388

@elharo elharo requested a review from sparsick July 1, 2026 13:07
@elharo elharo added the bug Something isn't working label Jul 1, 2026
@elharo elharo merged commit 5e13d9b into master Jul 1, 2026
15 checks passed
@elharo elharo deleted the fix/xpp3dom-value-null branch July 1, 2026 14:55
@github-actions github-actions Bot added this to the 3.5.0 milestone Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xpp3Dom.getValue() returns null despite @NonNull annotation

2 participants