From 4a242c7a9191411414c10e8637af72c2b9bec5e9 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 14 Sep 2023 16:57:22 +0200 Subject: [PATCH] refactor: Use try block for auto closeable --- .../twitch/adblock/PurpleAdblockService.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/app/revanced/twitch/adblock/PurpleAdblockService.java b/app/src/main/java/app/revanced/twitch/adblock/PurpleAdblockService.java index 5b2db973..07e47dca 100644 --- a/app/src/main/java/app/revanced/twitch/adblock/PurpleAdblockService.java +++ b/app/src/main/java/app/revanced/twitch/adblock/PurpleAdblockService.java @@ -1,14 +1,13 @@ package app.revanced.twitch.adblock; -import java.util.HashMap; -import java.util.Map; - import app.revanced.twitch.api.RetrofitClient; import app.revanced.twitch.utils.LogHelper; import app.revanced.twitch.utils.ReVancedUtils; import okhttp3.HttpUrl; import okhttp3.Request; -import okhttp3.ResponseBody; + +import java.util.HashMap; +import java.util.Map; public class PurpleAdblockService implements IAdblockService { private final Map tunnels = new HashMap<>() {{ @@ -36,9 +35,13 @@ public class PurpleAdblockService implements IAdblockService { if (!response.isSuccessful()) { LogHelper.error("PurpleAdBlock tunnel $tunnel returned an error: HTTP code %d", response.code()); LogHelper.debug(response.message()); - if (response.errorBody() != null) { - LogHelper.debug(((ResponseBody) response.errorBody()).string()); + + try (var errorBody = response.errorBody()) { + if (errorBody != null) { + LogHelper.debug(errorBody.string()); + } } + success = false; } } catch (Exception ex) {