Fix NPE in KCallable.isAccessible for interfaces loaded by boot class loader
Class.getClassLoader returns null for classes loaded by the system class
loader (the one used to start the application). In this case we need to
use ClassLoader.getSystemClassLoader. We already have an extension
`safeClassLoader` specifically for this purpose in reflection.jvm, but
forgot to use it in d59f2bcc80.
#KT-37707 Fixed
This commit is contained in:
Generated
+5
@@ -23938,6 +23938,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/instanceOfFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("isAccessibleOnAllMembers.kt")
|
||||
public void testIsAccessibleOnAllMembers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/isAccessibleOnAllMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaClassGetFunctions.kt")
|
||||
public void testJavaClassGetFunctions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/javaClassGetFunctions.kt");
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_REFLECT
|
||||
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
fun box(): String {
|
||||
val members = Observer::class.members
|
||||
for (member in members) {
|
||||
member.isAccessible = true
|
||||
}
|
||||
return members.single { it.name == "result" }.call(Observer()) as String
|
||||
}
|
||||
|
||||
class Observer : AutoCloseable {
|
||||
override fun close() {
|
||||
}
|
||||
|
||||
private fun result() = "OK"
|
||||
}
|
||||
+5
@@ -25524,6 +25524,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/instanceOfFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("isAccessibleOnAllMembers.kt")
|
||||
public void testIsAccessibleOnAllMembers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/isAccessibleOnAllMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaClassGetFunctions.kt")
|
||||
public void testJavaClassGetFunctions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/javaClassGetFunctions.kt");
|
||||
|
||||
+5
@@ -24341,6 +24341,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/instanceOfFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("isAccessibleOnAllMembers.kt")
|
||||
public void testIsAccessibleOnAllMembers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/isAccessibleOnAllMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaClassGetFunctions.kt")
|
||||
public void testJavaClassGetFunctions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/javaClassGetFunctions.kt");
|
||||
|
||||
+5
@@ -23938,6 +23938,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/instanceOfFunction.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("isAccessibleOnAllMembers.kt")
|
||||
public void testIsAccessibleOnAllMembers() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/isAccessibleOnAllMembers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("javaClassGetFunctions.kt")
|
||||
public void testJavaClassGetFunctions() throws Exception {
|
||||
runTest("compiler/testData/codegen/box/reflection/functions/javaClassGetFunctions.kt");
|
||||
|
||||
@@ -184,7 +184,7 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
||||
|
||||
// Static "$default" methods should be looked up in each DefaultImpls class, see KT-33430
|
||||
if (isStaticDefault) {
|
||||
val defaultImpls = superInterface.classLoader.tryLoadClass(superInterface.name + JvmAbi.DEFAULT_IMPLS_SUFFIX)
|
||||
val defaultImpls = superInterface.safeClassLoader.tryLoadClass(superInterface.name + JvmAbi.DEFAULT_IMPLS_SUFFIX)
|
||||
if (defaultImpls != null) {
|
||||
parameterTypes[0] = superInterface
|
||||
defaultImpls.tryGetMethod(name, parameterTypes, returnType)?.let { return it }
|
||||
|
||||
Reference in New Issue
Block a user