From e577e48ad7ff2cb49923fdc784bd5dc418c34c26 Mon Sep 17 00:00:00 2001 From: Thomas Nardone Date: Tue, 17 Dec 2024 11:22:46 -0800 Subject: [PATCH] Remove reflection in OkHttpCallUtil (#48308) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/48308 Reflection is overkill here, we can simply suppress the deprecation "error". Changelog: [Internal] Reviewed By: javache Differential Revision: D67337980 fbshipit-source-id: 12076258ed4cb5c8737c84378621dda3072ec5a0 --- .../facebook/react/common/network/OkHttpCallUtil.kt | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt index c989a388587..fdca61e4f8a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/network/OkHttpCallUtil.kt @@ -5,9 +5,10 @@ * LICENSE file in the root directory of this source tree. */ +@file:Suppress("DEPRECATION_ERROR") // Conflicting okhttp versions + package com.facebook.react.common.network -import okhttp3.Dispatcher import okhttp3.OkHttpClient /** @@ -15,13 +16,8 @@ import okhttp3.OkHttpClient */ internal object OkHttpCallUtil { @JvmStatic - public fun cancelTag(client: OkHttpClient, tag: Any) { - // client.dispatcher is private, so we need to use reflection to access - // it via method dispatcher() otherwise we will get a compile error: - // Using 'dispatcher(): Dispatcher' is an error. moved to val - val dispatcherMethod = OkHttpClient::class.java.getMethod("dispatcher") - dispatcherMethod.setAccessible(true) - val dispatcher = dispatcherMethod.invoke(client) as Dispatcher + fun cancelTag(client: OkHttpClient, tag: Any) { + val dispatcher = client.dispatcher() for (call in dispatcher.queuedCalls()) { if (tag == call.request().tag()) { call.cancel()