Skip to content

Commit

Permalink
UnusedVariable: flag parameters in _effectively_ private methods, not…
Browse files Browse the repository at this point in the history
… just private methods.

PiperOrigin-RevId: 584277317
  • Loading branch information
graememorgan authored and Error Prone Team committed Nov 21, 2023
1 parent 6a23848 commit 88a224c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -686,18 +686,21 @@ private boolean isParameterSubjectToAnalysis(Symbol sym) {
checkArgument(sym.getKind() == ElementKind.PARAMETER);
Symbol enclosingMethod = sym.owner;

for (String annotationName : methodAnnotationsExemptingParameters) {
if (hasAnnotation(enclosingMethod, annotationName, state)) {
return false;
}
if (!(enclosingMethod instanceof MethodSymbol)) {
return false;
}

if (methodAnnotationsExemptingParameters.stream()
.anyMatch(anno -> hasAnnotation(enclosingMethod, anno, state))) {
return false;
}

if (ANNOTATIONS_INDICATING_PARAMETERS_SHOULD_BE_CHECKED.stream()
.anyMatch(a -> hasAnnotation(enclosingMethod, a, state))) {
return true;
}

return enclosingMethod.getModifiers().contains(Modifier.PRIVATE);
return canBeRemoved(enclosingMethod, state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ public void unusedParamInPrivateMethod() {
" private void test(int i, int j) {",
" System.out.println(i);",
" }",
" private class Inner {",
" // BUG: Diagnostic contains: 'j' is never read",
" public void test(int i, int j) {",
" System.out.println(i);",
" }",
" }",
" public void main() {",
" test(1, 2);",
" }",
Expand Down

0 comments on commit 88a224c

Please sign in to comment.