Repository navigation
Align OAuth2AccessToken.TokenType hashCode with case-insensitive equals - #20208
Open
amalsaidov wants to merge 1 commit into
Open
amalsaidov wants to merge 1 commit into
amalsaidov wants to merge 1 commit into
Conversation
OAuth2AccessToken.TokenType.equals(Object) compares values using equalsIgnoreCase (token types are case-insensitive per RFC 6749 section 7.1), but hashCode() was derived from the case-sensitive String.hashCode(). Two instances that are equal but differ only in case therefore produced different hash codes, violating the equals/hashCode contract and breaking lookups in hash-based collections. Canonicalize the value to lower case when computing the hash so that equal token types always have equal hash codes. Signed-off-by: amalsaidov <amalsaidov@users.noreply.github.com>
This branch has not been deployed
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.
OAuth2AccessToken.TokenTypeoverridesequals(Object)usingequalsIgnoreCase(token types are case-insensitive per RFC 6749 §7.1), buthashCode()was derived from the case-sensitiveString.hashCode():Two instances that are
equalbut differ only in case therefore produced different hash codes, violating theequals/hashCodecontract and breaking lookups in hash-based collections (HashSet/HashMap):The public
TokenType(String)constructor (@since 6.5) lets callers/providers create arbitrary-case instances, and since gh-19377 call sites such asBearerTokenAuthenticationrely onTokenType.equals(...), so the inconsistency is easily reachable.This change canonicalizes the value to lower case when computing the hash, so equal token types always have equal hash codes. The case-insensitive
equals(intentional and RFC-aligned, present sinceTokenTypebecame a class) is unchanged.A regression test is added that fails before the change and passes after; the
spring-security-oauth2-coremodulecheck(tests + Checkstyle) passes.