1
0
mirror of synced 2026-05-22 13:23:17 +00:00

Fix equals nullability annotations for jspecify compliance

In this commit, we added `@Nullable` to equals methods of classes that
support `jspecify` for consistency with other Spring projects and to
avoid bugs that caused other Spring projects to do this natively.

Closes: gh-18929, gh-18927

Signed-off-by: Andrey Litvitski <andrey1010102008@gmail.com>
This commit is contained in:
Andrey Litvitski
2026-03-18 17:25:52 +03:00
committed by Josh Cummings
parent 330c565178
commit 2fda37de53
62 changed files with 125 additions and 68 deletions
@@ -20,6 +20,8 @@ import java.io.Serial;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.jspecify.annotations.Nullable;
import org.springframework.security.authorization.AuthorizationManager; import org.springframework.security.authorization.AuthorizationManager;
import org.springframework.security.core.annotation.SecurityAnnotationScanner; import org.springframework.security.core.annotation.SecurityAnnotationScanner;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -50,7 +52,7 @@ public class SecurityConfig implements ConfigAttribute {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof ConfigAttribute attr) { if (obj instanceof ConfigAttribute attr) {
return this.attrib.equals(attr.getAttribute()); return this.attrib.equals(attr.getAttribute());
} }
@@ -114,8 +114,10 @@ public final class DelegatingMethodSecurityMetadataSource extends AbstractMethod
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(@Nullable Object other) {
DefaultCacheKey otherKey = (DefaultCacheKey) other; if (!(other instanceof DefaultCacheKey otherKey)) {
return false;
}
return (this.method.equals(otherKey.method) return (this.method.equals(otherKey.method)
&& ObjectUtils.nullSafeEquals(this.targetClass, otherKey.targetClass)); && ObjectUtils.nullSafeEquals(this.targetClass, otherKey.targetClass));
} }
@@ -265,7 +265,7 @@ public class MapBasedMethodSecurityMetadataSource extends AbstractFallbackMethod
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -16,6 +16,8 @@
package org.springframework.security.acls.domain; package org.springframework.security.acls.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.Permission; import org.springframework.security.acls.model.Permission;
/** /**
@@ -52,7 +54,7 @@ public abstract class AbstractPermission implements Permission {
} }
@Override @Override
public final boolean equals(Object obj) { public final boolean equals(@Nullable Object obj) {
if (obj == null) { if (obj == null) {
return false; return false;
} }
@@ -63,7 +63,7 @@ public class AccessControlEntryImpl implements AccessControlEntry, AuditableAcce
} }
@Override @Override
public boolean equals(Object arg0) { public boolean equals(@Nullable Object arg0) {
if (!(arg0 instanceof AccessControlEntryImpl)) { if (!(arg0 instanceof AccessControlEntryImpl)) {
return false; return false;
} }
@@ -278,7 +278,7 @@ public class AclImpl implements Acl, MutableAcl, AuditableAcl, OwnershipAcl {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj == this) { if (obj == this) {
return true; return true;
} }
@@ -16,6 +16,8 @@
package org.springframework.security.acls.domain; package org.springframework.security.acls.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.Sid; import org.springframework.security.acls.model.Sid;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -47,7 +49,7 @@ public class GrantedAuthoritySid implements Sid {
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(@Nullable Object object) {
if ((object == null) || !(object instanceof GrantedAuthoritySid)) { if ((object == null) || !(object instanceof GrantedAuthoritySid)) {
return false; return false;
} }
@@ -19,6 +19,8 @@ package org.springframework.security.acls.domain;
import java.io.Serializable; import java.io.Serializable;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.ObjectIdentity; import org.springframework.security.acls.model.ObjectIdentity;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.ClassUtils; import org.springframework.util.ClassUtils;
@@ -97,7 +99,7 @@ public class ObjectIdentityImpl implements ObjectIdentity {
* @return <code>true</code> if the presented object matches this object * @return <code>true</code> if the presented object matches this object
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj == null || !(obj instanceof ObjectIdentityImpl)) { if (obj == null || !(obj instanceof ObjectIdentityImpl)) {
return false; return false;
} }
@@ -16,6 +16,8 @@
package org.springframework.security.acls.domain; package org.springframework.security.acls.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.Sid; import org.springframework.security.acls.model.Sid;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -46,7 +48,7 @@ public class PrincipalSid implements Sid {
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(@Nullable Object object) {
if ((object == null) || !(object instanceof PrincipalSid)) { if ((object == null) || !(object instanceof PrincipalSid)) {
return false; return false;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.acls.model;
import java.io.Serializable; import java.io.Serializable;
import org.jspecify.annotations.Nullable;
/** /**
* Represents the identity of an individual domain object instance. * Represents the identity of an individual domain object instance.
* *
@@ -40,7 +42,7 @@ public interface ObjectIdentity extends Serializable {
* @see Object#equals(Object) * @see Object#equals(Object)
*/ */
@Override @Override
boolean equals(Object obj); boolean equals(@Nullable Object obj);
/** /**
* Obtains the actual identifier. This identifier must not be reused to represent * Obtains the actual identifier. This identifier must not be reused to represent
@@ -18,6 +18,8 @@ package org.springframework.security.acls.model;
import java.io.Serializable; import java.io.Serializable;
import org.jspecify.annotations.Nullable;
/** /**
* A security identity recognised by the ACL system. * A security identity recognised by the ACL system.
* *
@@ -40,7 +42,7 @@ public interface Sid extends Serializable {
* @return <code>true</code> if the objects are equal, <code>false</code> otherwise * @return <code>true</code> if the objects are equal, <code>false</code> otherwise
*/ */
@Override @Override
boolean equals(Object obj); boolean equals(@Nullable Object obj);
/** /**
* Refer to the <code>java.lang.Object</code> documentation for the interface * Refer to the <code>java.lang.Object</code> documentation for the interface
@@ -124,7 +124,7 @@ public class CasAuthenticationToken extends AbstractAuthenticationToken implemen
} }
@Override @Override
public boolean equals(final Object obj) { public boolean equals(@Nullable final Object obj) {
if (!super.equals(obj)) { if (!super.equals(obj)) {
return false; return false;
} }
@@ -71,7 +71,7 @@ final class DefaultServiceAuthenticationDetails extends WebAuthenticationDetails
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -27,6 +27,7 @@ import java.util.function.Supplier;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.jspecify.annotations.Nullable;
import org.reactivestreams.Publisher; import org.reactivestreams.Publisher;
import org.reactivestreams.Subscription; import org.reactivestreams.Subscription;
import reactor.core.CoreSubscriber; import reactor.core.CoreSubscriber;
@@ -286,7 +287,7 @@ class SecurityReactorContextConfiguration {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -132,7 +132,7 @@ public abstract class AbstractAuthenticationToken implements Authentication, Cre
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (!(obj instanceof AbstractAuthenticationToken test)) { if (!(obj instanceof AbstractAuthenticationToken test)) {
return false; return false;
} }
@@ -19,6 +19,8 @@ package org.springframework.security.authentication;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collection; import java.util.Collection;
import org.jspecify.annotations.Nullable;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -70,7 +72,7 @@ public class AnonymousAuthenticationToken extends AbstractAuthenticationToken im
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (!super.equals(obj)) { if (!super.equals(obj)) {
return false; return false;
} }
@@ -103,7 +103,7 @@ public class RememberMeAuthenticationToken extends AbstractAuthenticationToken {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (!super.equals(obj)) { if (!super.equals(obj)) {
return false; return false;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.authentication.jaas;
import java.security.Principal; import java.security.Principal;
import org.jspecify.annotations.Nullable;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -53,7 +55,7 @@ public final class JaasGrantedAuthority implements GrantedAuthority {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -71,7 +71,7 @@ public final class RequiredFactor {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (!(o instanceof RequiredFactor that)) { if (!(o instanceof RequiredFactor that)) {
return false; return false;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.authorization;
import java.util.Objects; import java.util.Objects;
import org.jspecify.annotations.Nullable;
import org.springframework.security.core.authority.FactorGrantedAuthority; import org.springframework.security.core.authority.FactorGrantedAuthority;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -68,7 +70,7 @@ public class RequiredFactorError {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (o == null || getClass() != o.getClass()) { if (o == null || getClass() != o.getClass()) {
return false; return false;
} }
@@ -143,7 +143,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -208,7 +208,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -271,7 +271,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -379,7 +379,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -607,7 +607,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
return (o instanceof ComparableVersion) && items.equals(((ComparableVersion) o).items); return (o instanceof ComparableVersion) && items.equals(((ComparableVersion) o).items);
} }
@@ -150,7 +150,7 @@ public final class FactorGrantedAuthority implements GrantedAuthority {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -16,6 +16,8 @@
package org.springframework.security.core.authority; package org.springframework.security.core.authority;
import org.jspecify.annotations.Nullable;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -51,7 +53,7 @@ public final class SimpleGrantedAuthority implements GrantedAuthority {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -42,7 +42,7 @@ public class SecurityContextImpl implements SecurityContext {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof SecurityContextImpl other) { if (obj instanceof SecurityContextImpl other) {
if ((this.getAuthentication() == null) && (other.getAuthentication() == null)) { if ((this.getAuthentication() == null) && (other.getAuthentication() == null)) {
return true; return true;
@@ -18,6 +18,8 @@ package org.springframework.security.core.token;
import java.util.Date; import java.util.Date;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -58,7 +60,7 @@ public class DefaultToken implements Token {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof DefaultToken rhs) { if (obj instanceof DefaultToken rhs) {
return this.key.equals(rhs.key) && this.keyCreationTime == rhs.keyCreationTime return this.key.equals(rhs.key) && this.keyCreationTime == rhs.keyCreationTime
&& this.extendedInformation.equals(rhs.extendedInformation); && this.extendedInformation.equals(rhs.extendedInformation);
@@ -177,7 +177,7 @@ public class User implements UserDetails, CredentialsContainer {
* the same principal. * the same principal.
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof User user) { if (obj instanceof User user) {
return this.username.equals(user.getUsername()); return this.username.equals(user.getUsername());
} }
@@ -99,13 +99,16 @@ public class KerberosServiceRequestToken extends AbstractAuthenticationToken imp
* equals() is based only on the Kerberos token * equals() is based only on the Kerberos token
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (!super.equals(obj)) { if (!super.equals(obj)) {
return false; return false;
} }
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) { if (getClass() != obj.getClass()) {
return false; return false;
} }
@@ -115,7 +115,7 @@ public class LdapAuthority implements GrantedAuthority {
* values. * values.
*/ */
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -133,7 +133,7 @@ public class LdapUserDetailsImpl implements LdapUserDetails, PasswordPolicyData
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof LdapUserDetailsImpl) { if (obj instanceof LdapUserDetailsImpl) {
Assert.notNull(this.dn, "dn cannot be null"); Assert.notNull(this.dn, "dn cannot be null");
return this.dn.equals(((LdapUserDetailsImpl) obj).dn); return this.dn.equals(((LdapUserDetailsImpl) obj).dn);
@@ -16,6 +16,8 @@
package org.springframework.security.messaging.util.matcher; package org.springframework.security.messaging.util.matcher;
import org.jspecify.annotations.Nullable;
import org.springframework.messaging.Message; import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders; import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.simp.SimpMessageHeaderAccessor; import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
@@ -53,7 +55,7 @@ public class SimpMessageTypeMatcher implements MessageMatcher<Object> {
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(@Nullable Object other) {
if (this == other) { if (this == other) {
return true; return true;
} }
@@ -71,7 +71,7 @@ public class OAuth2TokenExchangeCompositeAuthenticationToken extends AbstractAut
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (!(obj instanceof OAuth2TokenExchangeCompositeAuthenticationToken other)) { if (!(obj instanceof OAuth2TokenExchangeCompositeAuthenticationToken other)) {
return false; return false;
} }
@@ -19,6 +19,8 @@ package org.springframework.security.oauth2.client;
import java.io.Serializable; import java.io.Serializable;
import java.util.Objects; import java.util.Objects;
import org.jspecify.annotations.Nullable;
import org.springframework.security.oauth2.client.registration.ClientRegistration; import org.springframework.security.oauth2.client.registration.ClientRegistration;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -69,7 +71,7 @@ public final class OAuth2AuthorizedClientId implements Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -766,7 +766,7 @@ public final class ClientRegistration implements Serializable {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -92,7 +92,7 @@ public abstract class AbstractOAuth2Token implements OAuth2Token, Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.oauth2.core;
import java.io.Serializable; import java.io.Serializable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -59,7 +61,7 @@ public final class AuthenticationMethod implements Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.oauth2.core;
import java.io.Serializable; import java.io.Serializable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -84,7 +86,7 @@ public final class AuthorizationGrantType implements Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.oauth2.core;
import java.io.Serializable; import java.io.Serializable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -114,7 +116,7 @@ public final class ClientAuthenticationMethod implements Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -135,7 +135,7 @@ public class OAuth2AccessToken extends AbstractOAuth2Token {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -210,7 +210,7 @@ public class OAuth2AuthorizationRequest implements Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.oauth2.core.endpoint;
import java.io.Serializable; import java.io.Serializable;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -56,7 +58,7 @@ public final class OAuth2AuthorizationResponseType implements Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -75,7 +75,7 @@ public final class DefaultAddressStandardClaim implements AddressStandardClaim {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -23,6 +23,8 @@ import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -66,7 +68,7 @@ public class OidcUserInfo implements StandardClaimAccessor, Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -126,7 +126,7 @@ public class OidcUserAuthority extends OAuth2UserAuthority {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -104,7 +104,7 @@ public class DefaultOAuth2User implements OAuth2User, Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -115,7 +115,7 @@ public class OAuth2UserAuthority implements GrantedAuthority {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -199,7 +199,7 @@ public final class Saml2X509Credential implements Serializable {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -24,6 +24,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import org.jspecify.annotations.NullUnmarked; import org.jspecify.annotations.NullUnmarked;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -95,7 +96,7 @@ public class DefaultSaml2AuthenticatedPrincipal implements Saml2AuthenticatedPri
} }
@Override @Override
public boolean equals(Object object) { public boolean equals(@Nullable Object object) {
if (this == object) { if (this == object) {
return true; return true;
} }
@@ -25,6 +25,7 @@ import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException; import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletRequest;
import jakarta.servlet.ServletResponse; import jakarta.servlet.ServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.security.config.BeanIds; import org.springframework.security.config.BeanIds;
import org.springframework.test.web.servlet.request.RequestPostProcessor; import org.springframework.test.web.servlet.request.RequestPostProcessor;
@@ -142,7 +143,7 @@ final class SecurityMockMvcConfigurer extends MockMvcConfigurerAdapter {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
return getDelegate().equals(obj); return getDelegate().equals(obj);
} }
@@ -49,7 +49,7 @@ public class RequestKey {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (!(obj instanceof RequestKey key)) { if (!(obj instanceof RequestKey key)) {
return false; return false;
} }
@@ -80,7 +80,7 @@ public class WebAuthenticationDetails implements Serializable {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -16,6 +16,8 @@
package org.springframework.security.web.authentication.switchuser; package org.springframework.security.web.authentication.switchuser;
import org.jspecify.annotations.Nullable;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -59,7 +61,7 @@ public final class SwitchUserGrantedAuthority implements GrantedAuthority {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -20,6 +20,7 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -62,7 +63,7 @@ public final class Header {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -18,6 +18,8 @@ package org.springframework.security.web.server.csrf;
import java.io.Serial; import java.io.Serial;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@@ -69,7 +71,7 @@ public final class DefaultCsrfToken implements CsrfToken {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -161,7 +161,7 @@ public final class PathPatternRequestMatcher implements RequestMatcher {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (!(o instanceof PathPatternRequestMatcher that)) { if (!(o instanceof PathPatternRequestMatcher that)) {
return false; return false;
} }
@@ -24,6 +24,7 @@ import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.WriteListener; import jakarta.servlet.WriteListener;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponseWrapper; import jakarta.servlet.http.HttpServletResponseWrapper;
import org.jspecify.annotations.Nullable;
/** /**
* Base class for response wrappers which encapsulate the logic for handling an event when * Base class for response wrappers which encapsulate the logic for handling an event when
@@ -311,7 +312,7 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
return this.delegate.equals(obj); return this.delegate.equals(obj);
} }
@@ -678,7 +679,7 @@ public abstract class OnCommittedResponseWrapper extends HttpServletResponseWrap
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
return this.delegate.equals(obj); return this.delegate.equals(obj);
} }
@@ -23,6 +23,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -88,7 +89,7 @@ public final class AndRequestMatcher implements RequestMatcher {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -17,6 +17,7 @@
package org.springframework.security.web.util.matcher; package org.springframework.security.web.util.matcher;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
/** /**
* Matches any supplied request. * Matches any supplied request.
@@ -38,7 +39,7 @@ public final class AnyRequestMatcher implements RequestMatcher {
@Override @Override
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
return obj instanceof AnyRequestMatcher return obj instanceof AnyRequestMatcher
|| obj instanceof org.springframework.security.web.util.matcher.AnyRequestMatcher; || obj instanceof org.springframework.security.web.util.matcher.AnyRequestMatcher;
} }
@@ -26,6 +26,7 @@ import java.util.Set;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -253,7 +254,7 @@ public final class MediaTypeRequestMatcher implements RequestMatcher {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -19,6 +19,7 @@ package org.springframework.security.web.util.matcher;
import java.util.Objects; import java.util.Objects;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -50,7 +51,7 @@ public class NegatedRequestMatcher implements RequestMatcher {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -21,6 +21,7 @@ import java.util.List;
import java.util.Objects; import java.util.Objects;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import org.jspecify.annotations.Nullable;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@@ -83,7 +84,7 @@ public final class OrRequestMatcher implements RequestMatcher {
} }
@Override @Override
public boolean equals(Object o) { public boolean equals(@Nullable Object o) {
if (this == o) { if (this == o) {
return true; return true;
} }
@@ -94,7 +94,7 @@ public final class RequestHeaderRequestMatcher implements RequestMatcher {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (this == obj) { if (this == obj) {
return true; return true;
} }
@@ -71,7 +71,7 @@ public final class Bytes implements Serializable {
} }
@Override @Override
public boolean equals(Object obj) { public boolean equals(@Nullable Object obj) {
if (obj instanceof Bytes that) { if (obj instanceof Bytes that) {
return that.toBase64UrlString().equals(toBase64UrlString()); return that.toBase64UrlString().equals(toBase64UrlString());
} }