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.

java.lang.NullPointerException in CacheControl

See original GitHub issue
Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equalsIgnoreCase(java.lang.String)' on a null object reference
       at okhttp3.CacheControl.parse(CacheControl.java:173)
       at okhttp3.Request.cacheControl(Request.java:83)
       at okhttp3.internal.cache.CacheStrategy$Factory.get(CacheStrategy.java:175)
       at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.java:59)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:93)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:125)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
       at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
       at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:200)
       at okhttp3.RealCall$AsyncCall.execute(RealCall.java:147)
       at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)

I had the exception in fabric. I check my project code, it may be found using a single instance of each request, I’m not too sure.

This is the official demo.

private final OkHttpClient client = new OkHttpClient();
 Request request = new Request.Builder() 
        .url("https://api.github.com/markdown/raw")
        .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, postBody))
        .build();
    try (Response response = client.newCall(request).execute()) {
      if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);

      Headers responseHeaders = response.headers();
      for (int i = 0; i < responseHeaders.size(); i++) {
        System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
      }
      System.out.println(response.body().string());
    }

and i replace new Request.Builder() to getRequestBuilder().

 private static Request.Builder requestBuilder;
  public synchronized Request.Builder getRequestBuilder() {
        if (requestBuilder == null) {
            requestBuilder = new Request.Builder();
        }
        return requestBuilder;
    }

and I want to sure the Request object can use a Singleton Pattern when run request.Ths.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yschimkecommented, Dec 29, 2021

I suspect from the original report, “new Request.Builder() to getRequestBuilder()” the Request.Builder is being reused, probably in multiple threads? Are you creating a fresh Request.Builder on each request?

0reactions
ferdinandtaishevcommented, Dec 29, 2021

got this issue in 4.9.1 okhttp version. also we have null pointer in Http1ExchangeCodec. It seems to be the same problem with null header key

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException when getting Image Cache
I experienced this issue and discovered my AVD emulator was not configured correctly. Specifically, the null pointer is due to the lack of ......
Read more >
NullPointerException during space import due to cache ...
We are hitting into this issue of java.lang.NullPointerException due for cache management. This appears to be caused by corrupted caches on the ...
Read more >
57579 – NullPointerException error is raised on main sample ...
lang.Thread.run(Thread.java:745) Expected: No error is shown, no sample is recorded. Workaround: If you change the behavior of JMeter cache ...
Read more >
Apache Atlas Import Error - Cloudera Community - 235985
Now, when I try to import data (on the same Atlas instance where I exported data from) I get an Null Pointer Exception...
Read more >
NullPointerException when using REST to deploy remote ...
NullPointerException when using REST to deploy remote Docker instances via ... image with Liberty I am getting an exception: Error 500: java.lang.
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