SONARJAVA-6976 Clear check state after file analysis - #6144
romainbrenguier wants to merge 11 commits into
Conversation
…lived processes Move cache clearing (ifStatementCache, firstNullCheckCache, safeSymbols) from the start of scanFile to a finally block, so the last scanned file's AST is not retained for the lifetime of the plugin classloader in IDE sessions (SonarLint). Co-Authored-By: Claude Opus 4.6 <[email protected]>
This comment has been minimized.
This comment has been minimized.
|
❌ Ruling needs updating. A fix PR has been created: #6145 Please review and merge it into your branch. |
|
❌ Ruling needs updating. A fix PR has been created: #6145 Please review and merge it into your branch. |
Ruling Diff SummaryDetected changes in 5 rule files: 0 issues removed, 75 issues added. S1166 (
|
- Remove no-op pre-clear guards before reassignment in NestedIfStatementsCheck and TypeParametersShadowingCheck - Revert unnecessary mutable copy in DepthOfInheritanceTreeCheck (filteredPatterns is a property cache, not AST state) - Fix indentation in ClassImportCouplingCheck finally block - Fix MissingPackageInfoCheckTest: remove assertion on internal state that is now properly cleared in endOfAnalysis Co-Authored-By: Claude Opus 4.6 <[email protected]>
…ghten test - RedundantTypeCastCheck: set warnings = null instead of calling .clear() on the unmodifiable list, which threw UnsupportedOperationException - ClassImportCouplingCheck: remove redundant guarded cleanup blocks that can never execute; simplify to try/finally with null assignments - CheckStateCleanupTest: fix isPropertyCache returning true on empty stream (allMatch vacuous truth) by requiring non-empty value types Co-Authored-By: Claude Opus 4.6 <[email protected]>
✅ All code review findings resolved.
|
❌ Ruling needs updating. A fix PR has been created: #6149 Please review and merge it into your branch. |
…6 ruling Add a protected clearState() hook to IssuableSubscriptionVisitor, called automatically from setContext() before each file analysis. Checks that need to clear per-file state now simply override clearState() instead of duplicating the setContext/leaveFile boilerplate in every file. This eliminates ~210 lines of duplicated code across 14 checks. Also reverts the S1166 ruling file updates that were based on the bug where exceptions/exceptionIdentifiers were incorrectly cleared. Co-Authored-By: Claude Opus 4.6 <[email protected]>
…dant override - Add clearState() call in IssuableSubscriptionVisitor.leaveFile() so state is released after the last file analysis, not just before the next one - Remove redundant setContext() override in UnusedPrivateFieldCheck since the base class already calls clearState() in setContext() - Remove unused JavaFileScannerContext import in UnreachableCatchCheck (SQ QG) - Relax ArchUnit test to accept field cleared by any lifecycle method, since clearState() is called from both setContext() and leaveFile() Co-Authored-By: Claude Opus 4.6 <[email protected]>
Code Review ✅ Approved 13 resolved / 13 findingsClears collection-backed check state at file and module-analysis boundaries to prevent AST retention in long-lived processes. Resolves false positives from S1166 exclusion list wiping, S6539 import recomputation failures, S120 project-level accumulator clearing at file start, and several other check state lifecycle issues including redundant clears, dead code, and missing cleanup calls. ✅ 13 resolved✅ Bug: S1166: exclusion list wiped after first file (false positives)
✅ Bug: S6539: imports never recomputed after first file
✅ Bug: S120: project-level accumulator cleared at start of each file
✅ Quality: CheckStateCleanupTest does not enforce what it claims
✅ Performance: IndentationCheck copies all file lines just to clear them
...and 8 more resolved from earlier reviews Review coverageFunctional validation No results OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|




Summary
Validation