Иногда я получаю это исключение SctrictMode:
2019-01-28 14:18:23.073 4597-4615/my.app.package E/StrictMode: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'end' not called
at dalvik.system.CloseGuard.open(CloseGuard.java:223)
at java.util.zip.Inflater.<init>(Inflater.java:106)
at okio.GzipSource.<init>(GzipSource.java:62)
at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.java:103)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.java:126)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at okhttp3.logging.HttpLoggingInterceptor.intercept(HttpLoggingInterceptor.java:213)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:147)
at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.java:121)
at my.app.package.api.network.SetJsonContentTypeHeaderInterceptor.intercept(SetJsonContentTypeHeaderInterceptor.kt:15)
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:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Единственная часть из упомянутого в коде исключения, принадлежащая моему приложению, это SetJsonContentTypeHeaderInterceptor
:
import okhttp3.Interceptor
internal class SetJsonContentTypeHeaderInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain) =
chain.request()
.let {
it.newBuilder()
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.build()
}
.let { chain.proceed(it) }!!
}
Библиотекиверсии, используемые в приложении:
okHttp: 3.11.0
Модификация: 2.4.0
В чем причина и как ее исправить?