Skip to content

[bugfix] fixes potential NPE#6499

Merged
line-o merged 1 commit into
eXist-db:developfrom
reinhapa:bugfix/fix-npe
Jun 20, 2026
Merged

[bugfix] fixes potential NPE#6499
line-o merged 1 commit into
eXist-db:developfrom
reinhapa:bugfix/fix-npe

Conversation

@reinhapa

Copy link
Copy Markdown
Member

Fixes a NPE when null is passed into setContent(Object)

@reinhapa reinhapa requested a review from a team as a code owner June 19, 2026 06:51
case AtomicValue atomicValue -> value = atomicValue;
case InputSource source -> inputSource = source;
case byte[] bytes -> content = new String(bytes, UTF_8);
default -> content = obj.toString();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why did you choose not to handle the null case within the switch?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This will produce a codacy issue as the content is already set to null

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Then I would prefer an early return

if (obj == null) { return; }

@line-o line-o Jun 19, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

a noop would be another alternative

case null -> noop();
default -> content = obj.toString();

Signed-off-by: Patrick Reinhart <patrick@reini.net>
@line-o line-o merged commit 1a5c90c into eXist-db:develop Jun 20, 2026
14 of 15 checks passed
@reinhapa reinhapa deleted the bugfix/fix-npe branch June 20, 2026 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants