Fix source code bugs discovered during test coverage expansion#1036
Open
Avery-Dunn wants to merge 3 commits into
Open
Fix source code bugs discovered during test coverage expansion#1036Avery-Dunn wants to merge 3 commits into
Avery-Dunn wants to merge 3 commits into
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.
Fixes 8 source code bugs discovered while expanding unit test coverage. These bugs range from copy-paste errors in validation to a field initialization order bug introduced when Lombok was removed from the project.
Bugs Fixed
1. AuthenticationResult field initialization order
Root cause: When Lombok was removed (commit
67d3131a, April 2025),@Getter(lazy = true)fields were incorrectly translated to eager field initializers. Java field initializers run before the constructor body, so derived fields (idTokenObject,account,tenantProfile) were always computed when their source fields (idToken,accountCacheEntity) were still null.Impact:
tenantProfile()always returned null (publicly visible viaIAuthenticationResult)idTokenObjectalways null (internal only)accountfield always null, though the public getter re-calledgetAccount()and worked correctlyFix: Moved derived field computation into the constructor body, after source fields are assigned. Added graceful error handling in
getIdTokenObj()andgetTenantProfile()so malformed ID tokens (e.g., from cache) produce null rather than throwing exceptions.2. AuthenticationResult.getTenantProfile() latent NPE
Root cause:
getTenantProfile()calledgetAccount().environment()without null-checkinggetAccount(). Previously masked by bug #1 (idToken was always null during init, sogetTenantProfile()returned early).Fix: Added null check for
getAccount()before calling.environment().3. Missing equals/hashCode on AuthenticationResult-related classes
Root cause:
AuthenticationResultMetadata,IdToken, andTenantProfileused Object reference equality. SinceAuthenticationResult.equals()compares these fields, two AuthenticationResult instances with equivalent but separately-constructed metadata/idToken/tenantProfile would fail equality checks.Fix: Added proper
equals()andhashCode()implementations to all three classes.4. DeviceCodeFlowParameters validates wrong field
Location:
DeviceCodeFlowParameters.java:118Bug:
validateNotNull("deviceCodeConsumer", scopes)— validatesscopesinstead ofdeviceCodeConsumer.Fix: Changed to
validateNotNull("deviceCodeConsumer", deviceCodeConsumer).5. RefreshTokenParameters validates wrong field
Location:
RefreshTokenParameters.java:116Bug:
validateNotNull("refreshToken", scopes)— same copy-paste error.Fix: Changed to
validateNotNull("refreshToken", refreshToken).6. ErrorResponse.toJson() double writeStartObject
Location:
ErrorResponse.java:67-68Bug: Called
writeStartObject()twice, causingIllegalStateExceptionon anytoJson()call.Fix: Removed the duplicate call.
7. RequestedClaim.toJson() invalid JSON structure
Location:
RequestedClaim.java:53Bug: Called
writeString(name)inside an object context, producing invalid JSON.Fix: Changed to
writeFieldName(name).8. OidcDiscoveryResponse.toJson() missing issuer
Location:
OidcDiscoveryResponse.java:49-50Bug:
toJson()did not include theissuerfield, sofromJson() → toJson()round-trips lost data.Fix: Added
writeStringField("issuer", issuer).Test Changes
Updated tests
build_WithIdTokenButNullAccount_TenantProfileIsNullfor the null-check fix. Added 3AuthenticationResultMetadataequals/hashCode tests. Addedmetadatato parameterized equals provider.deviceCodeFlowandrefreshTokenvalidation tests from documenting wrong-field behavior to testing correct-field validation.errorResponse_toJsonandrequestedClaim_toJsontests fromassertThrows(documenting bug) to asserting correct JSON output. UpdatedoidcDiscoveryResponse_toJsonto verify issuer is included.