Using clashing versions of external libraries when unit-testing

IntelliJ uses protobuf v2.5.

My plugin uses protobuf v3.x.

This is not a problem when regularly running the plugin, just as promised. However, when unit-testing using IntelliJ's provided *TestCase classes, it seems that the special class loader implementation is not used. VerifyError-s and NoSuchMethodError-s prevent the unit test from running properly.

Can someone please advise on how unit tests may be run?

0
4 comments

Hi,

ensure that your library comes to the classpath before the IDEA SDK then your library would replace one, provided by IDEA

 

Anna

 

0
Avatar
Permanently deleted user

Hello Anna,

To clarify, the errors generated are *because* the library replaces the ones IDEA uses.

For example, the VerifyError presents itself because `org.jetbrains.jps.api.CmdlineRemoteProto$Message`, which is part of the IDEA SDK, overrides isInitialized(), an inherited protobuf library method that is okay to override within the old version of the protobuf library that IDEA uses, but may not be overridden in the version that I am using, because it is marked final within the new version of the library.

How do I perform unit-testing?

0
Avatar
Permanently deleted user
java.lang.VerifyError: class org.jetbrains.jps.api.CmdlineRemoteProto$Message overrides final method isInitialized.()Z

    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(CoreReflectionFactory.java:114)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:125)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.visitor.Reifier.reifyTypeArguments(Reifier.java:68)
    at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:138)
    at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
    at sun.reflect.generics.repository.ClassRepository.getSuperclass(ClassRepository.java:90)
    at java.lang.Class.getGenericSuperclass(Class.java:777)
    at io.netty.util.internal.TypeParameterMatcher.find0(TypeParameterMatcher.java:106)
    at io.netty.util.internal.TypeParameterMatcher.find(TypeParameterMatcher.java:78)
    at io.netty.channel.SimpleChannelInboundHandler.<init>(SimpleChannelInboundHandler.java:67)
    at org.jetbrains.io.SimpleChannelInboundHandlerAdapter.<init>(SimpleChannelInboundHandlerAdapter.java:11)
    at com.intellij.compiler.server.BuildMessageDispatcher.<init>(BuildMessageDispatcher.java:41)
    at com.intellij.compiler.server.BuildManager.<init>(BuildManager.java:224)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.picocontainer.defaults.InstantiatingComponentAdapter.newInstance(InstantiatingComponentAdapter.java:193)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter$1.run(ConstructorInjectionComponentAdapter.java:220)
    at org.picocontainer.defaults.ThreadLocalCyclicDependencyGuard.observe(ThreadLocalCyclicDependencyGuard.java:53)
    at org.picocontainer.defaults.ConstructorInjectionComponentAdapter.getComponentInstance(ConstructorInjectionComponentAdapter.java:248)
    at com.intellij.util.pico.CachingConstructorInjectionComponentAdapter.getComponentInstance(CachingConstructorInjectionComponentAdapter.java:58)
    at com.intellij.openapi.components.impl.ComponentManagerImpl$ComponentConfigComponentAdapter.getComponentInstance(ComponentManagerImpl.java:495)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.createComponents(ComponentManagerImpl.java:119)
    at com.intellij.openapi.application.impl.ApplicationImpl.lambda$createComponents$8(ApplicationImpl.java:429)
    at com.intellij.openapi.application.impl.ApplicationImpl.createComponents(ApplicationImpl.java:433)
    at com.intellij.openapi.components.impl.ComponentManagerImpl.init(ComponentManagerImpl.java:103)
    at com.intellij.openapi.application.impl.ApplicationImpl.load(ApplicationImpl.java:392)
    at com.intellij.idea.IdeaTestApplication.getInstance(IdeaTestApplication.java:54)
    at com.intellij.idea.IdeaTestApplication.getInstance(IdeaTestApplication.java:46)
    at com.intellij.testFramework.LightPlatformTestCase.initApplication(LightPlatformTestCase.java:166)
    at com.intellij.testFramework.fixtures.impl.LightIdeaTestFixtureImpl.setUp(LightIdeaTestFixtureImpl.java:52)
    at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl$17.run(CodeInsightTestFixtureImpl.java:1311)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:29)
    at com.intellij.testFramework.EdtTestUtil$Companion$runInEdtAndWait$1.invoke(EdtTestUtil.kt:27)
    at com.intellij.testFramework.EdtTestUtilKt.runInEdtAndWait(EdtTestUtil.kt:47)
    at com.intellij.testFramework.EdtTestUtil$Companion.runInEdtAndWait(EdtTestUtil.kt:29)
    at com.intellij.testFramework.EdtTestUtil.runInEdtAndWait(EdtTestUtil.kt)
    at com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl.setUp(CodeInsightTestFixtureImpl.java:1308)
    at com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase.setUp(LightPlatformCodeInsightFixtureTestCase.java:61)
    ...


P.S.: This particular error occurs even when "-noverify" is specified in the IDE's Java compiler settings (presumably because of the "unit test runner" mechanics that I'm unfamiliar with).

0
Avatar
Permanently deleted user

I suppose the month of silence means unit-testing isn't directly supported?

0

Please sign in to leave a comment.