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:
committed by
Josh Cummings
parent
330c565178
commit
2fda37de53
+1
-1
@@ -132,7 +132,7 @@ public abstract class AbstractAuthenticationToken implements Authentication, Cre
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (!(obj instanceof AbstractAuthenticationToken test)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+3
-1
@@ -19,6 +19,8 @@ package org.springframework.security.authentication;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -70,7 +72,7 @@ public class AnonymousAuthenticationToken extends AbstractAuthenticationToken im
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+1
-1
@@ -103,7 +103,7 @@ public class RememberMeAuthenticationToken extends AbstractAuthenticationToken {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (!super.equals(obj)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+3
-1
@@ -18,6 +18,8 @@ package org.springframework.security.authentication.jaas;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -53,7 +55,7 @@ public final class JaasGrantedAuthority implements GrantedAuthority {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public final class RequiredFactor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (!(o instanceof RequiredFactor that)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+3
-1
@@ -18,6 +18,8 @@ package org.springframework.security.authorization;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.security.core.authority.FactorGrantedAuthority;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -68,7 +70,7 @@ public class RequiredFactorError {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
@@ -208,7 +208,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
@@ -271,7 +271,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
@@ -379,7 +379,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(@Nullable Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
@@ -607,7 +607,7 @@ class ComparableVersion implements Comparable<ComparableVersion> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
public boolean equals(@Nullable Object o) {
|
||||
return (o instanceof ComparableVersion) && items.equals(((ComparableVersion) o).items);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ public final class FactorGrantedAuthority implements GrantedAuthority {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-1
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.security.core.authority;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -51,7 +53,7 @@ public final class SimpleGrantedAuthority implements GrantedAuthority {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ public class SecurityContextImpl implements SecurityContext {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof SecurityContextImpl other) {
|
||||
if ((this.getAuthentication() == null) && (other.getAuthentication() == null)) {
|
||||
return true;
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.security.core.token;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.jspecify.annotations.Nullable;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -58,7 +60,7 @@ public class DefaultToken implements Token {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof DefaultToken rhs) {
|
||||
return this.key.equals(rhs.key) && this.keyCreationTime == rhs.keyCreationTime
|
||||
&& this.extendedInformation.equals(rhs.extendedInformation);
|
||||
|
||||
@@ -177,7 +177,7 @@ public class User implements UserDetails, CredentialsContainer {
|
||||
* the same principal.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
if (obj instanceof User user) {
|
||||
return this.username.equals(user.getUsername());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user