SONARJAVA-6870: Fix FP in S9342 when zip stream is wrapped in custom OutputStream - #6056
SONARJAVA-6870: Fix FP in S9342 when zip stream is wrapped in custom OutputStream#6056romainbrenguier wants to merge 2 commits into
Conversation
…utputStream Add test example where ObjectMapper writes to a custom OutputStream wrapping a ZipOutputStream. Fix clearTrackedSymbolsUsedAsArguments to deeply scan non-identifier arguments for tracked symbol usage, preventing false positives when the zip stream is passed to a constructor nested inside a method call argument. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Unwrap casts and parenthesized expressions before checking if an argument is a tracked symbol, fixing FPs like `(OutputStream) zos`. Extract a shared removeUsedSymbols helper to eliminate duplicated visitor logic between scanForTrackedSymbolUsage and clearTrackedSymbolsUsedAsArguments. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Code Review ✅ Approved 2 resolved / 2 findingsFixes false positives in S9342 when a ✅ 2 resolved✅ Edge Case: Deep argument scan misses symbols behind casts or parentheses
✅ Quality: Duplicated visitor/removal logic and per-argument visitor allocation
Implementation Status ◻️ 2 of 3 objectives covered◻️ SONARJAVA-6870 - 2 of 3 objectives coveredThis PR fixes the false positive in S9342 when a zip stream is wrapped in a custom OutputStream or passed via casts and parentheses. Other objectives on this issue, possibly covered elsewhere:
✅ 2 covered here
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
ObjectMapper.writeValuewrites to a customOutputStreamwrapping aZipOutputStreamclearTrackedSymbolsUsedAsArgumentsto deeply scan non-identifier arguments (e.g.,new CustomOutputStream(zos)) for tracked symbol usage, preventing false positives when the zip stream is nested inside a constructor call within a method argumentTest plan
EmptyArchiveEntryCheckTestpasses (both with and without semantic)🤖 Generated with Claude Code