Error when I try to remove extension association

已回答

I tried this code in my intellij plugin and it crashes with strange error. What is the reason? 

FileTypeManager fileTypeManager = FileTypeManager.getInstance();
fileTypeManager.removeAssociatedExtension(FileTypes.PLAIN_TEXT, "eo");

Plugin 'org.antlr.jetbrains.eo' failed to initialize and will be disabled. Please restart IntelliJ IDEA.

CompositeException (2 nested):
------------------------------
[0]: com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@19535db1
Current thread: Thread[ApplicationImpl pooled thread 4,4,Idea Thread Group] 2108383111
Write thread (volatile): Thread[AWT-EventQueue-0,6,Idea Thread Group] 843795598com.intellij.openapi.diagnostic.Attachment@37047243
    at com.intellij.openapi.application.impl.ApplicationImpl.assertIsWriteThread(ApplicationImpl.java:1099)
    at com.intellij.openapi.application.impl.ApplicationImpl.assertIsWriteThread(ApplicationImpl.java:1078)
    at com.intellij.openapi.roots.impl.OrderRootsCache.clearCache(OrderRootsCache.java:85)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.clearScopesCachesForModules(ProjectRootManagerImpl.java:415)
    at com.intellij.openapi.roots.impl.ProjectRootManagerComponent.clearScopesCachesForModules(ProjectRootManagerComponent.java:326)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.clearScopesCaches(ProjectRootManagerImpl.java:410)
    at com.intellij.openapi.roots.impl.ProjectRootManagerComponent.clearScopesCaches(ProjectRootManagerComponent.java:316)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl.fireRootsChanged(ProjectRootManagerImpl.java:455)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl$2.fireRootsChanged(ProjectRootManagerImpl.java:167)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl$2.fireRootsChanged(ProjectRootManagerImpl.java:164)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl$BatchSession.rootsChanged(ProjectRootManagerImpl.java:113)
    at com.intellij.openapi.roots.impl.ProjectRootManagerImpl$BatchSession.rootsChanged(ProjectRootManagerImpl.java:121)
    at com.intellij.openapi.roots.impl.ProjectRootManagerComponent$1.fileTypesChanged(ProjectRootManagerComponent.java:99)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.intellij.util.messages.impl.MessageBusImpl.invokeListener(MessageBusImpl.java:656)
    at com.intellij.util.messages.impl.MessageBusImpl.deliverMessage(MessageBusImpl.java:426)
    at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:401)
    at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:383)
    at com.intellij.util.messages.impl.MessageBusImpl.access$100(MessageBusImpl.java:33)
    at com.intellij.util.messages.impl.MessageBusImpl$MessagePublisher.invoke(MessageBusImpl.java:189)
    at com.sun.proxy.$Proxy58.fileTypesChanged(Unknown Source)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.fireFileTypesChanged(FileTypeManagerImpl.java:816)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.fireFileTypesChanged(FileTypeManagerImpl.java:810)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.removeAssociation(FileTypeManagerImpl.java:1324)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.removeAssociation(FileTypeManagerImpl.java:798)
    at com.intellij.openapi.fileTypes.FileTypeManager.removeAssociatedExtension(FileTypeManager.java:163)
    at org.eolang.jetbrains.EOPluginController.initComponent(EOPluginController.java:48)
    at com.intellij.serviceContainer.MyComponentAdapter.doCreateInstance(MyComponentAdapter.kt:44)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstanceUncached(BaseComponentAdapter.kt:113)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstance(BaseComponentAdapter.kt:67)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstance$default(BaseComponentAdapter.kt:60)
    at com.intellij.serviceContainer.ComponentManagerImpl.createComponents(ComponentManagerImpl.kt:304)
    at com.intellij.openapi.project.impl.ProjectExImpl.init(ProjectExImpl.kt:177)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.initProject(ProjectManagerImpl.java:173)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl.prepareProject(ProjectManagerExImpl.kt:242)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl.access$prepareProject(ProjectManagerExImpl.kt:52)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl$openProject$$inlined$runInAutoSaveDisabledMode$lambda$1.invoke(ProjectManagerExImpl.kt:104)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl$openProject$$inlined$runInAutoSaveDisabledMode$lambda$1.invoke(ProjectManagerExImpl.kt:52)
    at com.intellij.openapi.project.impl.ProjectUiFrameAllocator$run$progressTask$1.run(ProjectFrameAllocator.kt:86)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$new$0(ProgressRunner.java:79)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:235)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:178)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:658)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:610)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:65)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:165)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:235)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:834)

