Skip to content

Commit 0750055

Browse files
authored
Added nullable annotations to org.asynchttpclient.filter package (#1875)
1 parent 8da2b18 commit 0750055

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

client/src/main/java/org/asynchttpclient/DefaultAsyncHttpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public <T> ListenableFuture<T> executeRequest(Request request, AsyncHandler<T> h
241241
if (noRequestFilters) {
242242
return execute(request, handler);
243243
} else {
244-
FilterContext<T> fc = new FilterContext.FilterContextBuilder<T>().asyncHandler(handler).request(request).build();
244+
FilterContext<T> fc = new FilterContext.FilterContextBuilder<>(handler, request).build();
245245
try {
246246
fc = preProcessRequest(fc);
247247
} catch (Exception e) {

client/src/main/java/org/asynchttpclient/filter/FilterContext.java

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

2122
import java.io.IOException;
2223

@@ -64,14 +65,14 @@ public Request getRequest() {
6465
/**
6566
* @return the unprocessed response's {@link HttpResponseStatus}
6667
*/
67-
public HttpResponseStatus getResponseStatus() {
68+
public @Nullable HttpResponseStatus getResponseStatus() {
6869
return builder.responseStatus;
6970
}
7071

7172
/**
7273
* @return the response {@link HttpHeaders}
7374
*/
74-
public HttpHeaders getResponseHeaders() {
75+
public @Nullable HttpHeaders getResponseHeaders() {
7576
return builder.headers;
7677
}
7778

@@ -85,19 +86,21 @@ public boolean replayRequest() {
8586
/**
8687
* @return the {@link IOException}
8788
*/
88-
public IOException getIOException() {
89+
public @Nullable IOException getIOException() {
8990
return builder.ioException;
9091
}
9192

9293
public static class FilterContextBuilder<T> {
9394
private AsyncHandler<T> asyncHandler;
9495
private Request request;
95-
private HttpResponseStatus responseStatus;
96+
private @Nullable HttpResponseStatus responseStatus;
9697
private boolean replayRequest;
97-
private IOException ioException;
98-
private HttpHeaders headers;
98+
private @Nullable IOException ioException;
99+
private @Nullable HttpHeaders headers;
99100

100-
public FilterContextBuilder() {
101+
public FilterContextBuilder(AsyncHandler<T> asyncHandler, Request request) {
102+
this.asyncHandler = asyncHandler;
103+
this.request = request;
101104
}
102105

103106
public FilterContextBuilder(FilterContext<T> clone) {

client/src/main/java/org/asynchttpclient/netty/handler/intercept/ResponseFiltersInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public boolean exitAfterProcessingFilters(Channel channel,
4343
HttpResponseStatus status,
4444
HttpHeaders responseHeaders) {
4545

46-
FilterContext fc = new FilterContext.FilterContextBuilder().asyncHandler(handler).request(future.getCurrentRequest()).responseStatus(status)
46+
FilterContext fc = new FilterContext.FilterContextBuilder(handler, future.getCurrentRequest()).responseStatus(status)
4747
.responseHeaders(responseHeaders).build();
4848

4949
for (ResponseFilter asyncFilter : config.getResponseFilters()) {

client/src/main/java/org/asynchttpclient/netty/request/NettyRequestSender.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,8 @@ public boolean applyIoExceptionFiltersAndReplayRequest(NettyResponseFuture<?> fu
501501

502502
boolean replayed = false;
503503
@SuppressWarnings({"unchecked", "rawtypes"})
504-
FilterContext<?> fc = new FilterContext.FilterContextBuilder().asyncHandler(future.getAsyncHandler())
505-
.request(future.getCurrentRequest()).ioException(e).build();
504+
FilterContext<?> fc = new FilterContext.FilterContextBuilder(future.getAsyncHandler(), future.getCurrentRequest())
505+
.ioException(e).build();
506506
for (IOExceptionFilter asyncFilter : config.getIoExceptionFilters()) {
507507
try {
508508
fc = asyncFilter.filter(fc);

client/src/test/java/org/asynchttpclient/filter/FilterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public void replayResponseFilterTest() throws Exception {
105105
public <T> FilterContext<T> filter(FilterContext<T> ctx) {
106106
if (replay.getAndSet(false)) {
107107
org.asynchttpclient.Request request = ctx.getRequest().toBuilder().addHeader("X-Replay", "true").build();
108-
return new FilterContext.FilterContextBuilder<T>().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build();
108+
return new FilterContext.FilterContextBuilder<T>(ctx.getAsyncHandler(), request).replayRequest(true).build();
109109
}
110110
return ctx;
111111
}
@@ -128,7 +128,7 @@ public void replayStatusCodeResponseFilterTest() throws Exception {
128128
public <T> FilterContext<T> filter(FilterContext<T> ctx) {
129129
if (ctx.getResponseStatus() != null && ctx.getResponseStatus().getStatusCode() == 200 && replay.getAndSet(false)) {
130130
org.asynchttpclient.Request request = ctx.getRequest().toBuilder().addHeader("X-Replay", "true").build();
131-
return new FilterContext.FilterContextBuilder<T>().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build();
131+
return new FilterContext.FilterContextBuilder<T>(ctx.getAsyncHandler(), request).replayRequest(true).build();
132132
}
133133
return ctx;
134134
}
@@ -150,7 +150,7 @@ public void replayHeaderResponseFilterTest() throws Exception {
150150
public <T> FilterContext<T> filter(FilterContext<T> ctx) {
151151
if (ctx.getResponseHeaders() != null && "Pong".equals(ctx.getResponseHeaders().get("Ping")) && replay.getAndSet(false)) {
152152
org.asynchttpclient.Request request = ctx.getRequest().toBuilder().addHeader("Ping", "Pong").build();
153-
return new FilterContext.FilterContextBuilder<T>().asyncHandler(ctx.getAsyncHandler()).request(request).replayRequest(true).build();
153+
return new FilterContext.FilterContextBuilder<T>(ctx.getAsyncHandler(), request).replayRequest(true).build();
154154
}
155155
return ctx;
156156
}

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231
-Xep:NullablePrimitive:ERROR
232232
-Xep:NullOptional:ERROR
233233
-XepExcludedPaths:.*/src/test/java/.*
234-
-XepOpt:NullAway:AnnotatedPackages=org.asynchttpclient.channel,org.asynchttpclient.config,org.asynchttpclient.cookie,org.asynchttpclient.exception
234+
-XepOpt:NullAway:AnnotatedPackages=org.asynchttpclient.channel,org.asynchttpclient.config,org.asynchttpclient.cookie,org.asynchttpclient.exception,org.asynchttpclient.filter
235235
-XepOpt:NullAway:AcknowledgeRestrictiveAnnotations=true
236236
-Xep:NullAway:ERROR
237237
</arg>

0 commit comments

Comments
 (0)