From 442f8b7ad162d13e4e240938164aaafcab15635b Mon Sep 17 00:00:00 2001 From: Ilia Permiashkin Date: Mon, 6 Oct 2025 17:44:09 +0000 Subject: [PATCH] [grazie] IJPL-211382 GrazieSpellCheckingInspection throws INRE in dumb mode Merge-request: IJ-MR-177658 Merged-by: Ilia Permiashkin GitOrigin-RevId: 487a202322628724de8f61ee186e490c5f80333c --- .../spellcheck/GrazieSpellCheckingInspection.java | 15 +++++++++++++++ plugins/grazie/src/test/BUILD.bazel | 1 + plugins/grazie/src/test/intellij.grazie.tests.iml | 1 + .../grazie/ide/language/JavaSupportTest.kt | 7 ++++++- .../NonNlsLocalVariableAndCommentDumb.java | 7 +++++++ .../JavaSpellcheckerInspectionTest.java | 3 ++- 6 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 plugins/java-i18n/testData/inspections/spellchecker/NonNlsLocalVariableAndCommentDumb.java diff --git a/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java b/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java index d0d0ba462e1b..f516e13e1ad8 100644 --- a/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java +++ b/plugins/grazie/src/main/kotlin/com/intellij/grazie/spellcheck/GrazieSpellCheckingInspection.java @@ -37,6 +37,8 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import com.intellij.openapi.project.DumbService; + import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.regex.Pattern; @@ -325,6 +327,19 @@ public final class GrazieSpellCheckingInspection extends SpellCheckingInspection return false; } + if (DumbService.isDumb(file.getProject())) { + for (int occurrence : occurrences) { + PsiElement element = file.findElementAt(occurrence); + if (element != null) { + SpellcheckingStrategy strategy = getSpellcheckingStrategy(element); + if (strategy != null && !strategy.elementFitsScope(element, Set.of(SpellCheckingScope.Comments))) { + return true; + } + } + } + return false; + } + for (int occurrence : occurrences) { PsiReference reference = file.findReferenceAt(occurrence); PsiElement resolvedReference = reference != null ? reference.resolve() : null; diff --git a/plugins/grazie/src/test/BUILD.bazel b/plugins/grazie/src/test/BUILD.bazel index 0305857f75e9..e5132833615e 100644 --- a/plugins/grazie/src/test/BUILD.bazel +++ b/plugins/grazie/src/test/BUILD.bazel @@ -25,6 +25,7 @@ jvm_library( "//platform/core-ui", "//platform/editor-ui-api:editor-ui", "//platform/projectModel-api:projectModel", + "//platform/util/jdom", "//spellchecker", "//spellchecker:spellchecker_test_lib", "//plugins/grazie", diff --git a/plugins/grazie/src/test/intellij.grazie.tests.iml b/plugins/grazie/src/test/intellij.grazie.tests.iml index f7bdf61c2816..becf50f40c03 100644 --- a/plugins/grazie/src/test/intellij.grazie.tests.iml +++ b/plugins/grazie/src/test/intellij.grazie.tests.iml @@ -13,6 +13,7 @@ + diff --git a/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/JavaSupportTest.kt b/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/JavaSupportTest.kt index 3b4158ee6fa1..ad7b026d5546 100644 --- a/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/JavaSupportTest.kt +++ b/plugins/grazie/src/test/kotlin/com/intellij/grazie/ide/language/JavaSupportTest.kt @@ -1,15 +1,17 @@ // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.grazie.ide.language +import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer +import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl import com.intellij.grazie.GrazieTestBase import com.intellij.grazie.jlanguage.Lang import com.intellij.grazie.spellcheck.engine.GrazieSpellCheckerEngine -import com.intellij.openapi.components.service import com.intellij.openapi.util.Disposer import com.intellij.spellchecker.ProjectDictionaryLayer import com.intellij.spellchecker.SpellCheckerManager import com.intellij.spellchecker.dictionary.Loader import com.intellij.spellchecker.settings.SpellCheckerSettings +import com.intellij.testFramework.DumbModeTestUtils.runInDumbModeSynchronously import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase import com.intellij.tools.ide.metrics.benchmark.Benchmark @@ -69,6 +71,9 @@ class JavaSupportTest : GrazieTestBase() { fun testCommentIsNotHighlightedIfThereIsReference() { runHighlightTestForFile("ide/language/java/VectorablexxClass.java") + + (DaemonCodeAnalyzer.getInstance(project) as DaemonCodeAnalyzerImpl).mustWaitForSmartMode(false, testRootDisposable) + runInDumbModeSynchronously(project) { runHighlightTestForFile("ide/language/java/VectorablexxClass.java") } } fun `test spellchecking normalization`() { diff --git a/plugins/java-i18n/testData/inspections/spellchecker/NonNlsLocalVariableAndCommentDumb.java b/plugins/java-i18n/testData/inspections/spellchecker/NonNlsLocalVariableAndCommentDumb.java new file mode 100644 index 000000000000..f44b091ba8e3 --- /dev/null +++ b/plugins/java-i18n/testData/inspections/spellchecker/NonNlsLocalVariableAndCommentDumb.java @@ -0,0 +1,7 @@ +import org.jetbrains.annotations.NonNls; + +class Test { + void m() { + @NonNls String s = "CONASTANT"; // CONASTANT comment + } +} \ No newline at end of file diff --git a/plugins/java-i18n/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckerInspectionTest.java b/plugins/java-i18n/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckerInspectionTest.java index a7f70a95f66d..c73a508ade17 100644 --- a/plugins/java-i18n/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckerInspectionTest.java +++ b/plugins/java-i18n/testSrc/com/intellij/spellchecker/inspection/JavaSpellcheckerInspectionTest.java @@ -49,7 +49,8 @@ public class JavaSpellcheckerInspectionTest extends LightJavaCodeInsightFixtureT public void testNonNlsField() { doTestInAllModes(); } public void testNonNlsField2() { doTestInAllModes(); } public void testNonNlsLocalVariable() { doTestInAllModes(); } - public void testNonNlsLocalVariableAndComment() { doTestInAllModes(); } + public void testNonNlsLocalVariableAndComment() { doTest(false); } + public void testNonNlsLocalVariableAndCommentDumb() { doTest(true); } public void testFieldComment() { doTestInAllModes(); } public void testDoNotCheckDerivedNames() { doTestInAllModes(); } public void testSkipDateTime() { doTestInAllModes(); }