Skip to content

SONARJAVA-4473 Add exception on S2384 for private methods #4985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rules/S2384/java/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ Instead use an unmodifiable ``++Collection++`` (via ``++Collections.unmodifiable

This rule checks that private arrays, collections and Dates are not stored or returned directly.

=== Exceptions ===

The rule violation is not reported for private methods due to the safety provided by the restricted scope.

=== Noncompliant code example

[source,java]
Expand Down Expand Up @@ -54,6 +58,10 @@ class A {
return strings.clone();
}

private void setStringsInternal(String [] strings) {
this.strings = strings;
}

public void setStrings(String [] strings) {
this.strings = strings.clone();
}
Expand Down