我在 Eclipse 里打开我的 Java 项目,双击一个 .java
文件,遇到错误消息:Failed to create the part's control
错误的调用栈如下图所示:
java.lang.NoClassDefFoundError: org/codehaus/groovy/eclipse/editor/GroovyAwareFoldingStructureProvider at org.codehaus.groovy.eclipse.GroovyPlugin$1.getCurrentFoldingProvider(GroovyPlugin.java:182) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createSourceViewer(JavaEditor.java:1891) at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(AbstractTextEditor.java:3369) at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(StatusTextEditor.java:64) at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(AbstractDecoratedTextEditor.java:454) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createPartControl(JavaEditor.java:3093) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.createPartControl(CompilationUnitEditor.java:1521) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:158) at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:365) 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 org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58) at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:995) at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:960) at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:140) at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:403) at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:330) at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:202) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:91) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:60) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42) at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:132) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:994) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:658) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:762) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:727) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:711) at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.lambda$0(PartServiceImpl.java:105)
java.lang.NoClassDefFoundError: org/codehaus/groovy/eclipse/editor/GroovyAwareFoldingStructureProvider at org.codehaus.groovy.eclipse.GroovyPlugin$1.getCurrentFoldingProvider(GroovyPlugin.java:182) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createSourceViewer(JavaEditor.java:1891) at org.eclipse.ui.texteditor.AbstractTextEditor.createPartControl(AbstractTextEditor.java:3369) at org.eclipse.ui.texteditor.StatusTextEditor.createPartControl(StatusTextEditor.java:64) at org.eclipse.ui.texteditor.AbstractDecoratedTextEditor.createPartControl(AbstractDecoratedTextEditor.java:454) at org.eclipse.jdt.internal.ui.javaeditor.JavaEditor.createPartControl(JavaEditor.java:3093) at org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor.createPartControl(CompilationUnitEditor.java:1521) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.createPartControl(CompatibilityPart.java:158) at org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor.createPartControl(CompatibilityEditor.java:96) at org.eclipse.ui.internal.e4.compatibility.CompatibilityPart.create(CompatibilityPart.java:365) 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 org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58) at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:995) at org.eclipse.e4.core.internal.di.InjectorImpl.processAnnotated(InjectorImpl.java:960) at org.eclipse.e4.core.internal.di.InjectorImpl.internalInject(InjectorImpl.java:140) at org.eclipse.e4.core.internal.di.InjectorImpl.internalMake(InjectorImpl.java:403) at org.eclipse.e4.core.internal.di.InjectorImpl.make(InjectorImpl.java:330) at org.eclipse.e4.core.contexts.ContextInjectionFactory.make(ContextInjectionFactory.java:202) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.createFromBundle(ReflectionContributionFactory.java:91) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.doCreate(ReflectionContributionFactory.java:60) at org.eclipse.e4.ui.internal.workbench.ReflectionContributionFactory.create(ReflectionContributionFactory.java:42) at org.eclipse.e4.ui.workbench.renderers.swt.ContributedPartRenderer.createWidget(ContributedPartRenderer.java:132) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createWidget(PartRenderingEngine.java:994) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:658) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.safeCreateGui(PartRenderingEngine.java:762) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$2.run(PartRenderingEngine.java:727) at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:45) at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.createGui(PartRenderingEngine.java:711) at org.eclipse.e4.ui.internal.workbench.PartServiceImpl.lambda$0(PartServiceImpl.java:105)
参看 Eclipse 的 bug 列表:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=577806
It seems that you have installed the Groovy Development tools, or at least some of the plugins of that project.
Their project overrides the getCurrentFoldingProvider method using reflection, that causes this error.
This issue is reported at the Groovy Eclipse plugin:
https://github.com/groovy/groovy-eclipse/issues/1319
如果 Eclipse 安装了 Eclipse Groovy Development Tools 和 Groovy compiler 3.0, 就会出现这个错误,因为 Groovy 插件通过 Java reflection 机制,复写了 getCurrentFoldingProvider,导致的 bug:
我把上图所示的两个黄色插件从 Eclipse 里卸载,就又可以重新打开 Java 文件了:
更详细的 Groovy plugin 信息:
Pivotal Software, Inc. Apache Groovy 2.5.14.v202103311613-e2103-RELEASE org.codehaus.groovy
Pivotal Software, Inc. Groovy Ant support 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.ant
Pivotal Software, Inc. Groovy AST Views 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.astviews
Pivotal Software, Inc. Groovy Code Assist 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.codeassist
Pivotal Software, Inc. Groovy Code Browsing 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.codebrowsing
Pivotal Software, Inc. Groovy Compiler Resolver 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.compilerResolver
Pivotal Software, Inc. Groovy Core 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.core
Pivotal Software, Inc. Groovy DSL support 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.dsl
Pivotal Software, Inc. Groovy-Eclipse 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse
Pivotal Software, Inc. Groovy-Eclipse integration 4.1.0.v202103311613-e2103-RELEASE org.eclipse.jdt.groovy.core
Pivotal Software, Inc. Groovy Quick Fix 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.quickfix
Pivotal Software, Inc. Groovy Refactoring 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.refactoring
Pivotal Software, Inc. Groovy UI 4.1.0.v202103311613-e2103-RELEASE org.codehaus.groovy.eclipse.ui
如果想保留 Groovy 插件,解决方案参考如下:
In our project (Apache OFBiz) we still use Groovy 2.5.11, so I tried to install GDT 3.5.0. Eclipse refused and suggested something else. It worked. I have now a mix of installed versions (3 4.50 and 1 4.40) but at least it works 😃