Skip to content

Commit 6e65b46

Browse files
committed
Merge avoidSpeculativeNotNullChecks and speculativelyCannotProduceNullPointerException into one method
1 parent e0fde47 commit 6e65b46

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

utbot-framework/src/main/kotlin/org/utbot/engine/Traverser.kt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,12 +2336,8 @@ class Traverser(
23362336
* See more detailed documentation in [ApplicationContext] mentioned methods.
23372337
*/
23382338
private fun checkAndMarkLibraryFieldSpeculativelyNotNull(field: SootField, createdField: SymbolicValue) {
2339-
if (applicationContext.avoidSpeculativeNotNullChecks(field) ||
2340-
!applicationContext.speculativelyCannotProduceNullPointerException(field, methodUnderTest.classId)) {
2341-
return
2342-
}
2343-
2344-
markAsSpeculativelyNotNull(createdField.addr)
2339+
if (applicationContext.speculativelyCannotProduceNullPointerException(field, methodUnderTest.classId))
2340+
markAsSpeculativelyNotNull(createdField.addr)
23452341
}
23462342

23472343
private fun createArray(pName: String, type: ArrayType): ArrayValue {

utbot-framework/src/main/kotlin/org/utbot/framework/context/ApplicationContext.kt

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,6 @@ open class ApplicationContext(
4949
*/
5050
open fun replaceTypeIfNeeded(type: RefType): ClassId? = null
5151

52-
/**
53-
* Sets the restrictions on speculative not null
54-
* constraints in current application context.
55-
*
56-
* @see docs/SpeculativeFieldNonNullability.md for more information.
57-
*/
58-
open fun avoidSpeculativeNotNullChecks(field: SootField): Boolean =
59-
UtSettings.maximizeCoverageUsingReflection || !field.declaringClass.isFromTrustedLibrary()
60-
6152
/**
6253
* Checks whether accessing [field] (with a method invocation or field access) speculatively
6354
* cannot produce [NullPointerException] (according to its finality or accessibility).
@@ -67,7 +58,10 @@ open class ApplicationContext(
6758
open fun speculativelyCannotProduceNullPointerException(
6859
field: SootField,
6960
classUnderTest: ClassId,
70-
): Boolean = field.isFinal || !field.isPublic
61+
): Boolean =
62+
!UtSettings.maximizeCoverageUsingReflection &&
63+
field.declaringClass.isFromTrustedLibrary() &&
64+
(field.isFinal || !field.isPublic)
7165

7266
open fun preventsFurtherTestGeneration(): Boolean = false
7367

utbot-framework/src/main/kotlin/org/utbot/framework/context/SpringApplicationContext.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ class SpringApplicationContext(
123123
null
124124
}
125125

126-
override fun avoidSpeculativeNotNullChecks(field: SootField): Boolean = false
127-
128126
/**
129127
* In Spring applications we can mark as speculatively not null
130128
* fields if they are mocked and injecting into class under test so on.

0 commit comments

Comments
 (0)