-
Notifications
You must be signed in to change notification settings - Fork 45
Disabled NPE checks for non-public library fields by default #353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7cf9b50
Disabled NPE checks for non-public fields in non-application classes …
Damtev 62df0e4
Added test
Damtev 3308cf1
Fixed rebasing error
Damtev 603aff9
Added docs
Damtev 0644c98
Enabled reflection for ContestEstimator
Damtev 4526d3b
Fixed review issues
Damtev 98c2dda
Added trusted libraries scope
Damtev be48844
Used only JDK as a default trusted library
Damtev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Added trusted libraries scope
- Loading branch information
commit 98c2dda7d0e008a5103bc603f85fca13d2933fd4
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
utbot-framework-api/src/main/kotlin/org/utbot/framework/TrustedLibraries.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| package org.utbot.framework | ||
|
|
||
| import mu.KotlinLogging | ||
| import org.utbot.common.PathUtil.toPath | ||
| import java.io.IOException | ||
|
|
||
| private val logger = KotlinLogging.logger {} | ||
|
|
||
| private val defaultUserTrustedLibrariesPath: String = "${utbotHomePath}/trustedLibraries.txt" | ||
| private const val userTrustedLibrariesKey: String = "utbot.settings.trusted.libraries.path" | ||
|
|
||
| object TrustedLibraries { | ||
| /** | ||
| * JDK and some "trustworthy" open-source libraries. | ||
| */ | ||
| private val defaultTrustedLibraries: List<String> = listOf( | ||
| "java", | ||
| "sun", | ||
| "javax", | ||
| "com.sun", | ||
| "org.omg", | ||
| "org.xml", | ||
| "org.w3c.dom", | ||
| "com.google.common", | ||
| "org.antlr.v4", | ||
| "org.antlr.runtime", | ||
| "com.alibaba.fastjson", | ||
|
Damtev marked this conversation as resolved.
Outdated
|
||
| "com.alibaba.fescar.core", | ||
| "org.apache.pdfbox", | ||
| "io.seata.core", | ||
| "spoon" | ||
| ) | ||
|
|
||
| private val userTrustedLibraries: List<String> | ||
| get() { | ||
| val userTrustedLibrariesPath = System.getProperty(userTrustedLibrariesKey) ?: defaultUserTrustedLibrariesPath | ||
| val userTrustedLibrariesFile = userTrustedLibrariesPath.toPath().toFile() | ||
|
|
||
| if (!userTrustedLibrariesFile.exists()) { | ||
| return emptyList() | ||
| } | ||
|
|
||
| return try { | ||
| userTrustedLibrariesFile.readLines() | ||
| } catch (e: IOException) { | ||
| logger.info { e.message } | ||
|
|
||
| emptyList() | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Represents prefixes of packages for trusted libraries - | ||
| * as the union of [defaultTrustedLibraries] and [userTrustedLibraries]. | ||
| */ | ||
| val trustedLibraries: Set<String> by lazy { (defaultTrustedLibraries + userTrustedLibraries).toSet() } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
utbot-framework/src/main/kotlin/org/utbot/engine/util/trusted/TrustedPackages.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| package org.utbot.engine.util.trusted | ||
|
|
||
| import org.utbot.framework.TrustedLibraries | ||
| import soot.SootClass | ||
|
|
||
| /** | ||
| * Cache for already discovered trusted/untrusted packages. | ||
| */ | ||
| private val isPackageTrusted: MutableMap<String, Boolean> = mutableMapOf() | ||
|
|
||
| /** | ||
| * Determines whether [this] class is from trusted libraries as defined in [TrustedLibraries]. | ||
| */ | ||
| fun SootClass.isFromTrustedLibrary(): Boolean { | ||
| isPackageTrusted[packageName]?.let { | ||
| return it | ||
| } | ||
|
|
||
| val isTrusted = TrustedLibraries.trustedLibraries.any { packageName.startsWith(it, ignoreCase = false) } | ||
|
|
||
| return isTrusted.also { isPackageTrusted[packageName] = it } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.