Skip to content

Return type of oauth2.core.ClaimAccessor#containsClaim(String) could be a primitive boolean #9201

@grimsa

Description

@grimsa

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)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions