From 9629b694eb562fdcb5b384587112f4eeba806990 Mon Sep 17 00:00:00 2001 From: tom79 Date: Sun, 15 Dec 2019 17:34:34 +0100 Subject: [PATCH] Some fixes --- .../app/fedilab/android/client/HttpsConnection.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java index 6ca2d2354..bfc3a42a8 100644 --- a/app/src/main/java/app/fedilab/android/client/HttpsConnection.java +++ b/app/src/main/java/app/fedilab/android/client/HttpsConnection.java @@ -321,7 +321,8 @@ public class HttpsConnection { public String get(String urlConnection) throws IOException, NoSuchAlgorithmException, KeyManagementException, HttpsConnectionException { if (Build.VERSION.SDK_INT >= 21) { - OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).cache(new Cache(context.getCacheDir(), cacheSize)); + Cache cache = new Cache(context.getCacheDir(), cacheSize); + OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).cache(cache); if (proxy != null) { builder.proxy(proxy); } @@ -347,6 +348,14 @@ public class HttpsConnection { } else { throw new HttpsConnectionException(code, error); } + }finally { + if (!cache.isClosed()) { + try { + cache.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } } } else {