Skip to content

Commit bbcb4a8

Browse files
Add flag in UtSettings.kt and workaround reason
1 parent a4235ae commit bbcb4a8

File tree

3 files changed

+45
-13
lines changed
  • utbot-core/src/main/kotlin/org/utbot/common
  • utbot-framework/src/main/kotlin/org/utbot/engine
  • utbot-framework-api/src/main/kotlin/org/utbot/framework

3 files changed

+45
-13
lines changed

utbot-core/src/main/kotlin/org/utbot/common/HackUtil.kt

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,46 @@ inline fun <T> heuristic(reason: WorkaroundReason, block: () -> T): T = block()
2525

2626
/**
2727
* Explains reason for applied workaround.
28-
*
29-
* Workarounds are:
30-
* - HACK - hacks behaviour for contest. Shall be removed sometimes
31-
* - MAKE_SYMBOLIC - Returns a new symbolic value with proper type instead of function result (i.e. for wrappers)
32-
* - IGNORE_SORT_INEQUALITY -- Ignores pairs of particular sorts in stores and selects
33-
* - RUN_CONCRETE -- Runs something concretely instead of symbolic run
34-
* - REMOVE_ANONYMOUS_CLASSES -- Remove anonymous classes from the results passed to the code generation till it doesn't support their generation
35-
* - IGNORE_MODEL_TYPES_INEQUALITY -- Ignore the fact that model before and model after have different types
36-
* - LONG_CODE_FRAGMENTS -- Comment too long blocks of code due to JVM restrictions [65536 bytes](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3)
37-
* - ARRAY_ELEMENT_TYPES_ALWAYS_NULLABLE -- Can't infer nullability for array elements from allocation statement, so make them nullable
38-
* Note:
39-
* - MAKE_SYMBOLIC can lose additional path constraints or branches from function call
4028
*/
4129
enum class WorkaroundReason {
30+
/**
31+
* Hacks behaviour for contest. Shall be removed sometimes
32+
*/
4233
HACK,
34+
/**
35+
* Returns a new symbolic value with proper type instead of function result (i.e. for wrappers)
36+
*
37+
* [MAKE_SYMBOLIC] can lose additional path constraints or branches from function call
38+
*/
4339
MAKE_SYMBOLIC,
40+
/**
41+
* Ignores pairs of particular sorts in stores and selects
42+
*/
4443
IGNORE_SORT_INEQUALITY,
44+
/**
45+
* Runs something concretely instead of symbolic run
46+
*/
4547
RUN_CONCRETE,
48+
/**
49+
* Remove anonymous classes from the results passed to the code generation till it doesn't support their generation
50+
*/
4651
REMOVE_ANONYMOUS_CLASSES,
52+
/**
53+
* Ignore the fact that model before and model after have different types
54+
*/
4755
IGNORE_MODEL_TYPES_INEQUALITY,
56+
/**
57+
* Comment too long blocks of code due to JVM restrictions [65536 bytes](https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.7.3)
58+
*/
4859
LONG_CODE_FRAGMENTS,
60+
/**
61+
* Can't infer nullability for array elements from allocation statement, so make them nullable
62+
*/
4963
ARRAY_ELEMENT_TYPES_ALWAYS_NULLABLE,
64+
/**
65+
* We won't branch on static field from trusted libraries and won't add them to staticsBefore. For now, it saves us
66+
* from setting [SecurityManager] and other suspicious stuff, but it can lead to coverage regression and thus it
67+
* requires thorough [investigation](https://github.com/UnitTestBot/UTBotJava/issues/716).
68+
*/
69+
IGNORE_STATICS_FROM_TRUSTED_LIBRARIES,
5070
}

utbot-framework-api/src/main/kotlin/org/utbot/framework/UtSettings.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@ object UtSettings {
389389
*/
390390
var skipTestGenerationForSyntheticMethods by getBooleanProperty(true)
391391

392+
/**
393+
* Flag that indicates whether should we branch on and set static fields from trusted libraries or not.
394+
*
395+
* @see [org.utbot.common.WorkaroundReason.IGNORE_STATICS_FROM_TRUSTED_LIBRARIES]
396+
*/
397+
var ignoreStaticsFromTrustedLibraries by getBooleanProperty(true)
398+
392399
override fun toString(): String =
393400
settingsValues
394401
.mapKeys { it.key.name }

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import kotlinx.collections.immutable.persistentSetOf
77
import kotlinx.collections.immutable.toPersistentList
88
import kotlinx.collections.immutable.toPersistentSet
99
import org.utbot.common.WorkaroundReason.HACK
10+
import org.utbot.framework.UtSettings.ignoreStaticsFromTrustedLibraries
11+
12+
`import org.utbot.common.WorkaroundReason.IGNORE_STATICS_FROM_TRUSTED_LIBRARIES
1013
import org.utbot.common.WorkaroundReason.REMOVE_ANONYMOUS_CLASSES
1114
import org.utbot.common.unreachableBranch
1215
import org.utbot.common.withAccessibility
@@ -1791,7 +1794,9 @@ class Traverser(
17911794
private fun isStaticFieldMeaningful(field: SootField) =
17921795
!Modifier.isSynthetic(field.modifiers) &&
17931796
// we don't want to set fields from library classes
1794-
!field.declaringClass.isFromTrustedLibrary()
1797+
workaround(IGNORE_STATICS_FROM_TRUSTED_LIBRARIES) {
1798+
!ignoreStaticsFromTrustedLibraries || !field.declaringClass.isFromTrustedLibrary()
1799+
}
17951800

17961801
/**
17971802
* Locates object represents static fields of particular class.

0 commit comments

Comments
 (0)