Skip to content

Commit 43a9760

Browse files
authored
Make loading Spring bean classes even more safe (#2154)
1 parent 2588785 commit 43a9760

File tree

1 file changed

+12
-2
lines changed
  • utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api

1 file changed

+12
-2
lines changed

utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api/Api.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.utbot.framework.plugin.api
1010

11+
import mu.KotlinLogging
1112
import org.utbot.common.FileUtil
1213
import org.utbot.common.isDefaultValue
1314
import org.utbot.common.withToStringThreadLocalReentrancyGuard
@@ -1270,6 +1271,10 @@ class SpringApplicationContext(
12701271
private val shouldUseImplementors: Boolean,
12711272
): ApplicationContext(mockInstalled, staticsMockingIsConfigured) {
12721273

1274+
companion object {
1275+
private val logger = KotlinLogging.logger {}
1276+
}
1277+
12731278
private var areInjectedClassesInitialized : Boolean = false
12741279

12751280
// Classes representing concrete types that are actually used in Spring application
@@ -1283,10 +1288,15 @@ class SpringApplicationContext(
12831288
!beanClass.isLocalClass && (!beanClass.isMemberClass || beanClass.isStatic)) {
12841289
springInjectedClassesStorage += beanClass.id
12851290
}
1286-
} catch (e: ClassNotFoundException) {
1291+
} catch (e: Throwable) {
12871292
// For some Spring beans (e.g. with anonymous classes)
12881293
// it is possible to have problems with classes loading.
1289-
continue
1294+
when (e) {
1295+
is ClassNotFoundException, is NoClassDefFoundError, is IllegalAccessError ->
1296+
logger.warn { "Failed to load bean class for $beanFqn (${e.message})" }
1297+
1298+
else -> throw e
1299+
}
12901300
}
12911301
}
12921302

0 commit comments

Comments
 (0)