Classloaders in 2020.3 EAP

Answered

Hello,

We are trying to migrate our tests to be compatible with Idea 2020.3 in anticipation of its release. We are having classloading issues, specifically when fetching services. Previously we could do something like this in our tests

final OurPluginClass someService = ServiceManager.getService(OurPluginClass.class);

now testing (`gradle :test`) against `LATEST-EAP-SNAPSHOT` a line like this produces `ClassCastException`s, like

 java.lang.ClassCastException: class ....OurPluginClass cannot be cast to class ....OurPluginClass (....OurPluginClass is in unnamed module of loader com.intellij.ide.plugins.cl.PluginClassLoader @da53469; ....OurPluginClass is in unnamed module of loader 'app')
at ....OurTestClass(OurTestClass.java:74)

Investigation in the debugger reveals that inside the `ServiceManager` the `OurPluginClass` instance returned is created by the `PluginClassLoader`, however the code in `OurTestClass` is all loaded from `AppClassLoader`.

Is there any simple setting which we can use to make the test code load classes from the `PluginClassLoader`, or make the `ServiceManager` return instances loaded from the `AppClassLoader`?

Many Thanks
Scott Smith

6 comments
Comment actions Permalink

Thanks Yann, I haven't tested this with 0.6.1 - looks like it has been released while I've been working on this problem. I'll test and get back to you.

0
Comment actions Permalink

Actually we're at 0.6.3 now, but it seems there might still be problems

0
Comment actions Permalink

Just ran into this same issue, upgrading gradle plugin to 0.6.3 fixed it for me (thanks to this post).

0
Comment actions Permalink

If 0.6.3 doesn't fix it, please also try current snapshot with _latest_ 2020.3 EAP https://github.com/JetBrains/gradle-intellij-plugin/#snapshot-version

0
Comment actions Permalink

Thanks Yann Cebron and sorry for the slow reply. We just updated to version 0.6.5 and this problem no longer occurs. Appreciate the help!

0

Please sign in to leave a comment.