2

I'm using Retrofit to do some requests to web services, but until recently everything went wrong and I started getting the exception mentioned in the title. I have a base class which basically looks like this:

protected BaseService(int version) {
    OkHttpClient.Builder builder = new OkHttpClient.Builder();

    if (cookieJar == null) {
        CookieManager cookieManager = new CookieManager();
        cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
        cookieJar = new JavaNetCookieJar(cookieManager);
    }

    builder.cookieJar(cookieJar);

    if (BuildConfig.IS_DEBUG) {
        BASE_URL = "http://nasko.dev.trainingassetsgateway.com";

        builder.interceptors().add(new Interceptor() {
            @Override
            public Response intercept(Interceptor.Chain chain) throws IOException {
                Request newRequest = chain
                        .request()
                        .newBuilder()
                        .addHeader("Authorization", "Basic REMOVED")
                        .build();

                return chain.proceed(newRequest);
            }
        });

    } else {
        BASE_URL = "https://trainingassetsgateway.com";
    }

    API_URL = BASE_URL + "/mapi/" + version + "/";

    client = new Retrofit
            .Builder()
            .baseUrl(API_URL)
            .client(okHttpClient = builder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .build();
}

The problem starts in the interceptor chain. I've traced it to the HttpEngine.createAddress method where a new instance of Address is being created.

createAddress from debugger

As seen the host part of the URL is there, but later on in the next call in the stack the "uriHost" is null, while it should have been the same thing that is seen in the "Watches" window.

uriHost is null from debugger

From there it reaches the point where the host is null and the exception is thrown. Am I doing something wrong or maybe missing something?

atanaspl
  • 41
  • 3

1 Answers1

0

If someone ever comes into this just delete the app on the phone. I wish I did this sooner...

atanaspl
  • 41
  • 3