File tree Expand file tree Collapse file tree 2 files changed +28
-0
lines changed
main/java/com/google/errorprone/bugpatterns
test/java/com/google/errorprone/bugpatterns Expand file tree Collapse file tree 2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 1717package com .google .errorprone .bugpatterns ;
1818
1919import static com .google .common .collect .Iterables .getOnlyElement ;
20+ import static com .google .common .collect .Streams .stream ;
2021import static com .google .errorprone .BugPattern .SeverityLevel .WARNING ;
2122import static com .google .errorprone .matchers .Description .NO_MATCH ;
2223import static com .google .errorprone .util .ASTHelpers .constValue ;
@@ -64,6 +65,16 @@ private Description handle(
6465 if (args .isEmpty ()) {
6566 return NO_MATCH ;
6667 }
68+ // Bail out if we're calling an overload of the same method: it's likely we'll introduce
69+ // problems (delegating constructors are a common case).
70+ if (stream (state .getPath ().getParentPath ())
71+ .anyMatch (
72+ t ->
73+ getSymbol (t ) instanceof MethodSymbol ms
74+ && ms .owner .equals (symbol .owner )
75+ && ms .name .contentEquals (symbol .name ))) {
76+ return NO_MATCH ;
77+ }
6778 // The last argument isn't substituting for varargs if it isn't in place of the varargs
6879 // parameter.
6980 if (args .size () != symbol .getParameters ().size ()) {
Original file line number Diff line number Diff line change @@ -103,4 +103,21 @@ List<Object> nonempty() {
103103 """ )
104104 .doTest ();
105105 }
106+
107+ @ Test
108+ public void refactoringWouldCauseRecursion () {
109+ helper
110+ .addSourceLines (
111+ "Test.java" ,
112+ """
113+ class Test {
114+ Test() {
115+ this(new String[0]);
116+ }
117+
118+ protected Test(String... xs) {}
119+ }
120+ """ )
121+ .doTest ();
122+ }
106123}
You can’t perform that action at this time.
0 commit comments