-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Closed
Labels
in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: enhancementA general enhancementA general enhancement
Milestone
Description
Current Behavior
In org.springframework.security.oauth2.core.ClaimAccessor
interface there is a containsClaim
method:
/**
* Returns {@code true} if the claim exists in {@link #getClaims()}, otherwise {@code false}.
*
* @param claim the name of the claim
* @return {@code true} if the claim exists, otherwise {@code false}
*/
default Boolean containsClaim(String claim) {
Assert.notNull(claim, "claim cannot be null");
return getClaims().containsKey(claim);
}
Return type of this method is a nullable Boolean.
Expected Behavior
It seems the method could return a non-nullable primitive boolean
. This is supported by all of:
- javadoc - not mentioning
null
return value - default implementation -
Map#containsKey
returning primitive boolean - use in other methods assumes non-null values, e.g.
return !containsClaim(claim) ? ... : ...
Context
Noticed this when SonarQube marked if (!accessTokenJwt.containsClaim(CUSTOM_CLAIM)) {
code as non-compliant for rule Boxed "Boolean" should be avoided in boolean expressions
.
Metadata
Metadata
Assignees
Labels
in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: enhancementA general enhancementA general enhancement