Skip to content

Commit f0d870f

Browse files
authored
Add @Nullable to the parameter of equals(Object) (#2093)
Motivation: `Object.equals(Object)` accepts `null`, but many of our `equals()` implementations do not have `@Nullable` annotation on their parameters. Modifications: - Add `@Nullable` to the parameter of `equals(Object)` Result: - Better `null`-related inference
1 parent df3fde1 commit f0d870f

File tree

59 files changed

+104
-60
lines changed

Some content is hidden

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

59 files changed

+104
-60
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public final class MyClass {
212212
}
213213

214214
@Override
215-
public boolean equals(Object obj) {
215+
public boolean equals(@Nullable Object obj) {
216216
... usual type check ...
217217
// OK
218218
return name.equals(((MyClass) obj).name);

core/src/main/java/com/linecorp/armeria/client/ClientDecoration.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
import java.util.List;
2121
import java.util.function.Function;
2222

23+
import javax.annotation.Nullable;
24+
2325
import com.linecorp.armeria.common.Request;
2426
import com.linecorp.armeria.common.Response;
2527

@@ -113,7 +115,7 @@ Function<Client<I, O>, Client<I, O>> decorator() {
113115
}
114116

115117
@Override
116-
public boolean equals(Object o) {
118+
public boolean equals(@Nullable Object o) {
117119
if (this == o) {
118120
return true;
119121
}

core/src/main/java/com/linecorp/armeria/client/DefaultEventLoopScheduler.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
3030
import java.util.function.ToIntFunction;
3131

32+
import javax.annotation.Nullable;
33+
3234
import org.slf4j.Logger;
3335
import org.slf4j.LoggerFactory;
3436

@@ -262,7 +264,7 @@ public int hashCode() {
262264
}
263265

264266
@Override
265-
public boolean equals(Object obj) {
267+
public boolean equals(@Nullable Object obj) {
266268
if (this == obj) {
267269
return true;
268270
}

core/src/main/java/com/linecorp/armeria/client/Endpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ private static void validateWeight(int weight) {
643643
}
644644

645645
@Override
646-
public boolean equals(Object obj) {
646+
public boolean equals(@Nullable Object obj) {
647647
if (this == obj) {
648648
return true;
649649
}

core/src/main/java/com/linecorp/armeria/client/HttpChannelPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ static final class PoolKey {
551551
}
552552

553553
@Override
554-
public boolean equals(Object o) {
554+
public boolean equals(@Nullable Object o) {
555555
if (this == o) {
556556
return true;
557557
}

core/src/main/java/com/linecorp/armeria/client/circuitbreaker/EventCount.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.linecorp.armeria.client.circuitbreaker;
1818

19+
import javax.annotation.Nullable;
20+
1921
/**
2022
* An immutable object that stores the count of events.
2123
*/
@@ -99,7 +101,7 @@ public int hashCode() {
99101
}
100102

101103
@Override
102-
public boolean equals(Object o) {
104+
public boolean equals(@Nullable Object o) {
103105
if (this == o) {
104106
return true;
105107
}

core/src/main/java/com/linecorp/armeria/client/endpoint/dns/DnsQuestionWithoutTrailingDot.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
import java.net.IDN;
2121

22+
import javax.annotation.Nullable;
23+
2224
import io.netty.handler.codec.dns.DnsQuestion;
2325
import io.netty.handler.codec.dns.DnsRecordType;
2426

@@ -56,7 +58,7 @@ public long timeToLive() {
5658
}
5759

5860
@Override
59-
public boolean equals(Object o) {
61+
public boolean equals(@Nullable Object o) {
6062
if (this == o) {
6163
return true;
6264
}

core/src/main/java/com/linecorp/armeria/common/AbstractHttpData.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
package com.linecorp.armeria.common;
1818

19+
import javax.annotation.Nullable;
20+
1921
/**
2022
* Support APIs for creating well-behaved {@link HttpData} objects. {@link HttpData} generally should extend
2123
* {@link AbstractHttpData} to interact with other {@link HttpData} implementations, via, e.g., {@code equals}.
@@ -37,7 +39,7 @@ public int hashCode() {
3739
}
3840

3941
@Override
40-
public boolean equals(Object obj) {
42+
public boolean equals(@Nullable Object obj) {
4143
if (!(obj instanceof AbstractHttpData)) {
4244
return false;
4345
}

core/src/main/java/com/linecorp/armeria/common/AbstractRequestContext.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.function.Consumer;
2727
import java.util.function.Function;
2828

29+
import javax.annotation.Nullable;
30+
2931
import com.linecorp.armeria.common.util.SafeCloseable;
3032
import com.linecorp.armeria.server.DefaultServiceRequestContext;
3133

@@ -195,7 +197,7 @@ public final int hashCode() {
195197
}
196198

197199
@Override
198-
public final boolean equals(Object obj) {
200+
public final boolean equals(@Nullable Object obj) {
199201
return super.equals(obj);
200202
}
201203
}

core/src/main/java/com/linecorp/armeria/common/CacheControl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.linecorp.armeria.common;
1717

18+
import javax.annotation.Nullable;
19+
1820
/**
1921
* Directives for HTTP caching mechanisms in requests or responses. Use {@link ServerCacheControl} for
2022
* response-side and {@link ClientCacheControl} for request-side.
@@ -115,7 +117,7 @@ final StringBuilder newHeaderValueBuffer() {
115117
}
116118

117119
@Override
118-
public boolean equals(Object o) {
120+
public boolean equals(@Nullable Object o) {
119121
if (this == o) {
120122
return true;
121123
}

0 commit comments

Comments
 (0)