Skip to content
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

UngroupedOverloads: ignore generated constructors #3632

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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));
}
Comment on lines +99 to +101
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check matches the constraint that otherwise triggers the IllegalArgumentException reported in #3404. As these generated constructors are invisible, it makes sense (I suppose) that UngroupedOverloads shouldn't care about their location.

}
}
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();
}
}