Skip to content

Commit f25d32b

Browse files
authored
Add nullness annotations to org.asynchttpclient.channel (#1873)
1 parent 8046826 commit f25d32b

File tree

4 files changed

+24
-7
lines changed

4 files changed

+24
-7
lines changed

client/src/main/java/org/asynchttpclient/channel/ChannelPool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.asynchttpclient.channel;
1717

1818
import io.netty.channel.Channel;
19+
import org.jetbrains.annotations.Nullable;
1920

2021
import java.util.Map;
2122
import java.util.function.Predicate;
@@ -37,7 +38,7 @@ public interface ChannelPool {
3738
* @param partitionKey the partition used when invoking offer
3839
* @return the channel associated with the uri
3940
*/
40-
Channel poll(Object partitionKey);
41+
@Nullable Channel poll(Object partitionKey);
4142

4243
/**
4344
* Remove all channels from the cache. A channel might have been associated

client/src/main/java/org/asynchttpclient/channel/ChannelPoolPartitioning.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.asynchttpclient.proxy.ProxyServer;
1919
import org.asynchttpclient.proxy.ProxyType;
2020
import org.asynchttpclient.uri.Uri;
21+
import org.jetbrains.annotations.Nullable;
2122

2223
import java.util.Objects;
2324

@@ -31,7 +32,7 @@ enum PerHostChannelPoolPartitioning implements ChannelPoolPartitioning {
3132
INSTANCE;
3233

3334
@Override
34-
public Object getPartitionKey(Uri uri, String virtualHost, ProxyServer proxyServer) {
35+
public Object getPartitionKey(Uri uri, @Nullable String virtualHost, @Nullable ProxyServer proxyServer) {
3536
String targetHostBaseUrl = uri.getBaseUrl();
3637
if (proxyServer == null) {
3738
if (virtualHost == null) {
@@ -59,12 +60,13 @@ public Object getPartitionKey(Uri uri, String virtualHost, ProxyServer proxyServ
5960

6061
class CompositePartitionKey {
6162
private final String targetHostBaseUrl;
62-
private final String virtualHost;
63-
private final String proxyHost;
63+
private final @Nullable String virtualHost;
64+
private final @Nullable String proxyHost;
6465
private final int proxyPort;
65-
private final ProxyType proxyType;
66+
private final @Nullable ProxyType proxyType;
6667

67-
CompositePartitionKey(String targetHostBaseUrl, String virtualHost, String proxyHost, int proxyPort, ProxyType proxyType) {
68+
CompositePartitionKey(String targetHostBaseUrl, @Nullable String virtualHost,
69+
@Nullable String proxyHost, int proxyPort, @Nullable ProxyType proxyType) {
6870
this.targetHostBaseUrl = targetHostBaseUrl;
6971
this.virtualHost = virtualHost;
7072
this.proxyHost = proxyHost;

client/src/main/java/org/asynchttpclient/channel/NoopChannelPool.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.asynchttpclient.channel;
1717

1818
import io.netty.channel.Channel;
19+
import org.jetbrains.annotations.Nullable;
1920

2021
import java.util.Collections;
2122
import java.util.Map;
@@ -31,7 +32,7 @@ public boolean offer(Channel channel, Object partitionKey) {
3132
}
3233

3334
@Override
34-
public Channel poll(Object partitionKey) {
35+
public @Nullable Channel poll(Object partitionKey) {
3536
return null;
3637
}
3738

pom.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,11 @@
200200
<artifactId>jakarta.activation</artifactId>
201201
<version>${activation.version}</version>
202202
</dependency>
203+
<dependency>
204+
<groupId>org.jetbrains</groupId>
205+
<artifactId>annotations</artifactId>
206+
<version>24.0.1</version>
207+
</dependency>
203208
</dependencies>
204209

205210
<build>
@@ -226,6 +231,9 @@
226231
-Xep:NullablePrimitive:ERROR
227232
-Xep:NullOptional:ERROR
228233
-XepExcludedPaths:.*/src/test/java/.*
234+
-XepOpt:NullAway:AnnotatedPackages=org.asynchttpclient.channel
235+
-XepOpt:NullAway:AcknowledgeRestrictiveAnnotations=true
236+
-Xep:NullAway:ERROR
229237
</arg>
230238
</compilerArgs>
231239
<annotationProcessorPaths>
@@ -234,6 +242,11 @@
234242
<artifactId>error_prone_core</artifactId>
235243
<version>2.18.0</version>
236244
</path>
245+
<path>
246+
<groupId>com.uber.nullaway</groupId>
247+
<artifactId>nullaway</artifactId>
248+
<version>0.10.10</version>
249+
</path>
237250
<!-- Other annotation processors go here -->
238251
</annotationProcessorPaths>
239252
</configuration>

0 commit comments

Comments
 (0)