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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 8 additions & 6 deletions
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

Lines changed: 4 additions & 8 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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

Lines changed: 3 additions & 1 deletion
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
}

0 commit comments

Comments
 (0)