Ed .
Ed .

Reputation: 6403

LinkageError thrown when attempting to pass instance of class between 2 eclipse plugins

I have found many people with simliar issues but no soultions...basically I have two eclipse plug-ins that both in ther class path rely on the same jar.

The UI plug-in replies on the Driver plug-in (implementing a custom ODA driver and UI for it). Both rely on a jar containing some other classes of mine and is called plugin-dto.jar

When the UI plug-in calls a method on one of the classes in the Driver plug-in that returns an object whose class is found in the plugin-dto jar I get the error:

java.lang.LinkageError: Class com/test/reporting/NrDsDriverProvider violates loader constraints
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.defineClass(DefaultClassLoader.java:183)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.defineClass(ClasspathManager.java:576)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findClassImpl(ClasspathManager.java:546)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClassImpl(ClasspathManager.java:477)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass_LockClassLoader(ClasspathManager.java:465)
    at org.eclipse.osgi.baseadaptor.loader.ClasspathManager.findLocalClass(ClasspathManager.java:445)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.findLocalClass(DefaultClassLoader.java:211)
    at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:381)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:457)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:410)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:398)
    at org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader.loadClass(DefaultClassLoader.java:105)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

Any ideas how I get around this issue?

Thanks in advance.

Upvotes: 1

Views: 2275

Answers (1)

Josh Knauer
Josh Knauer

Reputation: 1754

The problem is that instances of classes loaded in two different plugins are different, even if they came from the same jar. The Eclipse Plugin class loader is doing what it is supposed to. Assuming that Plugin A and Plugin B are both trying to access the same instance of class Z, a couple of solutions to this problem are:

Upvotes: 3

Related Questions