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.

StackOverflowError when add a networkInterceptors

See original GitHub issue

java.lang.StackOverflowError at java.lang.ThreadLocal.get(ThreadLocal.java:53) at dalvik.system.BlockGuard.getThreadPolicy(BlockGuard.java:140) at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:163) at libcore.io.IoBridge.recvfrom(IoBridge.java:513) at java.net.PlainSocketImpl.read(PlainSocketImpl.java:488) at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46) at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240) at okio.Okio$2.read(Okio.java:139) at okio.AsyncTimeout$2.read(AsyncTimeout.java:211) at okio.RealBufferedSource.indexOf(RealBufferedSource.java:306) at okio.RealBufferedSource.indexOf(RealBufferedSource.java:300) at okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:196) at com.squareup.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:191) at com.squareup.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:79) at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:909) at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:93) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:894) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.library_http.RequestInterceptor.intercept(RequestInterceptor.java:27) at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:867) at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:748) at com.squareup.okhttp.Call.getResponse(Call.java:277) at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:234) at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:196) at com.squareup.okhttp.Call.access$100(Call.java:34) at com.squareup.okhttp.Call$AsyncCall.execute(Call.java:162) at com.squareup.okhttp.internal.NamedRunnable.run(NamedRunnable.java:33) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:856)

the method in the HttpEngine and the RequestInterceptor chain.proceed() call each other

i add interceptor below this

mOkHttpClient.networkInterceptors().add(new RequestInterceptor(ctx));

this is the code of interceptor `public class RequestInterceptor implements Interceptor { private Context mCtx;

public RequestInterceptor(Context ctx) {
    mCtx = ctx;
}

@Override
public Response intercept(Chain chain) throws IOException {
    Request originalRequest = chain.request();
    if (originalRequest.body() == null) {
        return chain.proceed(originalRequest);
    }
    String url = originalRequest.urlString();
    if (!url.contains("distinctRequestId=")) {
        String requestId = OkHttpClientManager.getDistinctRequestId();
        if (url.contains("?")) {
            url = originalRequest.urlString() + "&distinctRequestId=" + requestId;
        } else {
            url = originalRequest.urlString() + "?distinctRequestId=" + requestId;
        }
        url = url + "&p=" + PreferenceUtils.getRequestId(mCtx) + "&span=" + PreferenceUtils.getConnectTime(mCtx);
        PreferenceUtils.setRequestId(mCtx, requestId);
        Request compressedRequest = originalRequest.newBuilder()
                .url(url)
                .build();
        return chain.proceed(compressedRequest);
    }
    return chain.proceed(originalRequest);
}

} `

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:28 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
XiaomeiZengcommented, Aug 4, 2016

Looks like the error I reported above can be fixed by clearing interceptors every time (thanks for chrisstewart comments above). I have run the following code more than one hour and there is no StackOverflowError any more.

Add code (Kotlin): httpClient.interceptors().clear()

The the code as following: ` private val httpClient = OkHttpClient.Builder() fun createService(serviceClass: Class, username: String?, password: String?): S? {

///////////////////////////new code if (httpClient.interceptors().isNotEmpty()) { httpClient.interceptors().clear() } ////////////////////////////////new code

val credential = Credentials.basic(username, password) val interceptor = Interceptor { chain -> val original = chain.request() val requestBuilder = original.newBuilder() .header(“Authorization”, credential) .header(“Accept”, “application/json”) .header(“Content-Type”, “application/json”) .method(original.method(), original.body()) val request = requestBuilder.build() chain.proceed(request) } httpClient.addInterceptor(interceptor) val retrofit = Retrofit.Builder().baseUrl(IEventConstant.baseUrl).addConverterFactory(GsonConverterFactory.create()).client(httpClient.build()).build()

return retrofit.create(serviceClass) } `

0reactions
scsfwgycommented, Jun 21, 2018

@XiaomeiZeng The solution of clearing interceptors maybe create a lot of repetitive same interceptors…,can be same better solution? @swankjesse

Read more comments on GitHub >

github_iconTop Results From Across the Web

Okhttp3: Add global header to all requests error - Stack Overflow
According to the documentation httpClient.networkInterceptors(). Returns an immutable list of interceptors that observe a single network ...
Read more >
Use of "async" calls eventually causes StackoverflowErrors ...
Use of "async" calls eventually causes StackoverflowErrors due to unbounded growth of networkInterceptors in OkHttpClient.
Read more >
How to Fix java.lang.StackOverflowError in Java - Rollbar
StackOverflowError indicates that the application stack is exhausted and is usually caused by deep or infinite recursion. What Causes java.lang.
Read more >
okhttp3.OkHttpClient.networkInterceptors java code examples
origin: stackoverflow.com ... networkInterceptors().add(new UserAgentInterceptor("foo/bar")); Request testRequest = new Request.Builder().url(url).build() ...
Read more >
Interceptors - OkHttp
Interceptors are registered as either application or network interceptors. ... For example, you can use an application interceptor to add request body ...
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