route parameter of authenticate can be null but is not marked as @Nullable
See original GitHub issueHere is a test proving that route
can be null
(I’m using 3.11.0):
import org.junit.Test;
import okhttp3.Authenticator;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
public class AuthenticatorTest {
@Test
public void routeCanBeNull() throws Exception {
Authenticator authenticator = new Authenticator() {
@Override
public Request authenticate(Route route, Response response) {
if (route == null) {
throw new NullPointerException("route is null");
}
return null;
}
};
OkHttpClient client = new OkHttpClient.Builder()
.authenticator(authenticator)
.build();
Request request = new Request.Builder()
.url("https://httpbin.org/status/401")
.build();
client.newCall(request).execute(); // route is not null
client.newCall(request).execute(); // route is null
}
}
I’m not sure if it is a correct behaviour. If it is actually correct I’ll make a PR adding @Nullable
to route
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:14 (3 by maintainers)
Top Results From Across the Web
Entity Framework Core: `SqlNullValueException: Data is Null ...
The error message indicates that EF Core is trying to read string value for a required property, i.e. a property which should never...
Read more >Using Optional and Nullable Properties in API Requests
Learn how optional and nullable properties can be used flexibly in combinations in each parameter of your API requests made from a SDK....
Read more >Java static code analysis: Nullness of parameters should be ...
The rule raises an issue every time a parameter could be null for a method invocation, where the method is annotated as forbidding...
Read more >Nulls in GraphQL: Cheatsheet - Hasura
Nulls in the query A GraphQL query can have fields and inputs, with or without variables. Fields are always optional, whether nullable or...
Read more >Resolve nullable warnings | Microsoft Learn
Several compiler warnings indicate code that isn't null-safe. ... CS8631 - The type cannot be used as type parameter in the generic type...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hardysim in Kotlin you can just replace
route: Route
withroute: Route?
.@swankjesse @yschimke, Please I would like to know how I can reproduce this bug manually. A project I am working on includes an authenticator in the client set up, and this bug was encountered because of some intermittent failures from the server. I would like to know the kind of server response that could cause this to happen if I don’t mark the route as
@Nullable