Skip to content

RUM-16478: UnsafeThirdPartyFunctionCall improvements#3557

Open
satween wants to merge 2 commits into
developfrom
tvaleev/feature/RUM-16478
Open

RUM-16478: UnsafeThirdPartyFunctionCall improvements#3557
satween wants to merge 2 commits into
developfrom
tvaleev/feature/RUM-16478

Conversation

@satween

@satween satween commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

  • Adds generics support for the UnsafeThirdPartyFunctionCall detekt rule. * means any non-null type, ? means any nullable type.
  • Adds configuration self-checks: verifies that all records in each config are unique.
  • Adds configuration self-checks: prevents the same method from being added to controversial (safe and unsafe) configs at the same time.
  • UnsafeThirdPartyFunctionCall is now divided into three subclasses: CodeParser for Kotlin code parsing, and DetektConfigValidator and DetektConfigParser for YAML config parsing and validation.
  • detekt_custom_unsafe_calls.yml and detekt_custom_safe_calls.yml have 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)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)

satween added 2 commits June 16, 2026 17:39
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.
@satween satween requested review from a team as code owners June 18, 2026 16:16
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.39%. Comparing base (bc840ec) to head (af9aead).
⚠️ Report is 13 commits behind head on develop.

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     

see 41 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hamorillo hamorillo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()}."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ 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. */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would say the comment is saying the opposite of what the value means.

@sbarrio sbarrio requested a review from hamorillo June 19, 2026 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants