Loading a service from a plugin included as a library results in a ClassCastException

Working on a plugin (pluginC) in idea community sources, with another plugin (pluginG) included as a "global library". PluginC included in it's dependencies PluginG as a library dependency.

When I try to use a service from PluginG in PluginC, it appears the service interface is loaded using a URLClassLoader and the interface implementation is loaded using the PluginClassLoader.  I'm not super familiar with how the classloading works here, but does anyone know what's going on here? I get a ClassCastException and I'm not how to get around this.

 

1 comment
Comment actions Permalink

Hi Appu,

Each plugin is loaded by separate PluginClassLoader and its dependencies from ./lib/ directory are loaded by URLClassLoader. Likely you've installed DependencyPlugin in IDEA and in the same time you've added it in ./lib directory of DependentPlugin. In this case when you ask IDEA to provide a service implemented in DependencyPlugin, IDEA loads it from its plugin-system and when you assign it to variable, class from DependentPlugin dependency is used. CCE is unavoidable.

You shouldn't put DependencyPlugin in ./lib directory of DependentPlugin. DependencyPlugin should be a 'provided' library instead. Also you should add depends-tag in DependentPlugin in order to tell IDEA that you want to use classes from DependencyPlugin. See also http://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html.

0

Please sign in to leave a comment.