diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConstructorBodyProcessor.java b/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConstructorBodyProcessor.java index 9a979fff725f..bdb8ae500d3f 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConstructorBodyProcessor.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConstructorBodyProcessor.java @@ -260,7 +260,17 @@ final class ConstructorBodyProcessor { @Override public void visitClass(PsiClass aClass) { - // Empty on purpose. + if (aClass instanceof PsiAnonymousClass anonymousClass) { + PsiExpressionList arguments = anonymousClass.getArgumentList(); + if (arguments != null) { + for (PsiExpression expression : arguments.getExpressions()) { + if (hasReferenceToContainingClass(containingClass, expression)) { + markInvalid(); + return; + } + } + } + } } @Override diff --git a/java/java-tests/testData/inspection/classCanBeRecord/flexibleConstructorBodies/beforeDelegating_11.java b/java/java-tests/testData/inspection/classCanBeRecord/flexibleConstructorBodies/beforeDelegating_11.java new file mode 100644 index 000000000000..f83d6b09a597 --- /dev/null +++ b/java/java-tests/testData/inspection/classCanBeRecord/flexibleConstructorBodies/beforeDelegating_11.java @@ -0,0 +1,20 @@ +// "Convert to record class" "false" +class Person { + final String name; + final int age; + + Person(String name, int age) { + this.name = name; + this.age = age; + } + + Person(Person person) { + new Other(hashCode()) {}; + this(person.name, person.age); + } +} + +class Other { + Other(int x) { + } +} \ No newline at end of file