Android 当服务器拒绝连接时,带缓存的Websocket排队会产生崩溃
设置 导致此异常不可能被捕获:Android 当服务器拒绝连接时,带缓存的Websocket排队会产生崩溃,android,websocket,okhttp,Android,Websocket,Okhttp,设置 导致此异常不可能被捕获: File cacheDirectory = new File(app.getCacheDir(), "network_cache"); if (!cacheDirectory.exists()) { cacheDirectory.mkdir(); } Cache cache = new Cache(cacheDirectory, CACHE_MAX_SIZE); OkHttpC
File cacheDirectory = new File(app.getCacheDir(), "network_cache");
if (!cacheDirectory.exists()) {
cacheDirectory.mkdir();
}
Cache cache = new Cache(cacheDirectory, CACHE_MAX_SIZE);
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.networkInterceptors().add(new StethoInterceptor());
okHttpClient.setCache(cache);
这发生在OKHTTP2.5和OKHTTPWS2.5中。使用OKHTTP2.4和OKHTTPWS2.4,我们得到了一个没有stacktrace的崩溃
已创建问题:删除缓存可修复该问题
Process: xx.xx.xx.debug, PID: 8227
java.lang.NullPointerException: Attempt to invoke virtual method 'okio.BufferedSource com.squareup.okhttp.ResponseBody.source()' on a null object reference
at com.squareup.okhttp.internal.http.HttpEngine.cacheWritingResponse(HttpEngine.java:935)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:821)
at com.squareup.okhttp.Call.getResponse(Call.java:268)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:224)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:195)
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:1112)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
at java.lang.Thread.run(Thread.java:818)
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.networkInterceptors().add(new StethoInterceptor());