Skip to content

fix NPE in getBoolean when the value is json null - #83

Merged
JornC merged 1 commit into
aerius:mainfrom
JornC:fix-getboolean-json-null
Sep 23, 2026
Merged

JornC merged 1 commit into
aerius:mainfrom
JornC:fix-getboolean-json-null

Conversation

@JornC

@JornC JornC commented Aug 3, 2026

Copy link
Copy Markdown
Member

Fixes a couple of small bugs that we haven't actually run into yet.


LLM-generated technical summary

inner.get(key) returns Java null only when the key is absent. A JSON null comes back as JSONNull.getInstance(), which is non-null, so the guard passed and isBoolean() then returned null, making booleanValue() throw an NPE. {"someFlag": null} crashes today.

The replacement is the shape getString, getNumber and getArray already use: resolve through getValue(key), narrow with isBoolean(), and null-check the narrowed value. The message also said "Number" in the boolean accessor, which is the second fix.

One behaviour change beyond the NPE: for an absent key this now throws getValue's "Did not encounter required field in object" instead of the misleading "Wrongly assumed json value to be Number". Same exception type, and consistent with the sibling accessors.

Note the module has no test files, so mvn test passes having run nothing — compilation is the only automated evidence here.

The null check tested the raw value, which is non-null for json null, so isBoolean() returned null and booleanValue() threw. Matches the shape the other typed accessors already use.
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

@JornC
JornC requested a review from BertScholten September 22, 2026 20:40

@BertScholten BertScholten left a comment

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.

LGTM (imagine it's pointless to check this in a unittest?)

@JornC
JornC merged commit 86918b5 into aerius:main Sep 23, 2026
2 checks passed
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.

2 participants