#1168: handle JSON null in User.Smart#name() and #hasName()#1851
Merged
yegor256 merged 2 commits intojcabi:masterfrom May 6, 2026
Merged
#1168: handle JSON null in User.Smart#name() and #hasName()#1851yegor256 merged 2 commits intojcabi:masterfrom
yegor256 merged 2 commits intojcabi:masterfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@yegor256, this PR closes #1168.
The bug
When a GitHub user account has no name set, the API returns
"name": nullin the user JSON instead of omitting the key. In that case,User.Smart#hasName()returnedtrue(because the key is present) andUser.Smart#name()then failed withjava.lang.ClassCastExceptionfromJsonObject#getStringwhile trying to castJsonValue.NULLtoJsonString. CallinghasName()first did not protect callers from the CCE.The fix
Both
name()andhasName()now treat a JSONnullvalue the same as an absent key:hasName()returnsfalsewhen the value is JSONnull.name()throws the sameIllegalStateExceptionit already threw when the key was absent.The behavioral contract
if (smart.hasName()) smart.name();is once again safe.Tests
RtUserTestgets two regression tests (hasNameReturnsFalseWhenNameIsNull,nameThrowsIllegalStateWhenNameIsNull) that fail onmasterwith the originalClassCastExceptionand pass after the fix. They are committed before the fix so the regression is reproducible from the test commit alone.Commits
#1168: regression tests for User.Smart with null name JSON value#1168: skip JSON null when checking User.Smart#name() and #hasName()CI note
The
mvnworkflow currently fails onmasterdue to ~837 pre-existingqulice(PMD/Checkstyle) violations that this PR does not introduce. With my changes the violation count is unchanged at 837. All other 8 CI jobs pass.