diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java b/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java index c29df14641a2..7ef3334b7a63 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/UngroupedOverloads.java @@ -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 descriptions = diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java index 69c33408a9fc..f2fb2305beba 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UngroupedOverloadsTest.java @@ -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; @@ -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 strings) {", + " MyRecord(Set strings) {", + " this(strings == null ? ImmutableSet.of() : ImmutableSet.copyOf(strings));", + " }", + "}") + .doTest(); + } }