java.lang.LinkageError: attempted duplicate class definition

Franz-kun picture Franz-kun · Jul 25, 2016 · Viewed 15k times · Source

Why does the error happen and how do I fix it?

[02:13:02] [pool-4-thread-2/WARN]: Exception in thread "pool-4-thread-2" 
[02:13:02] [pool-4-thread-2/WARN]: java.lang.LinkageError: loader (instance of  org/bukkit/plugin/java/PluginClassLoader): attempted  duplicate class definition for name: "com/mongodb/client/model/Filters"
[02:13:02] [pool-4-thread-2/WARN]:  at java.lang.ClassLoader.defineClass1(Native Method)
[02:13:02] [pool-4-thread-2/WARN]:  at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
[02:13:02] [pool-4-thread-2/WARN]:  at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
[02:13:02] [pool-4-thread-2/WARN]:  at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
[02:13:02] [pool-4-thread-2/WARN]:  at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
[02:13:02] [pool-4-thread-2/WARN]:  at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
[02:13:02] [pool-4-thread-2/WARN]:  at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
[02:13:02] [pool-4-thread-2/WARN]:  at java.security.AccessController.doPrivileged(Native Method)
[02:13:02] [pool-4-thread-2/WARN]:  at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
[02:13:02] [pool-4-thread-2/WARN]:  at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101)
[02:13:02] [pool-4-thread-2/WARN]:  at org.bukkit.plugin.java.JavaPluginLoader.getClassByName(JavaPluginLoader.java:195)
[02:13:02] [pool-4-thread-2/WARN]:  at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:97)
[02:13:02] [pool-4-thread-2/WARN]:  at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86)
[02:13:02] [pool-4-thread-2/WARN]:  at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
[02:13:02] [pool-4-thread-2/WARN]:  at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
[02:13:02] [pool-4-thread-2/WARN]:  at me.franzsan.data.mongo.MongoCharacter.existsCharacter(MongoCharacter.java:109)
[02:13:02] [pool-4-thread-2/WARN]:  at me.franzsan.data.mongo.MongoCharacter.lambda$loadCharacter$0(MongoCharacter.java:44)
[02:13:02] [pool-4-thread-2/WARN]:  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[02:13:02] [pool-4-thread-2/WARN]:  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[02:13:02] [pool-4-thread-2/WARN]:  at java.lang.Thread.run(Thread.java:745)

This is the line that causes the error

FindIterable cursor = connection.getCharacters().find(Filters.eq("uuid", uuid));

And then there is also this. It's from another module and both should be executed asynchronously at the same time (or shortly after one another, because I think right now I have only one thread). This one works without error.

FindIterable cursor = connection.getPlayers().find(Filters.eq("uuid", id));

Filters.eq is a static method.

Both are using the same

ExecutorService pool = Executors.newCachedThreadPool();

I feel like i'm lacking crucial knowledge, but I have no idea where to look fo rit.

Answer

JanBebendorf picture JanBebendorf · Aug 2, 2016

duplicate class definition for name says all. It seems that you copied the mongodb driver in you plugin under the classpath com.mongodb.client like in your other plugin and you are running both plugins on the same server. This causes a conflict, because you attempt to load 2 classes with the exact same classpath.