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 a8fe3e6107..1b56a0be68 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 @@ -61,7 +61,6 @@ import org.utbot.framework.plugin.api.TypeReplacementMode.* import org.utbot.framework.plugin.api.util.allDeclaredFieldIds import org.utbot.framework.plugin.api.util.fieldId import org.utbot.framework.plugin.api.util.isSubtypeOf -import org.utbot.framework.plugin.api.util.objectClassId import org.utbot.framework.plugin.api.util.utContext import org.utbot.framework.process.OpenModulesContainer import soot.SootField @@ -1276,7 +1275,7 @@ class SpringApplicationContext( private val springInjectedClasses: Set get() { if (!areInjectedClassesInitialized) { - springInjectedClassesStorage += beanQualifiedNames + _springInjectedClasses += beanQualifiedNames .map { fqn -> utContext.classLoader.loadClass(fqn) } .filterNot { it.isAbstract || it.isInterface || it.isLocalClass || it.isMemberClass && !it.isStatic } .mapTo(mutableSetOf()) { it.id } @@ -1286,7 +1285,7 @@ class SpringApplicationContext( areInjectedClassesInitialized = true } - return springInjectedClassesStorage + return _springInjectedClasses } // This is a service field to model the lazy behavior of [springInjectedClasses]. @@ -1294,7 +1293,7 @@ class SpringApplicationContext( // // Actually, we should just call [springInjectedClasses] with `by lazy`, but we had problems // with a strange `kotlin.UNINITIALIZED_VALUE` in `speculativelyCannotProduceNullPointerException` method call. - private val springInjectedClassesStorage = mutableSetOf() + private val _springInjectedClasses = mutableSetOf() override val typeReplacementMode: TypeReplacementMode = if (shouldUseImplementors) KnownImplementor else NoImplementors diff --git a/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/postProcessors/UtBotBeanFactoryPostProcessor.kt b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/postProcessors/UtBotBeanFactoryPostProcessor.kt index b0276dbac2..18ce18cd62 100644 --- a/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/postProcessors/UtBotBeanFactoryPostProcessor.kt +++ b/utbot-spring-analyzer/src/main/kotlin/org/utbot/spring/postProcessors/UtBotBeanFactoryPostProcessor.kt @@ -1,5 +1,6 @@ package org.utbot.spring.postProcessors +import org.springframework.beans.factory.BeanCreationException import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition import org.springframework.beans.factory.config.BeanFactoryPostProcessor import org.springframework.beans.factory.config.ConfigurableListableBeanFactory @@ -28,26 +29,18 @@ object UtBotBeanFactoryPostProcessor : BeanFactoryPostProcessor, PriorityOrdered println("Finished post-processing bean factory in UtBot") } - private fun findBeanClassNames(beanFactory: ConfigurableListableBeanFactory): ArrayList { - val beanClassNames = ArrayList() - for (beanDefinitionName in beanFactory.beanDefinitionNames) { - val beanDefinition = beanFactory.getBeanDefinition(beanDefinitionName) - - if (beanDefinition is AnnotatedBeanDefinition) { - val factoryMethodMetadata = beanDefinition.factoryMethodMetadata - if (factoryMethodMetadata != null) { - beanClassNames.add(factoryMethodMetadata.returnTypeName) - } - } else { - var className = beanDefinition.beanClassName - if (className == null) { - className = beanFactory.getBean(beanDefinitionName).javaClass.name - } - className?.let { beanClassNames.add(it) } + private fun findBeanClassNames(beanFactory: ConfigurableListableBeanFactory): List { + return beanFactory.beanDefinitionNames.mapNotNull { + try { + beanFactory.getBeanDefinition(it).beanClassName + //TODO: avoid getting bean here, change the interface to find method and return type + // and obtain required information from PsiClass in UtBot after that. + ?: beanFactory.getBean(it).javaClass.name + } catch (e: BeanCreationException) { + //logger.warn { "Failed to get bean: $it" } + null } - } - - return beanClassNames + }.filterNot { it.startsWith("org.utbot.spring") } } private fun destroyBeanDefinitions(beanFactory: ConfigurableListableBeanFactory) {