From a2a19cb7c69958b71561426c96f33187e2b5c45c Mon Sep 17 00:00:00 2001 From: Yuri Schimke Date: Sun, 4 Jul 2021 16:06:11 +0100 Subject: [PATCH] Handle strict module handling on JDK17 (#6707) --- .../src/main/kotlin/okhttp3/internal/platform/Platform.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/okhttp/src/main/kotlin/okhttp3/internal/platform/Platform.kt b/okhttp/src/main/kotlin/okhttp3/internal/platform/Platform.kt index 664f913964a1..9e0c362d6787 100644 --- a/okhttp/src/main/kotlin/okhttp3/internal/platform/Platform.kt +++ b/okhttp/src/main/kotlin/okhttp3/internal/platform/Platform.kt @@ -94,6 +94,14 @@ open class Platform { val context = readFieldOrNull(sslSocketFactory, sslContextClass, "context") ?: return null readFieldOrNull(context, X509TrustManager::class.java, "trustManager") } catch (e: ClassNotFoundException) { + null + } catch (e: RuntimeException) { + // Throws InaccessibleObjectException (added in JDK9) on JDK 17 due to + // JEP 403 Strongly Encapsulate JDK Internals. + if (e.javaClass.name != "java.lang.reflect.InaccessibleObjectException") { + throw e + } + null } }