Skip to content

PrettyPrintXMLWriter: handle null lineIndent in constructors#382

Open
elharo wants to merge 3 commits into
masterfrom
fix/prettyprint-npe-null-lineindent
Open

PrettyPrintXMLWriter: handle null lineIndent in constructors#382
elharo wants to merge 3 commits into
masterfrom
fix/prettyprint-npe-null-lineindent

Conversation

@elharo

@elharo elharo commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Constructors accepting a String lineIndent parameter document it "can be null" but call lineIndent.toCharArray() without a null check, throwing NullPointerException.

Fixed constructors now fall back to the default indentation (two spaces) when lineIndent is null, and to "\n" when lineSeparator is null — matching the behavior of the constructors that don't take these parameters.

Fixes #381

Commits:

  • 581ca4a — Add failing test: PrettyPrintXMLWriter with null lineIndent
  • b38df77 — PrettyPrintXMLWriter: handle null lineIndent/lineSeparator in constructors

@elharo elharo force-pushed the fix/prettyprint-npe-null-lineindent branch from b38df77 to 0f86410 Compare July 1, 2026 12:13
@elharo elharo added the bug Something isn't working label Jul 1, 2026
@elharo elharo requested review from Copilot and hboutemy July 1, 2026 12:18

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes PrettyPrintXMLWriter constructors that documented nullable lineIndent/lineSeparator but could throw NullPointerException by calling toCharArray() unconditionally, aligning behavior with the default constructors (two-space indent and "\n" line separator).

Changes:

  • Update constructor overloads to fall back to DEFAULT_LINE_INDENT when lineIndent is null.
  • Update the constructor overload that accepts lineSeparator to fall back to "\n" when lineSeparator is null.
  • Add a regression test covering null lineIndent construction.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main/java/org/apache/maven/shared/utils/xml/PrettyPrintXMLWriter.java Adds null-handling fallback logic in constructors for lineIndent and lineSeparator.
src/test/java/org/apache/maven/shared/utils/xml/PrettyPrintXmlWriterTest.java Adds a regression test for constructing with null lineIndent.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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.

PrettyPrintXMLWriter NPE when lineIndent is null

2 participants