File tree 4 files changed +89
-4
lines changed
utbot-framework/src/main/kotlin/org/utbot/engine
utbot-framework-api/src/main/kotlin/org/utbot/framework
4 files changed +89
-4
lines changed Original file line number Diff line number Diff line change
1
+ package org.utbot.framework
2
+
3
+ import mu.KotlinLogging
4
+ import org.utbot.common.PathUtil.toPath
5
+ import java.io.IOException
6
+
7
+ private val logger = KotlinLogging .logger {}
8
+
9
+ private val defaultUserTrustedLibrariesPath: String = " ${utbotHomePath} /trustedLibraries.txt"
10
+ private const val userTrustedLibrariesKey: String = " utbot.settings.trusted.libraries.path"
11
+
12
+ object TrustedLibraries {
13
+ /* *
14
+ * JDK and some "trustworthy" open-source libraries.
15
+ */
16
+ private val defaultTrustedLibraries: List <String > = listOf (
17
+ " java" ,
18
+ " sun" ,
19
+ " javax" ,
20
+ " com.sun" ,
21
+ " org.omg" ,
22
+ " org.xml" ,
23
+ " org.w3c.dom" ,
24
+ " com.google.common" ,
25
+ " org.antlr.v4" ,
26
+ " org.antlr.runtime" ,
27
+ " com.alibaba.fastjson" ,
28
+ " com.alibaba.fescar.core" ,
29
+ " org.apache.pdfbox" ,
30
+ " io.seata.core" ,
31
+ " spoon"
32
+ )
33
+
34
+ private val userTrustedLibraries: List <String >
35
+ get() {
36
+ val userTrustedLibrariesPath = System .getProperty(userTrustedLibrariesKey) ? : defaultUserTrustedLibrariesPath
37
+ val userTrustedLibrariesFile = userTrustedLibrariesPath.toPath().toFile()
38
+
39
+ if (! userTrustedLibrariesFile.exists()) {
40
+ return emptyList()
41
+ }
42
+
43
+ return try {
44
+ userTrustedLibrariesFile.readLines()
45
+ } catch (e: IOException ) {
46
+ logger.info { e.message }
47
+
48
+ emptyList()
49
+ }
50
+ }
51
+
52
+ /* *
53
+ * Represents prefixes of packages for trusted libraries -
54
+ * as the union of [defaultTrustedLibraries] and [userTrustedLibraries].
55
+ */
56
+ val trustedLibraries: Set <String > by lazy { (defaultTrustedLibraries + userTrustedLibraries).toSet() }
57
+ }
Original file line number Diff line number Diff line change @@ -10,11 +10,16 @@ import kotlin.reflect.KProperty
10
10
11
11
private val logger = KotlinLogging .logger {}
12
12
13
+ /* *
14
+ * Path to the utbot home folder.
15
+ */
16
+ internal val utbotHomePath = " ${System .getProperty(" user.home" )} /.utbot"
17
+
13
18
/* *
14
19
* Default path for properties file
15
20
*/
16
- internal val defaultSettingsPath = " ${ System .getProperty( " user.home " )} /.utbot /settings.properties"
17
- internal const val defaultKeyForSettingsPath = " utbot.settings.path"
21
+ private val defaultSettingsPath = " $utbotHomePath /settings.properties"
22
+ private const val defaultKeyForSettingsPath = " utbot.settings.path"
18
23
19
24
internal class SettingDelegate <T >(val initializer : () -> T ) {
20
25
private var value = initializer()
Original file line number Diff line number Diff line change @@ -106,6 +106,7 @@ import org.utbot.engine.symbolic.asHardConstraint
106
106
import org.utbot.engine.symbolic.asSoftConstraint
107
107
import org.utbot.engine.symbolic.asAssumption
108
108
import org.utbot.engine.symbolic.asUpdate
109
+ import org.utbot.engine.util.trusted.isFromTrustedLibrary
109
110
import org.utbot.engine.util.mockListeners.MockListener
110
111
import org.utbot.engine.util.mockListeners.MockListenerController
111
112
import org.utbot.engine.util.statics.concrete.associateEnumSootFieldsWithConcreteValues
@@ -2249,10 +2250,10 @@ class UtBotSymbolicEngine(
2249
2250
* Marks the [createdField] as speculatively not null if the [field] is considering as
2250
2251
* not producing [NullPointerException].
2251
2252
*
2252
- * @see [SootField.speculativelyCannotProduceNullPointerException], [markAsSpeculativelyNotNull]
2253
+ * @see [SootField.speculativelyCannotProduceNullPointerException], [markAsSpeculativelyNotNull], [isFromTrustedLibrary].
2253
2254
*/
2254
2255
private fun checkAndMarkLibraryFieldSpeculativelyNotNull (field : SootField , createdField : SymbolicValue ) {
2255
- if (maximizeCoverageUsingReflection || ! field.declaringClass.isLibraryClass ) {
2256
+ if (maximizeCoverageUsingReflection || ! field.declaringClass.isFromTrustedLibrary() ) {
2256
2257
return
2257
2258
}
2258
2259
Original file line number Diff line number Diff line change
1
+ package org.utbot.engine.util.trusted
2
+
3
+ import org.utbot.framework.TrustedLibraries
4
+ import soot.SootClass
5
+
6
+ /* *
7
+ * Cache for already discovered trusted/untrusted packages.
8
+ */
9
+ private val isPackageTrusted: MutableMap <String , Boolean > = mutableMapOf ()
10
+
11
+ /* *
12
+ * Determines whether [this] class is from trusted libraries as defined in [TrustedLibraries].
13
+ */
14
+ fun SootClass.isFromTrustedLibrary (): Boolean {
15
+ isPackageTrusted[packageName]?.let {
16
+ return it
17
+ }
18
+
19
+ val isTrusted = TrustedLibraries .trustedLibraries.any { packageName.startsWith(it, ignoreCase = false ) }
20
+
21
+ return isTrusted.also { isPackageTrusted[packageName] = it }
22
+ }
You can’t perform that action at this time.
0 commit comments