Registering Application-level plugin components

I'm at a loss. IDEA is throwing a ClassCastException if I try to register an application-level component in my plugin. I'm sure this was working fine a day or two ago, and I have no idea what I might be doing differently now... I've reduced it to a trivial test case. Can anyone tell me what I'm doing wrong?

L.

plugin.xml:
... ...TestAppComponent ]]>

component class:
public class TestAppComponent implements ApplicationComponent {
public TestAppComponent() {
System.out.println("ctor");
}

@NonNls
public String getComponentName() {
System.out.println("get name");
return "testComponent";
}

public void initComponent() {
System.out.println("init");
}

public void disposeComponent() {
System.out.println("dispose");
}
}

console output on application launch:
/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/bin/java -Xbootclasspath/p:/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/lib/boot.jar -Didea.config.path=/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/sandbox/config -Didea.system.path=/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/sandbox/system -Didea.plugins.path=/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/sandbox/plugins -Didea.smooth.progress=false -Dapple.laf.useScreenMenuBar=true -Dfile.encoding=MacRoman -classpath /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Home/lib/tools.jar:/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/lib/idea.jar:/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/lib/extensions.jar:/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/lib/openapi.jar:/Users/laurie/Developer/Applications/IntelliJ IDEA 5.1.app/lib/log4j.jar com.intellij.idea.Main
ctor
java.lang.ClassCastException: org.codehaus.mevenide2.idea.TestAppComponent
at com.intellij.openapi.components.impl.ComponentManagerImpl.instantiateComponent(ComponentManagerImpl.java:122)
at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:172)
at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:114)
at com.intellij.openapi.components.impl.ComponentManagerImpl.initComponents(ComponentManagerImpl.java:272)
at com.intellij.openapi.application.impl.ApplicationImpl.initComponents(ApplicationImpl.java:149)
at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:39)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:23)
at com.intellij.idea.Main$3.run(Main.java:1)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:94)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:119)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
ERROR - ij.components.ComponentManager -
ERROR - ij.components.ComponentManager - JDK: 1.5.0_05
ERROR - ij.components.ComponentManager - VM: Java HotSpot(TM) Client VM
ERROR - ij.components.ComponentManager - Vendor: Apple Computer, Inc.
ERROR - ij.components.ComponentManager - OS: Mac OS X
ERROR - ij.components.ComponentManager -
java.lang.ClassCastException: org.codehaus.mevenide2.idea.TestAppComponent
at com.intellij.openapi.components.impl.ComponentManagerImpl.instantiateComponent(ComponentManagerImpl.java:122)
at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:172)
at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:114)
at com.intellij.openapi.components.impl.ComponentManagerImpl.initComponents(ComponentManagerImpl.java:272)
at com.intellij.openapi.application.impl.ApplicationImpl.initComponents(ApplicationImpl.java:149)
at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:39)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:23)
at com.intellij.idea.Main$3.run(Main.java:1)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:94)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:119)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
java.lang.ClassCastException: org.codehaus.mevenide2.idea.TestAppComponent
at com.intellij.openapi.components.impl.ComponentManagerImpl.instantiateComponent(ComponentManagerImpl.java:122)
at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:172)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponentFromContainer(ComponentManagerImpl.java:245)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:192)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:284)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponents(ComponentManagerImpl.java:184)
at com.intellij.openapi.components.impl.ComponentManagerImpl.initComponents(ComponentManagerImpl.java:34)
at com.intellij.openapi.application.impl.ApplicationImpl.initComponents(ApplicationImpl.java:149)
at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:39)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:23)
at com.intellij.idea.Main$3.run(Main.java:1)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:94)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:119)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.InvocationEvent[INVOCATION_DEFAULT,runnable=com.intellij.idea.Main$3@911946,notifier=null,catchExceptions=false,when=1143005976969] on apple.awt.CToolkit@12491c
ERROR - com.intellij.ide.IdeEventQueue - IntelliJ IDEA 5.1 Build #4155
ERROR - com.intellij.ide.IdeEventQueue - JDK: 1.5.0_05
ERROR - com.intellij.ide.IdeEventQueue - VM: Java HotSpot(TM) Client VM
ERROR - com.intellij.ide.IdeEventQueue - Vendor: Apple Computer, Inc.
ERROR - com.intellij.ide.IdeEventQueue - OS: Mac OS X
ERROR - com.intellij.ide.IdeEventQueue - Last Action:
ERROR - com.intellij.ide.IdeEventQueue - Error during dispatching of java.awt.event.InvocationEvent[INVOCATION_DEFAULT,runnable=com.intellij.idea.Main$3@911946,notifier=null,catchExceptions=false,when=1143005976969] on apple.awt.CToolkit@12491c
java.lang.ClassCastException: org.codehaus.mevenide2.idea.TestAppComponent
at com.intellij.openapi.components.impl.ComponentManagerImpl.instantiateComponent(ComponentManagerImpl.java:122)
at com.intellij.openapi.components.impl.ComponentManagerImpl.a(ComponentManagerImpl.java:172)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponentFromContainer(ComponentManagerImpl.java:245)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:192)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponent(ComponentManagerImpl.java:284)
at com.intellij.openapi.components.impl.ComponentManagerImpl.getComponents(ComponentManagerImpl.java:184)
at com.intellij.openapi.components.impl.ComponentManagerImpl.initComponents(ComponentManagerImpl.java:34)
at com.intellij.openapi.application.impl.ApplicationImpl.initComponents(ApplicationImpl.java:149)
at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:39)
at com.intellij.idea.IdeaApplication.run(IdeaApplication.java:23)
at com.intellij.idea.Main$3.run(Main.java:1)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at com.intellij.ide.IdeEventQueue.defaultDispatchEvent(IdeEventQueue.java:94)
at com.intellij.ide.IdeEventQueue.a(IdeEventQueue.java:119)
at com.intellij.ide.IdeEventQueue.dispatchEvent(IdeEventQueue.java:25)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:275)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:182)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

7 comments

Most probably you have idea.jar defined as a library for your plugin. Then the ApplicationComponent class you're implementing is not the one used by IDEA, but the one contained in the idea.jar of your plugin. And as your plugin is loaded by its own class loader, those two classes are in fact different ones.

To avoid this problem you should remove idea.jar from libraries and add it to the IDEA SDK instead.

0

Can you please post full source of TestAppComponent with import section?

0

No, it no mater. I'm usaly have idea.jar defined in JDK.

0

No, it no mater. I'm usaly have idea.jar defined in JDK.


You're wrong here, it matters a lot. Having idea.jar defined in the SDK is fine. But by adding it as a regular library you'll get exactly the problems Laurie is talking about.

0

Hmm... Maybe... :)


It's maybe something else, but with a probability of 99.5% it's either idea.jar or rather openapi.jar that somehow ended up in the sandbox - though since 5.1 IDEA should not copy any libraries from IDEA-HOME/lib to the sandbox any more. Thinking about this again, openapi.jar could also come from the redist-directory which it would not complain about.

It's also important to clean the sandbox after removing the jar from the libraries.

Sascha

0

Gah, I had openide-5.1.jar and extensions-5.1.jar in my plugin's lib/ directory. It looks like 'mvn idea:idea' had propogated those dependencies back into the project, even though they're flagged as 'provided' and so ought to be ignored. I'll have to mark that a Maven2 / IDEA plugin bug. The maddening thing is I 'knew' that wasn't the problem because I'd fixed it previously. Just goes to show, check all assumptions! :)

Thanks,

L.

0

Please sign in to leave a comment.