Fix occasional reflection test failure
The cache in moduleByClassLoader.kt contains weak references to instances of RuntimeModuleData. However, prior to this change no one else had any _strong_ reference to the corresponding RuntimeModuleData: KClassImpl depends on the ModuleDescriptor almost directly. Therefore the weak references were sometimes garbage collected and a new module was constructed for a new reflection object, which resulted in broken equality between two reflection objects. No test added because it was rather hard to come up with (and, more importantly, to support) a test case.
This commit is contained in:
@@ -33,6 +33,11 @@ import java.lang.reflect.Method
|
|||||||
import kotlin.reflect.KotlinReflectionInternalError
|
import kotlin.reflect.KotlinReflectionInternalError
|
||||||
|
|
||||||
abstract class KCallableContainerImpl {
|
abstract class KCallableContainerImpl {
|
||||||
|
// Note: this is stored here on a soft reference to prevent GC from destroying the weak reference to it in the moduleByClassLoader cache
|
||||||
|
val moduleData by ReflectProperties.lazySoft {
|
||||||
|
jClass.getOrCreateModule()
|
||||||
|
}
|
||||||
|
|
||||||
abstract val jClass: Class<*>
|
abstract val jClass: Class<*>
|
||||||
|
|
||||||
abstract val scope: JetScope
|
abstract val scope: JetScope
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class KClassImpl<T>(override val jClass: Class<T>) : KCallableContainerImpl(), K
|
|||||||
// resulting in infinite recursion
|
// resulting in infinite recursion
|
||||||
|
|
||||||
val descriptor by ReflectProperties.lazySoft {
|
val descriptor by ReflectProperties.lazySoft {
|
||||||
val moduleData = jClass.getOrCreateModule()
|
|
||||||
val classId = classId
|
val classId = classId
|
||||||
|
|
||||||
val descriptor =
|
val descriptor =
|
||||||
|
|||||||
Reference in New Issue
Block a user