Load JDK 8 platform implementations class without reflection

Also remove search for other platform implementation classes because
now the first match should be found in the same jar

Helps to avoid GraalVM related reflection problems in KT-51579
This commit is contained in:
Ilya Gorbunov
2023-01-26 22:03:00 +01:00
committed by Space Team
parent 3cb0d489bf
commit 61e9f98b9f
3 changed files with 28 additions and 17 deletions
+14
View File
@@ -15,6 +15,11 @@ configurations {
}
sourceSets {
compileOnlyDeclarations {
java {
srcDir 'compileOnly'
}
}
main {
java {
srcDir "${rootDir}/core/builtins/src"
@@ -74,6 +79,7 @@ dependencies {
api group: 'org.jetbrains', name: 'annotations', version:'13.0'
compileOnly sourceSets.compileOnlyDeclarations.output
mainJdk7Api sourceSets.main.output
mainJdk8Api sourceSets.main.output
mainJdk8Api sourceSets.mainJdk7.output
@@ -176,6 +182,14 @@ compileMainJdk8Kotlin {
kotlinOptions.moduleName = "kotlin-stdlib-jdk8"
}
compileCompileOnlyDeclarationsKotlin {
kotlinOptions {
freeCompilerArgs = [
"-Xallow-kotlin-package",
]
}
}
compileTestKotlin {
kotlinOptions {
freeCompilerArgs += [
@@ -0,0 +1,11 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package kotlin.internal.jdk8
// forward-reference declaration of JDK8PlatformImplementations
// declared in the source set compiled against JDK 8
// used in the source set compiled against JDK 6
public open class JDK8PlatformImplementations()
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@@ -47,22 +47,8 @@ internal open class PlatformImplementations {
@JvmField
internal val IMPLEMENTATIONS: PlatformImplementations = run {
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
try {
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance())
} catch (e: ClassNotFoundException) { }
PlatformImplementations()
}
internal val IMPLEMENTATIONS: PlatformImplementations =
castToBaseType<PlatformImplementations>(kotlin.internal.jdk8.JDK8PlatformImplementations())
@kotlin.internal.InlineOnly
private inline fun <reified T : Any> castToBaseType(instance: Any): T {