Skip to content

Commit 00be19c

Browse files
committed
Consistently declare Object::equals argument as @nullable
1 parent a6dab10 commit 00be19c

File tree

74 files changed

+149
-103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+149
-103
lines changed

spring-aop/src/main/java/org/springframework/aop/aspectj/TypePatternClassFilter.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private String replaceBooleanOperators(String pcExpr) {
117117
}
118118

119119
@Override
120-
public boolean equals(Object obj) {
120+
public boolean equals(@Nullable Object obj) {
121121
return (this == obj || (obj instanceof TypePatternClassFilter that &&
122122
ObjectUtils.nullSafeEquals(this.typePattern, that.typePattern)));
123123
}

spring-aop/src/main/java/org/springframework/aop/support/RootClassFilter.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.Serializable;
2020

2121
import org.springframework.aop.ClassFilter;
22+
import org.springframework.lang.Nullable;
2223
import org.springframework.util.Assert;
2324

2425
/**
@@ -45,7 +46,7 @@ public boolean matches(Class<?> candidate) {
4546
}
4647

4748
@Override
48-
public boolean equals(Object obj) {
49+
public boolean equals(@Nullable Object obj) {
4950
return (this == obj || (obj instanceof RootClassFilter that &&
5051
this.clazz.equals(that.clazz)));
5152
}

spring-aop/src/main/java/org/springframework/aop/support/annotation/AnnotationMatchingPointcut.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public boolean matches(Class<?> clazz) {
183183
}
184184

185185
@Override
186-
public boolean equals(Object obj) {
186+
public boolean equals(@Nullable Object obj) {
187187
if (this == obj) {
188188
return true;
189189
}

spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/advice/MethodCounter.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24+
import org.springframework.lang.Nullable;
25+
2426
/**
2527
* Abstract superclass for counting advices etc.
2628
*
@@ -59,7 +61,7 @@ public int getCalls() {
5961
* @see java.lang.Object#equals(java.lang.Object)
6062
*/
6163
@Override
62-
public boolean equals(Object other) {
64+
public boolean equals(@Nullable Object other) {
6365
return (other != null && other.getClass() == this.getClass());
6466
}
6567

spring-aop/src/testFixtures/java/org/springframework/aop/testfixture/interceptor/NopInterceptor.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import org.aopalliance.intercept.MethodInterceptor;
2020
import org.aopalliance.intercept.MethodInvocation;
2121

22+
import org.springframework.lang.Nullable;
23+
2224
/**
2325
* Trivial interceptor that can be introduced in a chain to display it.
2426
*
@@ -45,14 +47,14 @@ public int getCount() {
4547

4648

4749
@Override
48-
public boolean equals(Object other) {
49-
if (!(other instanceof NopInterceptor)) {
50-
return false;
51-
}
52-
if (this == other) {
50+
public boolean equals(@Nullable Object obj) {
51+
if (this == obj) {
5352
return true;
5453
}
55-
return this.count == ((NopInterceptor) other).count;
54+
if (!(obj instanceof NopInterceptor that)) {
55+
return false;
56+
}
57+
return this.count == that.count;
5658
}
5759

5860
@Override

spring-aspects/src/test/java/org/springframework/cache/config/TestEntity.java

+4-8
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.cache.config;
1818

19+
import org.springframework.lang.Nullable;
1920
import org.springframework.util.ObjectUtils;
2021

2122
/**
@@ -45,16 +46,11 @@ public int hashCode() {
4546
}
4647

4748
@Override
48-
public boolean equals(Object obj) {
49+
public boolean equals(@Nullable Object obj) {
4950
if (obj == this) {
5051
return true;
5152
}
52-
if (obj == null) {
53-
return false;
54-
}
55-
if (obj instanceof TestEntity) {
56-
return ObjectUtils.nullSafeEquals(this.id, ((TestEntity) obj).id);
57-
}
58-
return false;
53+
return (obj instanceof TestEntity that && ObjectUtils.nullSafeEquals(this.id, that.id));
5954
}
55+
6056
}

spring-beans/src/test/java/org/springframework/beans/factory/DefaultListableBeanFactoryTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -2821,7 +2821,7 @@ public void setBeanName(String name) {
28212821
}
28222822

28232823
@Override
2824-
public boolean equals(Object o) {
2824+
public boolean equals(@Nullable Object o) {
28252825
if (this == o) {
28262826
return true;
28272827
}

spring-beans/src/test/java/org/springframework/beans/support/PagedListHolderTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.junit.jupiter.api.Test;
2323

2424
import org.springframework.beans.testfixture.beans.TestBean;
25+
import org.springframework.lang.Nullable;
2526

2627
import static org.assertj.core.api.Assertions.assertThat;
2728

@@ -194,7 +195,7 @@ public void setExtendedInfo(String extendedInfo) {
194195
}
195196

196197
@Override
197-
public boolean equals(Object o) {
198+
public boolean equals(@Nullable Object o) {
198199
if (this == o) {
199200
return true;
200201
}

spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/NestedTestBean.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.beans.testfixture.beans;
1818

19+
import org.springframework.lang.Nullable;
20+
1921
/**
2022
* Simple nested test bean used for testing bean factories, AOP framework etc.
2123
*
@@ -43,7 +45,7 @@ public String getCompany() {
4345
}
4446

4547
@Override
46-
public boolean equals(Object obj) {
48+
public boolean equals(@Nullable Object obj) {
4749
if (!(obj instanceof NestedTestBean ntb)) {
4850
return false;
4951
}

spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/Pet.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package org.springframework.beans.testfixture.beans;
1818

19+
import org.springframework.lang.Nullable;
20+
1921
/**
2022
* @author Rob Harrop
2123
* @since 2.0
@@ -38,7 +40,7 @@ public String toString() {
3840
}
3941

4042
@Override
41-
public boolean equals(Object o) {
43+
public boolean equals(@Nullable Object o) {
4244
if (this == o) {
4345
return true;
4446
}

spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/SerializablePerson.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.io.Serializable;
2020

21+
import org.springframework.lang.Nullable;
2122
import org.springframework.util.ObjectUtils;
2223

2324
/**
@@ -63,7 +64,7 @@ public Object echo(Object o) throws Throwable {
6364

6465

6566
@Override
66-
public boolean equals(Object other) {
67+
public boolean equals(@Nullable Object other) {
6768
if (!(other instanceof SerializablePerson p)) {
6869
return false;
6970
}

spring-beans/src/testFixtures/java/org/springframework/beans/testfixture/beans/TestBean.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.beans.factory.BeanFactory;
3131
import org.springframework.beans.factory.BeanFactoryAware;
3232
import org.springframework.beans.factory.BeanNameAware;
33+
import org.springframework.lang.Nullable;
3334
import org.springframework.util.ObjectUtils;
3435

3536
/**
@@ -464,7 +465,7 @@ public boolean wasDestroyed() {
464465

465466

466467
@Override
467-
public boolean equals(Object other) {
468+
public boolean equals(@Nullable Object other) {
468469
if (this == other) {
469470
return true;
470471
}

spring-context/src/main/java/org/springframework/scheduling/support/BitsCronField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ public int hashCode() {
256256
}
257257

258258
@Override
259-
public boolean equals(Object o) {
259+
public boolean equals(@Nullable Object o) {
260260
if (this == o) {
261261
return true;
262262
}

spring-context/src/main/java/org/springframework/scheduling/support/CompositeCronField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public int hashCode() {
7777
}
7878

7979
@Override
80-
public boolean equals(Object o) {
80+
public boolean equals(@Nullable Object o) {
8181
if (this == o) {
8282
return true;
8383
}

spring-context/src/main/java/org/springframework/scheduling/support/CronExpression.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ public int hashCode() {
273273
}
274274

275275
@Override
276-
public boolean equals(Object o) {
276+
public boolean equals(@Nullable Object o) {
277277
if (this == o) {
278278
return true;
279279
}

spring-context/src/main/java/org/springframework/scheduling/support/QuartzCronField.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ public int hashCode() {
359359
}
360360

361361
@Override
362-
public boolean equals(Object o) {
362+
public boolean equals(@Nullable Object o) {
363363
if (this == o) {
364364
return true;
365365
}

spring-context/src/test/java/org/springframework/aop/framework/AbstractAopProxyTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ public ITestBean getSpouse() {
16511651
public static class AllInstancesAreEqual implements IOther {
16521652

16531653
@Override
1654-
public boolean equals(Object other) {
1654+
public boolean equals(@Nullable Object other) {
16551655
return (other instanceof AllInstancesAreEqual);
16561656
}
16571657

spring-context/src/test/java/org/springframework/aop/framework/CglibProxyTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.springframework.context.ApplicationContext;
3636
import org.springframework.context.ApplicationContextException;
3737
import org.springframework.context.support.ClassPathXmlApplicationContext;
38+
import org.springframework.lang.Nullable;
3839

3940
import static org.assertj.core.api.Assertions.assertThat;
4041
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -214,7 +215,7 @@ public MethodMatcher getMethodMatcher() {
214215
return MethodMatcher.TRUE;
215216
}
216217
@Override
217-
public boolean equals(Object obj) {
218+
public boolean equals(@Nullable Object obj) {
218219
return true;
219220
}
220221
@Override

spring-context/src/test/java/org/springframework/aop/framework/JdkDynamicProxyTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.springframework.beans.testfixture.beans.IOther;
2828
import org.springframework.beans.testfixture.beans.ITestBean;
2929
import org.springframework.beans.testfixture.beans.TestBean;
30+
import org.springframework.lang.Nullable;
3031

3132
import static org.assertj.core.api.Assertions.assertThat;
3233
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -197,7 +198,7 @@ public String getName() {
197198
}
198199

199200
@Override
200-
public boolean equals(Object o) {
201+
public boolean equals(@Nullable Object o) {
201202
if (this == o) {
202203
return true;
203204
}

spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.springframework.context.testfixture.context.annotation.CglibConfiguration;
3838
import org.springframework.context.testfixture.context.annotation.LambdaBeanConfiguration;
3939
import org.springframework.core.ResolvableType;
40+
import org.springframework.lang.Nullable;
4041
import org.springframework.util.ObjectUtils;
4142

4243
import static java.lang.String.format;
@@ -732,7 +733,7 @@ public int hashCode() {
732733
}
733734

734735
@Override
735-
public boolean equals(Object obj) {
736+
public boolean equals(@Nullable Object obj) {
736737
if (this == obj) {
737738
return true;
738739
}

spring-context/src/test/java/org/springframework/context/event/test/AbstractIdentifiable.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import java.util.UUID;
2020

21+
import org.springframework.lang.Nullable;
22+
2123
/**
2224
* @author Stephane Nicoll
2325
*/
@@ -35,7 +37,7 @@ public String getId() {
3537
}
3638

3739
@Override
38-
public boolean equals(Object o) {
40+
public boolean equals(@Nullable Object o) {
3941
if (this == o) {
4042
return true;
4143
}

spring-context/src/test/java/org/springframework/context/event/test/GenericEventPojo.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import org.springframework.core.ResolvableType;
2020
import org.springframework.core.ResolvableTypeProvider;
21+
import org.springframework.lang.Nullable;
2122

2223
/**
2324
* A simple POJO that implements {@link ResolvableTypeProvider}.
@@ -37,7 +38,7 @@ public ResolvableType getResolvableType() {
3738
}
3839

3940
@Override
40-
public boolean equals(Object o) {
41+
public boolean equals(@Nullable Object o) {
4142
if (this == o) {
4243
return true;
4344
}

spring-context/src/test/java/org/springframework/context/event/test/IdentifiableApplicationEvent.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.util.UUID;
2020

2121
import org.springframework.context.ApplicationEvent;
22+
import org.springframework.lang.Nullable;
2223

2324
/**
2425
* A basic test event that can be uniquely identified easily.
@@ -49,7 +50,7 @@ public String getId() {
4950
}
5051

5152
@Override
52-
public boolean equals(Object o) {
53+
public boolean equals(@Nullable Object o) {
5354
if (this == o) {
5455
return true;
5556
}

spring-context/src/test/java/org/springframework/jmx/export/TestDynamicMBean.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import javax.management.MBeanNotificationInfo;
2626
import javax.management.MBeanOperationInfo;
2727

28+
import org.springframework.lang.Nullable;
29+
2830
/**
2931
* @author Rob Harrop
3032
* @author Juergen Hoeller
@@ -76,7 +78,7 @@ public MBeanInfo getMBeanInfo() {
7678
}
7779

7880
@Override
79-
public boolean equals(Object obj) {
81+
public boolean equals(@Nullable Object obj) {
8082
return (obj instanceof TestDynamicMBean);
8183
}
8284

spring-context/src/test/java/org/springframework/ui/ModelMapTests.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import org.springframework.aop.framework.ProxyFactory;
3131
import org.springframework.beans.testfixture.beans.TestBean;
32+
import org.springframework.lang.Nullable;
3233
import org.springframework.util.ClassUtils;
3334
import org.springframework.util.StringUtils;
3435

@@ -288,7 +289,7 @@ public void testRawJdkProxy() throws Exception {
288289
public static class SomeInnerClass {
289290

290291
@Override
291-
public boolean equals(Object obj) {
292+
public boolean equals(@Nullable Object obj) {
292293
return (obj instanceof SomeInnerClass);
293294
}
294295

0 commit comments

Comments
 (0)