question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

route parameter of authenticate can be null but is not marked as @Nullable

See original GitHub issue

Here 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:closed
  • Created 5 years ago
  • Comments:14 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
technoir42commented, Oct 11, 2018

@hardysim in Kotlin you can just replace route: Route with route: Route?.

0reactions
idrisadetunmbicommented, Jan 27, 2019

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found