[GCI27] System.arraycopy cannot always be used#193
Open
MohamedAliSidibe wants to merge 2 commits into
Open
Conversation
Author
|
Closes #19 |
Author
|
Mahamadou Ali Sidibe / LesShreks des dépendances moisies / CGI |
jbureau92
requested changes
May 20, 2026
Contributor
There was a problem hiding this comment.
Thank you for this PR! The logic change to avoid flagging array copies inside conditional and try/catch blocks is correct and well-tested.
Few fixes are needed in changelog, see inline comments.
GCIRulesIT.java is still configured to expect 36 issues at the old line numbers, which means the tests will fail
Nice to have: Branch coverage is 79.2% on ArrayCopyCheck (just below the 80% threshold). Adding one more test covering an uncovered branch path would push it over the threshold.
|
|
||
| - Update ecocode-rules-specifications to 1.4.6 | ||
|
|
||
| ## [unreleased] |
|
|
||
| - #193 GCI27 - reduce false positives for System.arraycopy suggestions inside conditional and try/catch blocks | ||
|
|
||
| ## [2.1.2] - 2026-05-20 |
|
|
||
| ### Changed | ||
|
|
||
| - #193 GCI27 - reduce false positives for System.arraycopy suggestions inside conditional and try/catch blocks |
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.
Description
This PR fixes false positives in rule
GCI27(Use System.arraycopy to copy arrays).Previously, the rule analyzed nested assignments inside conditional and try/catch/finally blocks, which caused incorrect suggestions of
System.arraycopy(...)for code performing filtering or conditional logic.Example of previous false positive:
This pattern cannot be safely replaced by
System.arraycopybecause it performs conditional filtering instead of a direct array copy.Changes
Removed recursive extraction of nested assignments inside:
iftrycatchfinallyThe rule now analyzes only direct assignments located in the main loop block.
Result
The rule still detects valid direct array copy patterns such as:
while avoiding false positives for conditional or transformed copies.