Report more diagnostics when JDK8PlatformImplementations can't be cast to base type
#EA-120914 - CCE: PlatformImplementationsKt.<clinit>
This commit is contained in:
@@ -25,25 +25,36 @@ internal val IMPLEMENTATIONS: PlatformImplementations = run {
|
||||
val version = getJavaVersion()
|
||||
if (version >= 0x10008) {
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance() as PlatformImplementations
|
||||
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk8.JDK8PlatformImplementations").newInstance())
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance() as PlatformImplementations
|
||||
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE8PlatformImplementations").newInstance())
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
}
|
||||
|
||||
if (version >= 0x10007) {
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance() as PlatformImplementations
|
||||
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.jdk7.JDK7PlatformImplementations").newInstance())
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
try {
|
||||
return@run Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance() as PlatformImplementations
|
||||
return@run castToBaseType<PlatformImplementations>(Class.forName("kotlin.internal.JRE7PlatformImplementations").newInstance())
|
||||
} catch (e: ClassNotFoundException) { }
|
||||
}
|
||||
|
||||
PlatformImplementations()
|
||||
}
|
||||
|
||||
@kotlin.internal.InlineOnly
|
||||
private inline fun <reified T : Any> castToBaseType(instance: Any): T {
|
||||
try {
|
||||
return instance as T
|
||||
} catch (e: ClassCastException) {
|
||||
val instanceCL = instance.javaClass.classLoader
|
||||
val baseTypeCL = T::class.java.classLoader
|
||||
throw ClassCastException("Instance classloader: $instanceCL, base type classloader: $baseTypeCL").initCause(e)
|
||||
}
|
||||
}
|
||||
|
||||
private fun getJavaVersion(): Int {
|
||||
val default = 0x10006
|
||||
val version = System.getProperty("java.specification.version") ?: return default
|
||||
|
||||
Reference in New Issue
Block a user