Skip to content

Commit 4fc363b

Browse files
Fix speculativelyCannotProduceNullPointerException in Spring projects (#2402)
1 parent 7af7430 commit 4fc363b

File tree

1 file changed

+6
-1
lines changed
  • utbot-framework-api/src/main/kotlin/org/utbot/framework/plugin/api

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ import org.utbot.framework.isFromTrustedLibrary
6161
import org.utbot.framework.plugin.api.TypeReplacementMode.*
6262
import org.utbot.framework.plugin.api.util.SpringModelUtils
6363
import org.utbot.framework.plugin.api.util.allDeclaredFieldIds
64+
import org.utbot.framework.plugin.api.util.allSuperTypes
6465
import org.utbot.framework.plugin.api.util.fieldId
6566
import org.utbot.framework.plugin.api.util.isSubtypeOf
6667
import org.utbot.framework.plugin.api.util.utContext
@@ -1492,6 +1493,10 @@ class SpringApplicationContext(
14921493
return springInjectedClassesStorage
14931494
}
14941495

1496+
private val allInjectedTypes: Set<ClassId> by lazy {
1497+
springInjectedClasses.flatMap { it.allSuperTypes() }.toSet()
1498+
}
1499+
14951500
// This is a service field to model the lazy behavior of [springInjectedClasses].
14961501
// Do not call it outside the getter.
14971502
//
@@ -1525,7 +1530,7 @@ class SpringApplicationContext(
15251530
override fun speculativelyCannotProduceNullPointerException(
15261531
field: SootField,
15271532
classUnderTest: ClassId,
1528-
): Boolean = field.fieldId in classUnderTest.allDeclaredFieldIds && field.declaringClass.id !in springInjectedClasses
1533+
): Boolean = field.fieldId in classUnderTest.allDeclaredFieldIds && field.type.classId !in allInjectedTypes
15291534

15301535
override fun preventsFurtherTestGeneration(): Boolean =
15311536
super.preventsFurtherTestGeneration() || springContextLoadingResult?.contextLoaded == false

0 commit comments

Comments
 (0)