Skip to content

Commit

Permalink
UngroupedOverloads: ignore generated constructors
Browse files Browse the repository at this point in the history
Fixes #3404.

Fixes #3632

COPYBARA_INTEGRATE_REVIEW=#3632 from PicnicSupermarket:bugfix/issue-3404 897aa79
PiperOrigin-RevId: 498743314
  • Loading branch information
Stephan202 authored and Error Prone Team committed Dec 31, 2022
1 parent 721096f commit 4fa8720
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,9 @@ public Description matchClass(ClassTree classTree, VisitorState state) {
Tree member = classTree.getMembers().get(i);
if (member instanceof MethodTree) {
MethodTree methodTree = (MethodTree) member;
methods.put(OverloadKey.create(methodTree), MemberWithIndex.create(i, methodTree));
if (!ASTHelpers.isGeneratedConstructor(methodTree)) {
methods.put(OverloadKey.create(methodTree), MemberWithIndex.create(i, methodTree));
}
}
}
ImmutableList<Description> descriptions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@

package com.google.errorprone.bugpatterns;

import static org.junit.Assume.assumeTrue;

import com.google.common.collect.ImmutableList;
import com.google.errorprone.BugCheckerRefactoringTestHelper;
import com.google.errorprone.BugCheckerRefactoringTestHelper.TestMode;
import com.google.errorprone.CompilationTestHelper;
import com.google.errorprone.util.RuntimeVersion;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -287,4 +290,22 @@ public void describingConstructors() {
"}")
.doTest();
}

@Test
public void recordConstructor() {
assumeTrue(RuntimeVersion.isAtLeast16());

compilationHelper
.addSourceLines(
"Test.java",
"import com.google.common.collect.ImmutableSet;",
"import java.util.Set;",
"",
"record MyRecord(ImmutableSet<String> strings) {",
" MyRecord(Set<String> strings) {",
" this(strings == null ? ImmutableSet.of() : ImmutableSet.copyOf(strings));",
" }",
"}")
.doTest();
}
}

0 comments on commit 4fa8720

Please sign in to comment.