From 37863903b4c780e4fb366226f4108378abff616e Mon Sep 17 00:00:00 2001 From: Ryan Brooks Date: Wed, 23 Oct 2024 10:39:07 -0700 Subject: [PATCH] Use internal copy of closeQuietly to avoid location mismatches in OkHTTP versions --- .../reaper/ReaperReportErrorWorker.kt | 2 +- .../reaper/ReaperReportUploadWorker.kt | 2 +- .../emergetools/reaper/utils/OkHttpUtils.kt | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 reaper/reaper/src/main/kotlin/com/emergetools/reaper/utils/OkHttpUtils.kt diff --git a/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportErrorWorker.kt b/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportErrorWorker.kt index bd91b273..bd7fa966 100644 --- a/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportErrorWorker.kt +++ b/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportErrorWorker.kt @@ -10,6 +10,7 @@ import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager import androidx.work.WorkerParameters import androidx.work.workDataOf +import com.emergetools.reaper.utils.OkHttpUtils.closeQuietly import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine @@ -22,7 +23,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response -import okhttp3.internal.closeQuietly import java.io.IOException import kotlin.coroutines.resumeWithException diff --git a/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportUploadWorker.kt b/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportUploadWorker.kt index e9e12e6d..5a32b35f 100644 --- a/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportUploadWorker.kt +++ b/reaper/reaper/src/main/kotlin/com/emergetools/reaper/ReaperReportUploadWorker.kt @@ -9,6 +9,7 @@ import android.util.Base64 import android.util.Log import androidx.work.CoroutineWorker import androidx.work.WorkerParameters +import com.emergetools.reaper.utils.OkHttpUtils.closeQuietly import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine @@ -21,7 +22,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.Request import okhttp3.RequestBody.Companion.toRequestBody import okhttp3.Response -import okhttp3.internal.closeQuietly import java.io.DataInputStream import java.io.EOFException import java.io.File diff --git a/reaper/reaper/src/main/kotlin/com/emergetools/reaper/utils/OkHttpUtils.kt b/reaper/reaper/src/main/kotlin/com/emergetools/reaper/utils/OkHttpUtils.kt new file mode 100644 index 00000000..50ca1ac7 --- /dev/null +++ b/reaper/reaper/src/main/kotlin/com/emergetools/reaper/utils/OkHttpUtils.kt @@ -0,0 +1,18 @@ +package com.emergetools.reaper.utils + +import java.io.Closeable + +internal object OkHttpUtils { + + // OkHttp moved this extension function in 5.x of the OkHttp library + // To avoid resolution issues, we'll implement this extension internally. + fun Closeable.closeQuietly() { + try { + close() + } catch (rethrown: RuntimeException) { + throw rethrown + } catch (ignored: Exception) { + // Ignored + } + } +}