[1]: com.intellij.openapi.diagnostic.RuntimeExceptionWithAttachments: EventQueue.isDispatchThread()=false Toolkit.getEventQueue()=com.intellij.ide.IdeEventQueue@19535db1
Current thread: Thread[ApplicationImpl pooled thread 4,4,Idea Thread Group] 2108383111
SystemEventQueueThread: Thread[AWT-EventQueue-0,6,Idea Thread Group] 843795598
    at com.intellij.openapi.application.impl.ApplicationImpl.throwThreadAccessException(ApplicationImpl.java:1088)
    at com.intellij.openapi.application.impl.ApplicationImpl.assertIsDispatchThread(ApplicationImpl.java:1063)
    at com.intellij.codeInsight.daemon.impl.IntentionsUIImpl.hide(IntentionsUIImpl.java:58)
    at com.intellij.codeInsight.daemon.impl.IntentionsUI.invalidate(IntentionsUI.java:41)
    at com.intellij.codeInsight.daemon.impl.DaemonListeners$9.fileTypesChanged(DaemonListeners.java:299)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at com.intellij.util.messages.impl.MessageBusImpl.invokeListener(MessageBusImpl.java:656)
    at com.intellij.util.messages.impl.MessageBusImpl.deliverMessage(MessageBusImpl.java:426)
    at com.intellij.util.messages.impl.MessageBusImpl.pumpWaitingBuses(MessageBusImpl.java:401)
    at com.intellij.util.messages.impl.MessageBusImpl.pumpMessages(MessageBusImpl.java:383)
    at com.intellij.util.messages.impl.MessageBusImpl.access$100(MessageBusImpl.java:33)
    at com.intellij.util.messages.impl.MessageBusImpl$MessagePublisher.invoke(MessageBusImpl.java:189)
    at com.sun.proxy.$Proxy58.fileTypesChanged(Unknown Source)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.fireFileTypesChanged(FileTypeManagerImpl.java:816)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.fireFileTypesChanged(FileTypeManagerImpl.java:810)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.removeAssociation(FileTypeManagerImpl.java:1324)
    at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.removeAssociation(FileTypeManagerImpl.java:798)
    at com.intellij.openapi.fileTypes.FileTypeManager.removeAssociatedExtension(FileTypeManager.java:163)
    at org.eolang.jetbrains.EOPluginController.initComponent(EOPluginController.java:48)
    at com.intellij.serviceContainer.MyComponentAdapter.doCreateInstance(MyComponentAdapter.kt:44)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstanceUncached(BaseComponentAdapter.kt:113)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstance(BaseComponentAdapter.kt:67)
    at com.intellij.serviceContainer.BaseComponentAdapter.getInstance$default(BaseComponentAdapter.kt:60)
    at com.intellij.serviceContainer.ComponentManagerImpl.createComponents(ComponentManagerImpl.kt:304)
    at com.intellij.openapi.project.impl.ProjectExImpl.init(ProjectExImpl.kt:177)
    at com.intellij.openapi.project.impl.ProjectManagerImpl.initProject(ProjectManagerImpl.java:173)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl.prepareProject(ProjectManagerExImpl.kt:242)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl.access$prepareProject(ProjectManagerExImpl.kt:52)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl$openProject$$inlined$runInAutoSaveDisabledMode$lambda$1.invoke(ProjectManagerExImpl.kt:104)
    at com.intellij.openapi.project.impl.ProjectManagerExImpl$openProject$$inlined$runInAutoSaveDisabledMode$lambda$1.invoke(ProjectManagerExImpl.kt:52)
    at com.intellij.openapi.project.impl.ProjectUiFrameAllocator$run$progressTask$1.run(ProjectFrameAllocator.kt:86)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$new$0(ProgressRunner.java:79)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$3(ProgressRunner.java:235)
    at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:178)
    at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:658)
    at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:610)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:65)
    at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:165)
    at com.intellij.openapi.progress.impl.ProgressRunner.lambda$submit$4(ProgressRunner.java:235)
    at java.base/java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1700)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:668)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:665)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:665)
    at java.base/java.lang.Thread.run(Thread.java:834)

评论操作 固定链接

The stacktrace suggests that the remove function wasn't invoked from the write thread.

Try to wrap this method call into writeAction block according to the docs:
https://plugins.jetbrains.com/docs/intellij/general-threading-rules.html

0

请先登录再写评论。