From 6bb0aeca840d686f3439dd9559e92f5ddafd1ef0 Mon Sep 17 00:00:00 2001 From: Syer10 Date: Sat, 7 Dec 2024 14:09:25 -0500 Subject: [PATCH] Fix Deprecation Warnings --- .../src/main/java/app/cash/quickjs/QuickJs.java | 9 +++++---- .../eu/kanade/tachiyomi/network/OkHttpExtensions.kt | 5 ++--- .../suwayomi/tachidesk/manga/impl/util/PackageTools.kt | 3 ++- .../suwayomi/tachidesk/manga/impl/util/network/OkHttp.kt | 5 ++--- .../tachidesk/server/util/WebInterfaceManager.kt | 4 ++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/AndroidCompat/src/main/java/app/cash/quickjs/QuickJs.java b/AndroidCompat/src/main/java/app/cash/quickjs/QuickJs.java index 02b42efeef..ab2c008aea 100644 --- a/AndroidCompat/src/main/java/app/cash/quickjs/QuickJs.java +++ b/AndroidCompat/src/main/java/app/cash/quickjs/QuickJs.java @@ -88,11 +88,12 @@ public void set(String name, Class ignoredType, T object) { context.getBindings("js").putMember(name, object); } - @Override public void close() { - this.context.leave(); - this.context.close(); - this.context = null; + if (this.context != null) { + this.context.leave(); + this.context.close(); + this.context = null; + } } } diff --git a/server/src/main/kotlin/eu/kanade/tachiyomi/network/OkHttpExtensions.kt b/server/src/main/kotlin/eu/kanade/tachiyomi/network/OkHttpExtensions.kt index c2f9dd80e4..cb49b32fe3 100644 --- a/server/src/main/kotlin/eu/kanade/tachiyomi/network/OkHttpExtensions.kt +++ b/server/src/main/kotlin/eu/kanade/tachiyomi/network/OkHttpExtensions.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.network -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.ExperimentalSerializationApi @@ -68,7 +67,6 @@ fun Call.asObservableSuccess(): Observable = } // Based on https://github.com/gildor/kotlin-coroutines-okhttp -@OptIn(ExperimentalCoroutinesApi::class) private suspend fun Call.await(callStack: Array): Response { return suspendCancellableCoroutine { continuation -> val callback = @@ -77,8 +75,9 @@ private suspend fun Call.await(callStack: Array): Response { call: Call, response: Response, ) { - continuation.resume(response) { + continuation.resume(response) { _, resourceToClose, _ -> response.body.close() + resourceToClose.close() } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/PackageTools.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/PackageTools.kt index 5defeee714..9b09457307 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/PackageTools.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/PackageTools.kt @@ -29,6 +29,7 @@ import java.net.URLClassLoader import java.nio.file.Files import java.nio.file.Path import javax.xml.parsers.DocumentBuilderFactory +import kotlin.io.path.Path object PackageTools { private val logger = KotlinLogging.logger {} @@ -152,7 +153,7 @@ object PackageTools { ): Any { try { logger.debug { "loading jar with path: $jarPath" } - val classLoader = jarLoaderMap[jarPath] ?: URLClassLoader(arrayOf(URL("file:$jarPath"))) + val classLoader = jarLoaderMap[jarPath] ?: URLClassLoader(arrayOf(Path(jarPath).toUri().toURL())) val classToLoad = Class.forName(className, false, classLoader) jarLoaderMap[jarPath] = classLoader diff --git a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/network/OkHttp.kt b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/network/OkHttp.kt index 3d20ac0ede..fba57c69e0 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/network/OkHttp.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/manga/impl/util/network/OkHttp.kt @@ -7,7 +7,6 @@ package suwayomi.tachidesk.manga.impl.util.network * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.suspendCancellableCoroutine import okhttp3.Call import okhttp3.Callback @@ -17,7 +16,6 @@ import java.io.IOException import kotlin.coroutines.resumeWithException // Based on https://github.com/gildor/kotlin-coroutines-okhttp -@OptIn(ExperimentalCoroutinesApi::class) suspend fun Call.await(): Response { return suspendCancellableCoroutine { continuation -> enqueue( @@ -31,8 +29,9 @@ suspend fun Call.await(): Response { return } - continuation.resume(response) { + continuation.resume(response) { _, resourceToClose, _ -> response.body.closeQuietly() + resourceToClose.closeQuietly() } } diff --git a/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt b/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt index 986c815625..5e2d6d8db4 100644 --- a/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt +++ b/server/src/main/kotlin/suwayomi/tachidesk/server/util/WebInterfaceManager.kt @@ -54,7 +54,7 @@ import uy.kohesive.injekt.injectLazy import java.io.File import java.io.InputStream import java.net.HttpURLConnection -import java.net.URL +import java.net.URI import java.nio.charset.StandardCharsets import java.security.MessageDigest import java.util.Date @@ -723,7 +723,7 @@ object WebInterfaceManager { zipFile.outputStream().use { webUIZipFileOut -> - val connection = URL(url).openConnection() as HttpURLConnection + val connection = URI.create(url).toURL().openConnection() as HttpURLConnection connection.connect() val contentLength = connection.contentLength