IconProvider Problem in IntelliJ 2023

Answered

I am using an IconProvider (com.intellij.ide.IconProvider) to add an overlay to the icons of some java classes and it had been working for years. Since version 2023.X it throws an exception:

Must be executed under progress indicator: com.intellij.openapi.progress.EmptyProgressIndicator@44a65a1b. Please see e.g. ProgressManager.runProcess()

The code that causes the problem is called in the “getIcon” method:

Query<PsiReference> search = ReferencesSearch.search(psiClass, GlobalSearchScope.moduleWithDependentsScope(module));
Collection<PsiReference> us = search.findAll();

 

So I tried to wrap my code, as suggested by the exception:

return ProgressManager.getInstance().runProcess(() -> {
    // my code
}, ProgressManager.getInstance().getProgressIndicator()

Then I get the following exception:

This thread is already running under this indicator, starting/stopping it here might be a data race    

 

Next try:

return ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
    // my code
}, "Searching", false, psiElement.getProject()

 

But also no success:

Calling invokeAndWait from read-action leads to possible deadlock.

 

I need the ReferencesSearch because I have to add the icon to classes that are 

  • directly referenced in an XML file (no problem because it works without ReferencesSearch)
  • classes that are instantiated in another class, that is referenced in an XML file (throws the exception because of ReferencesSearch)

 

Any idea what to change to make it work again?

0
6 comments

Hi Tom,

Could you please provide full stacktrace?

