From a78d6ba8408eefa17d1ee7c9949427461707830a Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Wed, 12 Jul 2023 16:38:46 +0300 Subject: [PATCH 1/2] Use custom by lazy in SpringApplicationContext because of RD --- .../kotlin/org/utbot/framework/plugin/api/Api.kt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 106be075f7..4daf1ec740 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -1461,6 +1461,7 @@ class SpringApplicationContext( } private var areInjectedClassesInitialized : Boolean = false + private var areAllInjectedTypesInitialized: Boolean = false // Classes representing concrete types that are actually used in Spring application private val springInjectedClasses: Set @@ -1493,8 +1494,15 @@ class SpringApplicationContext( return springInjectedClassesStorage } - private val allInjectedTypes: Set by lazy { - springInjectedClasses.flatMap { it.allSuperTypes() }.toSet() + // imitates `by lazy` (we can't use actual `by lazy` because communication via RD breaks it) + private var allInjectedTypesStorage: Set = emptySet() + private val allInjectedTypes: Set get() { + if (!areAllInjectedTypesInitialized) { + allInjectedTypesStorage = springInjectedClasses.flatMap { it.allSuperTypes() }.toSet() + areAllInjectedTypesInitialized = true + } + + return allInjectedTypesStorage } // This is a service field to model the lazy behavior of [springInjectedClasses]. From eee9fbde14c69984de7cd4482f860f0f199bf193 Mon Sep 17 00:00:00 2001 From: Egor Kulikov Date: Wed, 12 Jul 2023 16:42:21 +0300 Subject: [PATCH 2/2] Cleanup --- .../org/utbot/framework/plugin/api/Api.kt | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt index 4daf1ec740..99d71bc9da 100644 --- a/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt +++ b/utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt @@ -1494,16 +1494,18 @@ class SpringApplicationContext( return springInjectedClassesStorage } - // imitates `by lazy` (we can't use actual `by lazy` because communication via RD breaks it) - private var allInjectedTypesStorage: Set = emptySet() - private val allInjectedTypes: Set get() { - if (!areAllInjectedTypesInitialized) { - allInjectedTypesStorage = springInjectedClasses.flatMap { it.allSuperTypes() }.toSet() - areAllInjectedTypesInitialized = true + private val allInjectedTypes: Set + get() { + if (!areAllInjectedTypesInitialized) { + allInjectedTypesStorage = springInjectedClasses.flatMap { it.allSuperTypes() }.toSet() + areAllInjectedTypesInitialized = true + } + + return allInjectedTypesStorage } - return allInjectedTypesStorage - } + // imitates `by lazy` (we can't use actual `by lazy` because communication via RD breaks it) + private var allInjectedTypesStorage: Set = emptySet() // This is a service field to model the lazy behavior of [springInjectedClasses]. // Do not call it outside the getter.