1
0
mirror of synced 2026-05-22 21:33:16 +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
@@ -16,6 +16,8 @@
package org.springframework.security.acls.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.Permission;
/**
@@ -52,7 +54,7 @@ public abstract class AbstractPermission implements Permission {
}
@Override
public final boolean equals(Object obj) {
public final boolean equals(@Nullable Object obj) {
if (obj == null) {
return false;
}
@@ -63,7 +63,7 @@ public class AccessControlEntryImpl implements AccessControlEntry, AuditableAcce
}
@Override
public boolean equals(Object arg0) {
public boolean equals(@Nullable Object arg0) {
if (!(arg0 instanceof AccessControlEntryImpl)) {
return false;
}
@@ -278,7 +278,7 @@ public class AclImpl implements Acl, MutableAcl, AuditableAcl, OwnershipAcl {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}
@@ -16,6 +16,8 @@
package org.springframework.security.acls.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.Sid;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.util.Assert;
@@ -47,7 +49,7 @@ public class GrantedAuthoritySid implements Sid {
}
@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if ((object == null) || !(object instanceof GrantedAuthoritySid)) {
return false;
}
@@ -19,6 +19,8 @@ package org.springframework.security.acls.domain;
import java.io.Serializable;
import java.lang.reflect.Method;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.ObjectIdentity;
import org.springframework.util.Assert;
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
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == null || !(obj instanceof ObjectIdentityImpl)) {
return false;
}
@@ -16,6 +16,8 @@
package org.springframework.security.acls.domain;
import org.jspecify.annotations.Nullable;
import org.springframework.security.acls.model.Sid;
import org.springframework.security.core.Authentication;
import org.springframework.util.Assert;
@@ -46,7 +48,7 @@ public class PrincipalSid implements Sid {
}
@Override
public boolean equals(Object object) {
public boolean equals(@Nullable Object object) {
if ((object == null) || !(object instanceof PrincipalSid)) {
return false;
}
@@ -18,6 +18,8 @@ package org.springframework.security.acls.model;
import java.io.Serializable;
import org.jspecify.annotations.Nullable;
/**
* Represents the identity of an individual domain object instance.
*
@@ -40,7 +42,7 @@ public interface ObjectIdentity extends Serializable {
* @see Object#equals(Object)
*/
@Override
boolean equals(Object obj);
boolean equals(@Nullable Object obj);
/**
* 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 org.jspecify.annotations.Nullable;
/**
* 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
*/
@Override
boolean equals(Object obj);
boolean equals(@Nullable Object obj);
/**
* Refer to the <code>java.lang.Object</code> documentation for the interface