From 23abd792829b73202a560be2e6f37685fd80d2e1 Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Mon, 17 Apr 2023 23:21:00 +0300 Subject: [PATCH 1/2] Make Spring bean class loading safer --- .../kotlin/org/utbot/framework/plugin/api/Api.kt | 14 ++++++++++++-- 1 file changed, 12 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 47e7f09252..5b930dc41f 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 @@ -8,6 +8,7 @@ package org.utbot.framework.plugin.api +import mu.KotlinLogging import org.utbot.common.FileUtil import org.utbot.common.isDefaultValue import org.utbot.common.withToStringThreadLocalReentrancyGuard @@ -1270,6 +1271,10 @@ class SpringApplicationContext( private val shouldUseImplementors: Boolean, ): ApplicationContext(mockInstalled, staticsMockingIsConfigured) { + companion object { + private val logger = KotlinLogging.logger {} + } + private var areInjectedClassesInitialized : Boolean = false // Classes representing concrete types that are actually used in Spring application @@ -1283,10 +1288,15 @@ class SpringApplicationContext( !beanClass.isLocalClass && (!beanClass.isMemberClass || beanClass.isStatic)) { springInjectedClassesStorage += beanClass.id } - } catch (e: ClassNotFoundException) { + } catch (e: Throwable) { // For some Spring beans (e.g. with anonymous classes) // it is possible to have problems with classes loading. - continue + when (e) { + is ClassNotFoundException, is NoClassDefFoundError, is IllegalAccessError -> + logger.warn { "Failed to load bean class for $beanFqn" } + + else -> throw e + } } } From 7aefd99f2e00ac577e7abdabedafa05dafb60e7b Mon Sep 17 00:00:00 2001 From: IlyaMuravjov Date: Mon, 17 Apr 2023 23:36:44 +0300 Subject: [PATCH 2/2] Also log exception message when Spring bean class loading fails --- .../src/main/kotlin/org/utbot/framework/plugin/api/Api.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 5b930dc41f..d2235e3132 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 @@ -1293,7 +1293,7 @@ class SpringApplicationContext( // it is possible to have problems with classes loading. when (e) { is ClassNotFoundException, is NoClassDefFoundError, is IllegalAccessError -> - logger.warn { "Failed to load bean class for $beanFqn" } + logger.warn { "Failed to load bean class for $beanFqn (${e.message})" } else -> throw e }