RUM-16478: UnsafeThirdPartyFunctionCall improvements#3557
Open
satween wants to merge 2 commits into
Open
Conversation
Adds wildcard support and overlap detection to the rule, and splits it into focused modules. Wildcards: YAML entries in knownSafeCalls/knownThrowingCalls now accept per-parameter wildcards — * (any non-nullable type) and ? (any nullable type). Valid only at generic parameter positions; misuse throws IllegalStateException. Overlap detection: Rejects entries that are both safe and throwing, and catches duplicate/overlapping patterns within each list. Removed 17 pre-existing duplicates plus two genuine conflicts (Thread.interrupt(), Array.first(Function1)). Config cleanup: Collapsed repeated generic-parameter entries to wildcards across safe-calls and detekt configs. Refactor: RulesParser (YAML parsing), CodeParser (call-expression extraction), WildcardPattern (matching + validation); the rule now keeps only visitor wiring and the safe/throwing/unknown decision.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #3557 +/- ##
===========================================
- Coverage 72.40% 72.39% -0.01%
===========================================
Files 967 967
Lines 35717 35716 -1
Branches 5967 5967
===========================================
- Hits 25858 25854 -4
+ Misses 8200 8196 -4
- Partials 1659 1666 +7 🚀 New features to boost your workflow:
|
hamorillo
reviewed
Jun 19, 2026
hamorillo
left a comment
Contributor
There was a problem hiding this comment.
Looks good to me. Just leaving a question before approving.
| reportUnsafeCall(expression, msg) | ||
| reportUnsafeCall( | ||
| expression = expression, | ||
| message = "Calling $call can throw the following exceptions: ${exceptions.joinToString()}." |
Contributor
There was a problem hiding this comment.
nit: Maybe here we can report only the uncaught exceptions.
Comment on lines
+83
to
+86
| private val semanticUnsafeCalls = listOf( | ||
| "java.lang.Thread.interrupt():java.lang.SecurityException", | ||
| "kotlin.Array.first(kotlin.Function1):java.util.NoSuchElementException" | ||
| ) |
Contributor
There was a problem hiding this comment.
❓ What's the goal of this list? Why not to keep those in the unsafe_call.yml?
| private val methodPart: String = source.substringBefore('(') | ||
| internal val overlapKey: OverlapKey = OverlapKey(methodPart, paramSlots.size) | ||
|
|
||
| /** True when this rule has no wildcard slots and can be matched with a plain map lookup. */ |
Contributor
There was a problem hiding this comment.
nit: I would say the comment is saying the opposite of what the value means.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
UnsafeThirdPartyFunctionCalldetekt rule.*means any non-null type,?means any nullable type.UnsafeThirdPartyFunctionCallis now divided into three subclasses:CodeParserfor Kotlin code parsing, andDetektConfigValidatorandDetektConfigParserfor YAML config parsing and validation.detekt_custom_unsafe_calls.ymlanddetekt_custom_safe_calls.ymlhave been cleaned up according to the new rules.Motivation
An approach to reduce time to green build for each ticket. Fewer retries means less time and lower resource consumption.
Review checklist (to be filled by reviewers)