diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/DeconstructionCanBeUsedInspection.java b/java/java-impl-inspections/src/com/intellij/codeInspection/DeconstructionCanBeUsedInspection.java index 41be992d3803..7999e77a5d8c 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/DeconstructionCanBeUsedInspection.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/DeconstructionCanBeUsedInspection.java @@ -66,16 +66,13 @@ public final class DeconstructionCanBeUsedInspection extends AbstractBaseJavaLoc continue; } PsiRecordComponent component = getComponent(reference); - if (component == null) continue; + if (component == null) return Collections.emptyList(); if (!used.add(component) && !shouldFindAll) continue; PsiElementFactory factory = PsiElementFactory.getInstance(reference.getProject()); PsiExpression call = factory.createExpressionFromText(reference.getText() + "." + component.getName() + "()", reference); if (SideEffectChecker.mayHaveSideEffects(call)) return Collections.emptyList(); int index = ArrayUtil.indexOf(components, component); result.get(index).add((PsiReferenceExpression)PsiUtil.skipParenthesizedExprUp(reference.getParent())); - if (!shouldFindAll && used.size() == components.length) { - return result; - } } return used.size() == components.length ? result : Collections.emptyList(); } diff --git a/java/java-tests/testData/inspection/deconstructionCanBeUsed/beforeUseAsReference.java b/java/java-tests/testData/inspection/deconstructionCanBeUsed/beforeUseAsReference.java new file mode 100644 index 000000000000..88f92e8dabd5 --- /dev/null +++ b/java/java-tests/testData/inspection/deconstructionCanBeUsed/beforeUseAsReference.java @@ -0,0 +1,13 @@ +// "Replace with record pattern" "false" +class X { + record R(String oldText, String newText) { + } + + void patternBug(Object obj) { + if (obj instanceof R r) { + System.out.println(r.oldText()); + System.out.println(r.newText()); + System.out.println(r); + } + } +} \ No newline at end of file