diff --git a/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java b/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java index 3941ff9f2655..8489dc0f207b 100644 --- a/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java +++ b/java/java-impl/src/com/siyeh/ig/redundancy/RedundantStringOperationInspection.java @@ -1,4 +1,4 @@ -// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2025 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.siyeh.ig.redundancy; import com.intellij.codeInsight.BlockUtils; @@ -1212,19 +1212,15 @@ public final class RedundantStringOperationInspection extends AbstractBaseJavaLo if (!(parent instanceof PsiReferenceExpression ref)) { return; } - PsiElement grandParent = parent.getParent(); - if (!(grandParent instanceof PsiMethodCallExpression)) { - return; - } - PsiElement greatGrandParent = grandParent.getParent(); - if (!(greatGrandParent instanceof PsiReferenceExpression)) { - return; - } PsiExpression qualifier = ref.getQualifierExpression(); if (qualifier == null) { return; } - new CommentTracker().replaceAndRestoreComments(greatGrandParent, qualifier.getText() + ".length()"); + PsiElement grandParent = parent.getParent(); + if (!(grandParent instanceof PsiMethodCallExpression) || !(grandParent.getParent() instanceof PsiReferenceExpression toArrayCall)) { + return; + } + new CommentTracker().replaceAndRestoreComments(toArrayCall, qualifier.getText() + ".length()"); } } }