diff --git a/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariable.java b/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariable.java index eec50a07517..068e7a84a85 100644 --- a/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariable.java +++ b/core/src/main/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariable.java @@ -287,7 +287,8 @@ private static boolean isBoxableType(Type type, VisitorState state) { private static boolean canChangeMethodSignature(VisitorState state, MethodSymbol methodSymbol) { return !ASTHelpers.methodCanBeOverridden(methodSymbol) - && ASTHelpers.findSuperMethods(methodSymbol, state.getTypes()).isEmpty(); + && ASTHelpers.findSuperMethods(methodSymbol, state.getTypes()).isEmpty() + && !ASTHelpers.isRecord(methodSymbol); } private static class FindBoxedUsagesScanner extends TreePathScanner { diff --git a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java index 74c5212ed8e..89032326634 100644 --- a/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java +++ b/core/src/test/java/com/google/errorprone/bugpatterns/UnnecessaryBoxedVariableTest.java @@ -527,4 +527,21 @@ static Foo create(Integer foo, Boolean bar) { .setArgs(ImmutableList.of("-processor", AutoValueProcessor.class.getName())) .doTest(); } + + @Test + public void recordsIgnored() { + compilationTestHelper + .addSourceLines( + "Foo.java", + """ + import static com.google.common.base.Preconditions.checkNotNull; + + record Foo(Integer foo, boolean bar) { + Foo { + checkNotNull(foo); + } + } + """) + .doTest(); + } }