0
java.lang.Throwable: Must be executed under progress indicator: com.intellij.openapi.progress.EmptyProgressIndicator@4d93b327. Please see e.g. ProgressManager.runProcess()
    at com.intellij.openapi.diagnostic.Logger.error(Logger.java:370)
    at com.intellij.openapi.progress.impl.CoreProgressManager.assertUnderProgress(CoreProgressManager.java:996)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processFilesConcurrentlyDespiteWriteActions(PsiSearchHelperImpl.java:440)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.lambda$processPsiFileRoots$8(PsiSearchHelperImpl.java:408)
    at com.intellij.psi.impl.PsiManagerImpl.runInBatchFilesMode(PsiManagerImpl.java:455)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processPsiFileRoots(PsiSearchHelperImpl.java:401)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processCandidates(PsiSearchHelperImpl.java:920)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processGlobalRequests(PsiSearchHelperImpl.java:890)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processGlobalRequestsOptimized(PsiSearchHelperImpl.java:856)
    at com.intellij.psi.impl.search.PsiSearchHelperImpl.processRequests(PsiSearchHelperImpl.java:781)
    at com.intellij.psi.search.SearchRequestQuery.processResults(SearchRequestQuery.java:21)
    at com.intellij.util.AbstractQuery.doProcessResults(AbstractQuery.java:88)
    at com.intellij.util.AbstractQuery.delegateProcessResults(AbstractQuery.java:105)
    at com.intellij.util.MergeQuery.processResults(MergeQuery.java:22)
    at com.intellij.util.AbstractQuery.doProcessResults(AbstractQuery.java:88)
    at com.intellij.util.AbstractQuery.delegateProcessResults(AbstractQuery.java:105)
    at com.intellij.util.UniqueResultsQuery.processResults(UniqueResultsQuery.java:37)
    at com.intellij.util.AbstractQuery.doProcessResults(AbstractQuery.java:88)
    at com.intellij.util.AbstractQuery.forEach(AbstractQuery.java:80)
    at com.intellij.util.AbstractQuery.findAll(AbstractQuery.java:25)
    at de.my.plugin.caches.NavFilesIndexUtil.getIndirectUsageClasses(NavFilesIndexUtil.java:116)
    at de.my.plugin.codehighlighting.NavHighlightingUtil.lambda$getSysNavInfoText$0(NavHighlightingUtil.java:76)
    at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:909)
    at de.my.plugin.codehighlighting.NavHighlightingUtil.getSysNavInfoText(NavHighlightingUtil.java:43)
    at de.my.plugin.codehighlighting.NavigationIconProvider.handleClass(NavigationIconProvider.java:51)
    at de.my.plugin.codehighlighting.NavigationIconProvider.getIconInternal(NavigationIconProvider.java:39)
    at de.my.plugin.codehighlighting.IconProviderBase.getIcon(IconProviderBase.java:22)
    at com.intellij.util.PsiIconUtil.getProvidersIcon(PsiIconUtil.java:21)
    at com.intellij.psi.impl.ElementBase.doComputeIconNow(ElementBase.java:98)
    at com.intellij.psi.impl.ElementBase.lambda$computeIconNow$3(ElementBase.java:94)
    at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:130)
    at com.intellij.util.AstLoadingFilter.disallowTreeLoading(AstLoadingFilter.java:119)
    at com.intellij.psi.impl.ElementBase.computeIconNow(ElementBase.java:94)
    at com.intellij.psi.impl.ElementBase.lambda$static$0(ElementBase.java:45)
    at com.intellij.ui.DeferredIconImpl.evaluate(DeferredIconImpl.kt:279)
    at com.intellij.ui.DeferredIconImpl$scheduleCalculationIfNeeded$1$result$1$1.invoke(DeferredIconImpl.kt:218)
    at com.intellij.ui.DeferredIconImpl$scheduleCalculationIfNeeded$1$result$1$1.invoke(DeferredIconImpl.kt:218)
    at com.intellij.openapi.application.rw.InternalReadAction.insideReadAction(InternalReadAction.kt:105)
    at com.intellij.openapi.application.rw.InternalReadAction.access$insideReadAction(InternalReadAction.kt:14)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadCancellable$2.invoke(InternalReadAction.kt:95)
    at com.intellij.openapi.application.rw.InternalReadAction$tryReadCancellable$2.invoke(InternalReadAction.kt:94)
    at com.intellij.openapi.application.rw.CancellableReadActionKt$cancellableReadActionInternal$1.invoke$lambda$1$lambda$0(cancellableReadAction.kt:41)
    at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1133)
    at com.intellij.openapi.application.rw.CancellableReadActionKt$cancellableReadActionInternal$1.invoke$lambda$1(cancellableReadAction.kt:39)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtilService.runActionAndCancelBeforeWrite(ProgressIndicatorUtilService.java:63)
    at com.intellij.openapi.progress.util.ProgressIndicatorUtils.runActionAndCancelBeforeWrite(ProgressIndicatorUtils.java:133)
    at com.intellij.openapi.application.rw.CancellableReadActionKt$cancellableReadActionInternal$1.invoke(cancellableReadAction.kt:37)
    at com.intellij.openapi.progress.CoroutinesKt.blockingContext(coroutines.kt:248)
    at com.intellij.openapi.application.rw.CancellableReadActionKt.cancellableReadActionInternal(cancellableReadAction.kt:34)
    at com.intellij.openapi.application.rw.InternalReadAction.tryReadCancellable(InternalReadAction.kt:94)
    at com.intellij.openapi.application.rw.InternalReadAction.tryReadAction(InternalReadAction.kt:76)
    at com.intellij.openapi.application.rw.InternalReadAction.readLoop(InternalReadAction.kt:63)
    at com.intellij.openapi.application.rw.InternalReadAction.access$readLoop(InternalReadAction.kt:14)
    at com.intellij.openapi.application.rw.InternalReadAction$runReadAction$4.invokeSuspend(InternalReadAction.kt:42)
    at com.intellij.openapi.application.rw.InternalReadAction$runReadAction$4.invoke(InternalReadAction.kt)
    at com.intellij.openapi.application.rw.InternalReadAction$runReadAction$4.invoke(InternalReadAction.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at com.intellij.openapi.application.rw.InternalReadAction.runReadAction(InternalReadAction.kt:38)
    at com.intellij.openapi.application.rw.PlatformReadWriteActionSupport.executeReadAction(PlatformReadWriteActionSupport.kt:38)
    at com.intellij.openapi.application.ReadWriteActionSupport.executeReadAction$default(ReadWriteActionSupport.kt:15)
    at com.intellij.openapi.application.CoroutinesKt.constrainedReadAction(coroutines.kt:58)
    at com.intellij.openapi.application.CoroutinesKt.readAction(coroutines.kt:25)
    at com.intellij.ui.DeferredIconImpl$scheduleCalculationIfNeeded$1$invokeSuspend$$inlined$evaluateDeferred$1.invokeSuspend(IconDeferrerImpl.kt:91)
    at com.intellij.ui.DeferredIconImpl$scheduleCalculationIfNeeded$1$invokeSuspend$$inlined$evaluateDeferred$1.invoke(IconDeferrerImpl.kt)
    at com.intellij.ui.DeferredIconImpl$scheduleCalculationIfNeeded$1$invokeSuspend$$inlined$evaluateDeferred$1.invoke(IconDeferrerImpl.kt)
    at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
    at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
    at kotlinx.coroutines.BuildersKt.withContext(Unknown Source)
    at com.intellij.ui.DeferredIconImpl$scheduleCalculationIfNeeded$1.invokeSuspend(DeferredIconImpl.kt:374)
    at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
    at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
    at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
    at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
0

I tried to reproduce the problem by implementing a dummy icon provider with a similar logic, but could not. I run it under 2023.1.5.

Could you please share your code or create a reproducible example with a test project and steps to reproduce?

If you can share the code, but don't want to make it public, you can share it with https://uploads.jetbrains.com/browse and provide me with the upload ID (only JetBrains employees can access uploaded files).

0

I uploaded a minimal example that reproduces the problem with the latest stable version 2023.2.2

Upload id: 2023_09_19_23SBu73GV3gcrCBCeWwbBC (file: icontest.zip)

 

0

I think the problem is that the “find usages” should be run under a progress indicator. 
could you please try
 

return ProgressManager.getInstance().runProcess(() -> {
    // my code
}, new ProgressIndicatorBase());
0

Thank you, that solved my problem.

I had already tried it with ProgressManager but it seems my problem was, that I used

 ProgressManager.getInstance().getProgressIndicator()

instead of

new ProgressIndicatorBase()
0

Please sign in to leave a comment.