From cbd248b3c7da7903e5ba33b15599ac214302ab98 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 11 Sep 2025 16:33:23 +0200 Subject: [PATCH] exception in inspection visitor must not crash other inspections to fix IJPL-207109 exception in grazie inspection should not halt the entire highlighting GitOrigin-RevId: 43f00601ed8bed117f38843fcdb7607dcfb7e9a0 --- .../daemon/impl/InspectionRunner.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InspectionRunner.java b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InspectionRunner.java index f6aa1465249b..bf816b9d4dbe 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InspectionRunner.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/daemon/impl/InspectionRunner.java @@ -88,7 +88,7 @@ class InspectionRunner { // The containing file this tool was called for. In the case of injected context, this will be the injected file. @NotNull PsiFile psiFile) { @Override - public String toString() { + public @NotNull String toString() { return tool +"; inside:"+elementsInside().size()+"; outside:"+elementsOutside().size(); } } @@ -403,15 +403,22 @@ class InspectionRunner { * (starting from this inspection's most fertile elements if any), * maintaining parallelism during this process (i.e., several visitors from {@code init} can be executed concurrently, but elements from the list head get higher priority than the list tail). */ - private static void processContext(@NotNull InspectionContext context, List psiElements, + private static void processContext(@NotNull InspectionContext context, + @NotNull @Unmodifiable List psiElements, @NotNull InspectionVisitorOptimizer optimizer) { if (LOG.isTraceEnabled()) { LOG.trace("processContext: " + context + "; elements(" + psiElements.size() + "): " + StringUtil.join(psiElements, e-> e + "(" + e.getClass() + ")", ", ") + "; accepts=" + context.acceptingPsiTypes()); } - optimizer.acceptElements(psiElements, - context.acceptingPsiTypes, - psiElement -> context.holder.visitElement(psiElement, context.visitor)); + try { + optimizer.acceptElements(psiElements, + context.acceptingPsiTypes, + psiElement -> context.holder.visitElement(psiElement, context.visitor)); + } + catch (Throwable t) { + if (Logger.shouldRethrow(t)) throw t; + LOG.error(t); + } } private void injectedFound(@NotNull PsiFile injectedPsi, @NotNull PsiElement host, @NotNull LocalInspectionToolSession session,