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.IllegalStateException: closed when attempting to reference response body after interception

See original GitHub issue

📢 Describe the bug

As mentioned in https://github.com/ChuckerTeam/chucker/pull/165#issuecomment-576393906, I needed to revert that diff in order to keep my app working.

I have several interceptors, a network interceptor, gson data adapter and rxjava2 call adapters setup and I use retrofit 1.7.1 and okhttp 3.14.6.

This might be something affecting just my specific setup, but wanted to document here in case anyone else is experiencing the issue. Copy/pasting my comment from PR #165 below, thanks!

Hey all, just a heads up as I was testing the develop branch within my app today. I had to revert the commit associated with this change since I was getting errors in the GsonResponseBodyConverter retrofit converter stage where it apparently tries to read the response but it has already been closed by the chucker interceptor by this change.

Caused by: java.lang.IllegalStateException: closed
        at okio.RealBufferedSource.read(RealBufferedSource.java:48)
        at okio.ForwardingSource.read(ForwardingSource.java:35)
        at retrofit2.OkHttpCall$ExceptionCatchingResponseBody$1.read(OkHttpCall.java:296)
        at okio.RealBufferedSource.select(RealBufferedSource.java:100)
        at okhttp3.internal.Util.bomAwareCharset(Util.java:467)
        at okhttp3.ResponseBody$BomAwareReader.read(ResponseBody.java:260)
        at com.google.gson.stream.JsonReader.fillBuffer(JsonReader.java:1291)
        at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1329)
        at com.google.gson.stream.JsonReader.consumeNonExecutePrefix(JsonReader.java:1572)
        at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:535)
        at com.google.gson.stream.JsonReader.peek(JsonReader.java:426)
        at com.google.gson.internal.bind.ObjectTypeAdapter.read(ObjectTypeAdapter.java:55)
        at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:39)
        at retrofit2.converter.gson.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:27)
        at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:223)
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:186)
        at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:45)
        at io.reactivex.Observable.subscribe(Observable.java:12267) 
        at retrofit2.adapter.rxjava2.BodyObservable.subscribeActual(BodyObservable.java:34) 
        at io.reactivex.Observable.subscribe(Observable.java:12267) 
        at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96) 
        at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578) 
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66) 
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57) 
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) 
        at java.lang.Thread.run(Thread.java:919)

This was using retrofit 1.7.1 and okhttp 3.14.6.

The result of this error was that none of the JSON API responses were parsed in my app, essentially preventing the app from working.

Let me know if any others experienced the same, thanks!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kmayoralcommented, Jan 27, 2020

Apologies for the delay here, I was able to test this out and it works as expected, thank you @vbuberen and @cortinico!

0reactions
vbuberencommented, Jan 21, 2020

@kmayoral When you have time, please check latest develop-SNAPSHOT - just merged the fix for this issue from @cortinico

Read more comments on GitHub >

github_iconTop Results From Across the Web

Retrofit : java.lang.IllegalStateException: closed - Stack Overflow
According to retrofit document, if we call any of below method then response will be closed, which means it's not available to consume...
Read more >
Web on Servlet Stack - Spring
This model is flexible and supports diverse workflows. The DispatcherServlet , as any Servlet , needs to be declared and mapped according to...
Read more >
Retrofit : Java.Lang.Illegalstateexception: Closed - ADocLib
Both this class and Response implement Closeable. Closing a response simply closes its response body. If you invoke Call.execute or implement Callback.
Read more >
How to Fix The IllegalStateException in Java - Rollbar
An IllegalStateException is a runtime exception in Java that is thrown to indicate that a method has been invoked at the wrong time....
Read more >
Fix list for IBM WebSphere Application Server V8.5
The following is a complete listing of fixes for V8.5 with the most recent fix at the ... PH43960, Java.lang.classformaterror: jvmcfre106 duplicate method; ......
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