Add Nullable annotation to parameter of overridden equals method.

Closes: #4226
Original pull request: #4277
This commit is contained in:
Christoph Strobl
2022-11-08 12:28:47 +01:00
committed by Mark Paluch
parent f5ea80a346
commit d76c84326b
49 changed files with 85 additions and 57 deletions

View File

@@ -199,7 +199,7 @@ public class ChangeStreamEvent<T> {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;

View File

@@ -153,7 +153,7 @@ public class ChangeStreamOptions {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -598,7 +598,7 @@ class DefaultBulkOperations implements BulkOperations {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
@@ -667,7 +667,7 @@ class DefaultBulkOperations implements BulkOperations {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -269,7 +269,7 @@ public abstract class MongoDatabaseFactorySupport<C> implements MongoDatabaseFac
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -283,7 +283,7 @@ public class SimpleReactiveMongoDatabaseFactory implements DisposableBean, React
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -318,7 +318,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
@@ -431,7 +431,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
@@ -510,7 +510,7 @@ public final class ExposedFields implements Iterable<ExposedField> {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -326,7 +326,7 @@ public final class Fields implements Iterable<Field> {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -79,7 +80,7 @@ public class GeoJsonGeometryCollection implements GeoJson<Iterable<GeoJson<?>>>
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -20,6 +20,7 @@ import java.util.Collections;
import java.util.List;
import org.springframework.data.geo.Point;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -94,7 +95,7 @@ public class GeoJsonMultiLineString implements GeoJson<Iterable<GeoJsonLineStrin
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -21,6 +21,7 @@ import java.util.Collections;
import java.util.List;
import org.springframework.data.geo.Point;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -116,7 +117,7 @@ public class GeoJsonMultiPoint implements GeoJson<Iterable<Point>> {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -19,6 +19,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -78,7 +79,7 @@ public class GeoJsonMultiPolygon implements GeoJson<Iterable<GeoJsonPolygon>> {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -23,6 +23,7 @@ import java.util.List;
import org.springframework.data.geo.Point;
import org.springframework.data.geo.Polygon;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -145,7 +146,7 @@ public class GeoJsonPolygon extends Polygon implements GeoJson<List<GeoJsonLineS
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;
}

View File

@@ -23,6 +23,7 @@ import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Point;
import org.springframework.data.geo.Shape;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -105,7 +106,7 @@ public class Sphere implements Shape {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -179,7 +179,7 @@ public final class IndexField {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -283,7 +283,7 @@ public class IndexInfo {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}

View File

@@ -991,7 +991,7 @@ public class MongoPersistentEntityIndexResolver implements IndexResolver {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -205,7 +205,7 @@ public class TextIndexDefinition implements IndexDefinition {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.mongodb.core.mapping;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -39,7 +40,7 @@ class UnwrapEntityContext {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -350,7 +350,7 @@ class UnwrappedMongoPersistentProperty implements MongoPersistentProperty {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.mongodb.core.mapreduce;
import org.springframework.lang.Nullable;
/**
* Value object to encapsulate results of a map-reduce count.
*
@@ -89,7 +91,7 @@ public class MapReduceCounts {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.mongodb.core.mapreduce;
import org.springframework.lang.Nullable;
/**
* @deprecated since 3.4 in favor of {@link org.springframework.data.mongodb.core.aggregation}.
*/
@@ -74,7 +76,7 @@ public class MapReduceTiming {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -284,7 +284,7 @@ public class DefaultMessageListenerContainer implements MessageListenerContainer
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -108,7 +108,7 @@ public interface Message<S, T> {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -73,7 +73,7 @@ class SimpleMessage<S, T> implements Message<S, T> {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -176,7 +176,7 @@ public class BasicQuery extends Query {
* @see org.springframework.data.mongodb.core.query.Query#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;

View File

@@ -20,6 +20,7 @@ import java.util.Optional;
import org.bson.Document;
import org.springframework.core.convert.converter.Converter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
@@ -399,7 +400,7 @@ public class Collation {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;

View File

@@ -979,7 +979,7 @@ public class Criteria implements CriteriaDefinition {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -241,7 +241,7 @@ public class Field {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;

View File

@@ -22,6 +22,7 @@ import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Polygon;
import org.springframework.data.geo.Shape;
import org.springframework.data.mongodb.core.geo.Sphere;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
@@ -107,7 +108,7 @@ public final class GeoCommand {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -265,7 +265,7 @@ public class Meta {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -603,7 +603,7 @@ public class Query {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -98,7 +98,7 @@ public class Term {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;

View File

@@ -237,7 +237,7 @@ public class TextCriteria implements CriteriaDefinition {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) {
return true;

View File

@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core.query;
import java.util.Set;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -223,7 +224,7 @@ public class UntypedExampleMatcher implements ExampleMatcher {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;

View File

@@ -550,7 +550,7 @@ public class Update implements UpdateDefinition {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
@@ -628,7 +628,7 @@ public class Update implements UpdateDefinition {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
@@ -697,7 +697,7 @@ public class Update implements UpdateDefinition {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object that) {
public boolean equals(@Nullable Object that) {
if (this == that) {
return true;
@@ -1027,7 +1027,7 @@ public class Update implements UpdateDefinition {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -525,7 +525,7 @@ public interface JsonSchemaObject {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
@@ -573,7 +573,7 @@ public interface JsonSchemaObject {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;

View File

@@ -19,6 +19,7 @@ import org.bson.Document;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
import org.springframework.data.mongodb.core.query.SerializationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -73,7 +74,7 @@ class CriteriaValidator implements Validator {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())

View File

@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.core.validation;
import org.bson.Document;
import org.springframework.data.mongodb.core.query.SerializationUtils;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -69,7 +70,7 @@ class DocumentValidator implements Validator {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;

View File

@@ -18,6 +18,7 @@ package org.springframework.data.mongodb.core.validation;
import org.bson.Document;
import org.springframework.data.mongodb.core.query.SerializationUtils;
import org.springframework.data.mongodb.core.schema.MongoJsonSchema;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -69,7 +70,7 @@ class JsonSchemaValidator implements Validator {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o)
return true;

View File

@@ -86,6 +86,7 @@ import org.springframework.data.mongodb.test.util.MongoClientExtension;
import org.springframework.data.mongodb.test.util.MongoTestTemplate;
import org.springframework.data.mongodb.test.util.MongoVersion;
import org.springframework.data.util.CloseableIterator;
import org.springframework.lang.Nullable;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.util.ClassUtils;
import org.springframework.util.ObjectUtils;
@@ -3882,7 +3883,7 @@ public class MongoTemplateTests {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}
@@ -4125,7 +4126,7 @@ public class MongoTemplateTests {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;

View File

@@ -16,6 +16,7 @@
package org.springframework.data.mongodb.core;
import org.bson.types.ObjectId;
import org.springframework.lang.Nullable;
public class Person {
@@ -95,7 +96,7 @@ public class Person {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;
}

View File

@@ -15,6 +15,8 @@
*/
package org.springframework.data.mongodb.core;
import org.springframework.lang.Nullable;
public class User {
@Override
@@ -27,7 +29,7 @@ public class User {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj)
return true;
if (obj == null)

View File

@@ -55,6 +55,7 @@ import org.springframework.data.mongodb.core.convert.MappingMongoConverterUnitTe
import org.springframework.data.mongodb.core.mapping.MongoMappingContext;
import org.springframework.data.mongodb.core.mapping.MongoPersistentEntity;
import org.springframework.data.mongodb.core.mapping.MongoPersistentProperty;
import org.springframework.lang.Nullable;
import org.springframework.test.util.ReflectionTestUtils;
import org.springframework.util.SerializationUtils;
@@ -851,7 +852,7 @@ class DbRefMappingMongoConverterUnitTests {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj)
return true;
if (obj == null)

View File

@@ -37,6 +37,7 @@ import org.springframework.data.mongodb.core.query.TextQueryTests.FullTextDoc.Fu
import org.springframework.data.mongodb.test.util.MongoTemplateExtension;
import org.springframework.data.mongodb.test.util.MongoTestTemplate;
import org.springframework.data.mongodb.test.util.Template;
import org.springframework.lang.Nullable;
/**
* @author Christoph Strobl
@@ -251,7 +252,7 @@ public class TextQueryTests {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.mongodb.repository;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
import com.querydsl.core.annotations.QueryEmbeddable;
@@ -87,7 +88,7 @@ public class Address {
}
@Override
public boolean equals(Object o) {
public boolean equals(@Nullable Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

View File

@@ -38,6 +38,7 @@ import org.springframework.data.mongodb.repository.support.MongoRepositoryFactor
import org.springframework.data.mongodb.test.util.MongoTemplateExtension;
import org.springframework.data.mongodb.test.util.MongoTestTemplate;
import org.springframework.data.mongodb.test.util.Template;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -232,7 +233,7 @@ class MongoRepositoryTextSearchIntegrationTests {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;
}

View File

@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.repository;
import java.io.Serializable;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -42,7 +43,7 @@ public class MyId implements Serializable {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;

View File

@@ -30,6 +30,7 @@ import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.DocumentReference;
import org.springframework.data.mongodb.core.mapping.Field;
import org.springframework.data.mongodb.core.mapping.Unwrapped;
import org.springframework.lang.Nullable;
/**
* Sample domain class.
@@ -281,7 +282,7 @@ public class Person extends Contact {
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (this == obj) {
return true;

View File

@@ -17,6 +17,7 @@ package org.springframework.data.mongodb.repository;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;
/**
@@ -40,7 +41,7 @@ public class UserWithComplexId {
}
@Override
public boolean equals(Object obj) {
public boolean equals(@Nullable Object obj) {
if (obj == this) {
return true;