Skip to content

Xpp3DomWriter: add explicit null check for dom parameter#397

Closed
elharo wants to merge 1 commit into
masterfrom
fix/xpp3domwriter-null-dom
Closed

Xpp3DomWriter: add explicit null check for dom parameter#397
elharo wants to merge 1 commit into
masterfrom
fix/xpp3domwriter-null-dom

Conversation

@elharo

@elharo elharo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

All public write methods accept an Xpp3Dom dom parameter without null checks. Passing null throws a NullPointerException deep inside the delegation chain (at dom.getName() in the write(XMLWriter, Xpp3Dom, boolean) method), producing a confusing stack trace for callers.

Fix: Added Objects.requireNonNull(dom, "dom must not be null") at the entry to the shared write(XMLWriter, Xpp3Dom, boolean) method, so callers get a clear message immediately.

Fixes #396

@elharo elharo added the enhancement New feature or request label Jul 1, 2026
@elharo elharo self-assigned this Jul 1, 2026
@elharo elharo requested a review from desruisseaux July 1, 2026 14:20
* @throws IOException if writing fails
*/
public static void write(XMLWriter xmlWriter, Xpp3Dom dom, boolean escape) throws IOException {
Objects.requireNonNull(dom, "dom must not be null");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it really solving the problem described in the issue? The next line is dom.getName(), therefore a NullPointerException would happen there anyway. The stack trace produced by Objects will be even deeper (a little bit) than the stack trace produced by the NullPointerException on the next line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makese sense. thanks.

@elharo elharo closed this Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Xpp3DomWriter.write(null) throws confusing NPE

2 participants