【前车之鉴】【全网唯一】IDEA自研插件安装时出现error信息:idToEntry must be empty (idToEntry=xxx) 完美解决方式

发布时间:2023年12月20日

问题复现

在这里插入图片描述

最近在开发公司通用插件时,发现一个奇怪现象,只要打开装好插件的项目就提示如下错误:而且还不影响使用,最初没搭理,后来使用者多次反馈这一弊病,索性潜心思考下解决方式【此时Goole、百度目前还没有一个贴近的解决】

java.lang.Throwable: idToEntry must be empty (idToEntry={
BaiZe: com.intellij.toolWindow.ToolWindowEntry@3ce30078)
	at com.intellij.openapi.diagnostic.Logger.error(Logger.java:202)
	at com.intellij.openapi.wm.impl.ToolWindowManagerImpl.setLayoutOnInit(ToolWindowManagerImpl.kt:1215)
	at com.intellij.toolWindow.ToolWindowSetInitializer$createAndLayoutToolWindows$entries$1.invokeSuspend(ToolWindowSetInitializer.kt:120)
	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
	at com.intellij.openapi.application.TransactionGuardImpl$1.run(TransactionGuardImpl.java:194)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
	at com.intellij.openapi.application.impl.ApplicationImpl$3.run(ApplicationImpl.java:456)
	at com.intellij.openapi.application.impl.FlushQueue.doRun(FlushQueue.java:79)
	at com.intellij.openapi.application.impl.FlushQueue.runNextEvent(FlushQueue.java:122)
	at com.intellij.openapi.application.impl.FlushQueue.flushNow(FlushQueue.java:41)
	at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
	at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:788)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:739)
	at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:731)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
	at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:758)
	at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.kt:666)
	at com.intellij.ide.IdeEventQueue._dispatchEvent$lambda$7(IdeEventQueue.kt:570)
	at com.intellij.openapi.application.impl.ApplicationImpl.withoutImplicitRead(ApplicationImpl.java:1446)
	at com.intellij.ide.IdeEventQueue._dispatchEvent(IdeEventQueue.kt:570)
	at com.intellij.ide.IdeEventQueue.access$_dispatchEvent(IdeEventQueue.kt:68)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:349)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1$1.compute(IdeEventQueue.kt:348)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computePrioritized(CoreProgressManager.java:787)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:348)
	at com.intellij.ide.IdeEventQueue$dispatchEvent$processEventRunnable$1$1.invoke(IdeEventQueue.kt:343)
	at com.intellij.ide.IdeEventQueueKt.performActivity$lambda$1(IdeEventQueue.kt:994)
	at com.intellij.openapi.application.TransactionGuardImpl.performActivity(TransactionGuardImpl.java:105)
	at com.intellij.ide.IdeEventQueueKt.performActivity(IdeEventQueue.kt:994)
	at com.intellij.ide.IdeEventQueue.dispatchEvent$lambda$4(IdeEventQueue.kt:343)
	at com.intellij.openapi.application.impl.ApplicationImpl.runIntendedWriteActionOnCurrentThread(ApplicationImpl.java:831)
	at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.kt:385)
	at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:207)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:92)

}

Easy Answer

  <toolWindow id="BaiZe"-->
                    secondary="true"
                   icon="/META-INF/unit.svg
                   anchor="right" factoryClass="com.sg.user.ui.ShowCaseToolWindowFactory">
     </toolWindow>

经过笔者多次尝试,默认方式将插件配置在xml 方式是不会出现该问题,而出现上面异常90% 概率是因为你采用如下动态方式去创建ToolWindow,且没有做好生命周期嵌入的准备,导致IDEA加载插件时出现资源拿不到的情况;但是这个动态创建是有诉求的,所以通过大量实践验证得出最佳解决方案,在项目初始化 完毕之后嵌入组件不再产生该问题,核心代码如下

 toolWindowManager.registerToolWindow("BaiZe", false, ToolWindowAnchor.RIGHT);

解决方式即保证的你插件不要过早的加入到IDEA创建周期中

  StartupManager.getInstance(project).runWhenProjectIsInitialized(()-> {
     toolWindowManager.registerToolWindow("BaiZe", false, ToolWindowAnchor.RIGHT);
  }
文章来源:https://blog.csdn.net/lkg5211314/article/details/134803348
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。