diff --git a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java index b555f6600a22..3789fc270db6 100644 --- a/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java +++ b/java/java-analysis-impl/src/com/intellij/codeInsight/daemon/impl/analysis/HighlightControlFlowUtil.java @@ -543,11 +543,15 @@ public class HighlightControlFlowUtil { (PsiMethod)codeBlock.getParent() : null; // assignment to final field in several constructors threatens us only if these are linked (there is this() call in the beginning) final List redirectedConstructors = ctr != null && ctr.isConstructor() ? JavaHighlightUtil.getChainedConstructors(ctr) : Collections.emptyList(); - for (PsiMethod redirectedConstructor : redirectedConstructors) { - PsiCodeBlock body = redirectedConstructor.getBody(); - if (body != null && variableDefinitelyAssignedIn(variable, body)) { - alreadyAssigned = true; - break; + if (!redirectedConstructors.isEmpty() && aClass.isRecord()) { + alreadyAssigned = true; + } else { + for (PsiMethod redirectedConstructor : redirectedConstructors) { + PsiCodeBlock body = redirectedConstructor.getBody(); + if (body != null && variableDefinitelyAssignedIn(variable, body)) { + alreadyAssigned = true; + break; + } } } } diff --git a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingRecords/RecordConstructors.java b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingRecords/RecordConstructors.java index c8209d32456f..5a8fd57da8f2 100644 --- a/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingRecords/RecordConstructors.java +++ b/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/advHighlightingRecords/RecordConstructors.java @@ -35,7 +35,7 @@ record VarArgMismatch2(int[] x) { record Delegate(int x) { public Delegate(int x) { this(); - this.x = 0; + this.x = 0; } public Delegate() { @@ -57,4 +57,14 @@ record ImplicitCanonicalConstructor(String s) { static void test() { new ImplicitCanonicalConstructor("Asdasd"); } +} +record AssignmentInNonCanonical(int x, int y, long depth) { + public AssignmentInNonCanonical(int x, int y) { + this(x, y, 10); + this.x = x; + } + + void method() { + this.x = 0; + } } \ No newline at end of file