diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java b/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java index 0977a47762d..1b7a853166a 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/MissingOverride.java @@ -67,6 +67,7 @@ public Description matchMethod(MethodTree tree, VisitorState state) { return NO_MATCH; } if (ASTHelpers.isRecord(sym.owner) + && !sym.isConstructor() && sym.getModifiers().contains(Modifier.PUBLIC) && sym.getParameters().isEmpty()) { ImmutableSet components = diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/MissingOverrideTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/MissingOverrideTest.java index 2618bddfcb7..13ad7ae024c 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/MissingOverrideTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/MissingOverrideTest.java @@ -216,4 +216,23 @@ public int y() { """) .doTest(); } + + @Test + public void explicitRecordAccessor_doesNotFlagConstructors() { + assume().that(Runtime.version().feature()).isAtLeast(16); + + compilationHelper + .addSourceLines( + "Test.java", + """ + public record Test(int x) { + public Test() { + this(1); + } + + public Test {} + } + """) + .doTest(); + } }