Skip to content

Commit de8d88b

Browse files
authored
Enabled NullAway for "handler" package (#1879)
1 parent 1070093 commit de8d88b

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

client/src/main/java/org/asynchttpclient/handler/BodyDeferringAsyncHandler.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.asynchttpclient.HttpResponseBodyPart;
1818
import org.asynchttpclient.HttpResponseStatus;
1919
import org.asynchttpclient.Response;
20+
import org.jetbrains.annotations.Nullable;
2021

2122
import java.io.FilterInputStream;
2223
import java.io.IOException;
@@ -88,8 +89,8 @@ public class BodyDeferringAsyncHandler implements AsyncHandler<Response> {
8889
private final OutputStream output;
8990
private final Semaphore semaphore = new Semaphore(1);
9091
private boolean responseSet;
91-
private volatile Response response;
92-
private volatile Throwable throwable;
92+
private volatile @Nullable Response response;
93+
private volatile @Nullable Throwable throwable;
9394

9495
public BodyDeferringAsyncHandler(final OutputStream os) {
9596
output = os;
@@ -166,7 +167,7 @@ protected void closeOut() throws IOException {
166167
}
167168

168169
@Override
169-
public Response onCompleted() throws IOException {
170+
public @Nullable Response onCompleted() throws IOException {
170171

171172
if (!responseSet) {
172173
response = responseBuilder.build();
@@ -217,7 +218,7 @@ public Response onCompleted() throws IOException {
217218
* @throws InterruptedException if the latch is interrupted
218219
* @throws IOException if the handler completed with an exception
219220
*/
220-
public Response getResponse() throws InterruptedException, IOException {
221+
public @Nullable Response getResponse() throws InterruptedException, IOException {
221222
// block here as long as headers arrive
222223
headersArrived.await();
223224

@@ -278,7 +279,7 @@ public void close() throws IOException {
278279
* @throws InterruptedException if the latch is interrupted
279280
* @throws IOException if the handler completed with an exception
280281
*/
281-
public Response getAsapResponse() throws InterruptedException, IOException {
282+
public @Nullable Response getAsapResponse() throws InterruptedException, IOException {
282283
return bdah.getResponse();
283284
}
284285

client/src/main/java/org/asynchttpclient/handler/TransferCompletionHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.asynchttpclient.AsyncHandler;
1818
import org.asynchttpclient.HttpResponseBodyPart;
1919
import org.asynchttpclient.Response;
20+
import org.jetbrains.annotations.Nullable;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223

@@ -59,7 +60,7 @@ public class TransferCompletionHandler extends AsyncCompletionHandlerBase {
5960

6061
private final ConcurrentLinkedQueue<TransferListener> listeners = new ConcurrentLinkedQueue<>();
6162
private final boolean accumulateResponseBytes;
62-
private HttpHeaders headers;
63+
private @Nullable HttpHeaders headers;
6364

6465
/**
6566
* Create a TransferCompletionHandler that will not accumulate bytes. The resulting {@link Response#getResponseBody()},
@@ -116,7 +117,7 @@ public State onBodyPartReceived(final HttpResponseBodyPart content) throws Excep
116117
}
117118

118119
@Override
119-
public Response onCompleted(Response response) throws Exception {
120+
public @Nullable Response onCompleted(@Nullable Response response) throws Exception {
120121
fireOnEnd();
121122
return response;
122123
}

client/src/main/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandler.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import org.asynchttpclient.Response;
2222
import org.asynchttpclient.Response.ResponseBuilder;
2323
import org.asynchttpclient.handler.TransferCompletionHandler;
24+
import org.jetbrains.annotations.Nullable;
2425
import org.slf4j.Logger;
2526
import org.slf4j.LoggerFactory;
2627

2728
import java.io.IOException;
2829
import java.nio.ByteBuffer;
30+
import java.util.Collections;
2931
import java.util.HashMap;
3032
import java.util.Map;
3133
import java.util.concurrent.ConcurrentLinkedQueue;
@@ -47,18 +49,18 @@
4749
public class ResumableAsyncHandler implements AsyncHandler<Response> {
4850
private static final Logger logger = LoggerFactory.getLogger(TransferCompletionHandler.class);
4951
private static final ResumableIndexThread resumeIndexThread = new ResumableIndexThread();
50-
private static Map<String, Long> resumableIndex;
52+
private static Map<String, Long> resumableIndex = Collections.emptyMap();
5153

5254
private final AtomicLong byteTransferred;
5355
private final ResumableProcessor resumableProcessor;
54-
private final AsyncHandler<Response> decoratedAsyncHandler;
56+
private final @Nullable AsyncHandler<Response> decoratedAsyncHandler;
5557
private final boolean accumulateBody;
56-
private String url;
58+
private String url = "";
5759
private final ResponseBuilder responseBuilder = new ResponseBuilder();
5860
private ResumableListener resumableListener = new NULLResumableListener();
5961

60-
private ResumableAsyncHandler(long byteTransferred, ResumableProcessor resumableProcessor,
61-
AsyncHandler<Response> decoratedAsyncHandler, boolean accumulateBody) {
62+
private ResumableAsyncHandler(long byteTransferred, @Nullable ResumableProcessor resumableProcessor,
63+
@Nullable AsyncHandler<Response> decoratedAsyncHandler, boolean accumulateBody) {
6264

6365
this.byteTransferred = new AtomicLong(byteTransferred);
6466

@@ -152,7 +154,7 @@ public State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception
152154
}
153155

154156
@Override
155-
public Response onCompleted() throws Exception {
157+
public @Nullable Response onCompleted() throws Exception {
156158
resumableProcessor.remove(url);
157159
resumableListener.onAllBytesReceived();
158160

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@
233233
-Xep:NullOptional:ERROR
234234
-XepExcludedPaths:.*/src/test/java/.*
235235
-XepOpt:NullAway:AnnotatedPackages=org.asynchttpclient
236-
-XepOpt:NullAway:UnannotatedSubPackages=org.asynchttpclient.handler,org.asynchttpclient.netty,org.asynchttpclient.ntlm,org.asynchttpclient.request,org.asynchttpclient.spnego,org.asynchttpclient.uri,org.asynchttpclient.util,org.asynchttpclient.webdav,org.asynchttpclient.ws
236+
-XepOpt:NullAway:UnannotatedSubPackages=org.asynchttpclient.netty,org.asynchttpclient.ntlm,org.asynchttpclient.request,org.asynchttpclient.spnego,org.asynchttpclient.uri,org.asynchttpclient.util,org.asynchttpclient.webdav,org.asynchttpclient.ws
237237
-XepOpt:NullAway:AcknowledgeRestrictiveAnnotations=true
238238
-Xep:NullAway:ERROR
239239
</arg>

0 commit comments

Comments
 (0)