Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

"java.lang.LinkageError: loader constraint violation" for logger

x January 21, 2014

I'm seeing the following in my stash log (standalone, local) when using `atlas-install-plugin` for a newly created plugin:

2014-01-21 17:12:48,204 WARN  [UpmAsynchronousTaskManager:thread-2] admin 1032x8x0 1blz4pw 127.0.0.1 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.p.u.r.AlternativeDirectoryResourceLoader Resource directory , which resolves to /private/tmp/amps-standalone/target/container/tomcat7x/cargo-stash-home does not exist
2014-01-21 17:12:48,264 ERROR [ThreadPoolAsyncTaskExecutor::Thread 16] admin 1032x8x0 1blz4pw 127.0.0.1 "POST /rest/plugins/1.0/ HTTP/1.1" c.a.plugin.osgi.factory.OsgiPlugin Unable to start the plugin container for plugin com.squareup.stash.group-mention-plugin
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PullRequestListener' defined in URL [bundle://96.0:0/META-INF/spring/atlassian-plugins-components.xml]: Instantiation of bean failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/apache/catalina/loader/WebappClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254) ~[spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_65]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) ~[spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
	at java.lang.Thread.run(Thread.java:695) ~[na:1.6.0_65]
	... 18 frames trimmed
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/apache/catalina/loader/WebappClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:299) ~[slf4j-api-1.7.5.jar:1.7.5]
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269) ~[slf4j-api-1.7.5.jar:1.7.5]
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281) ~[slf4j-api-1.7.5.jar:1.7.5]
	at com.squareup.stash.PullRequestListener.<clinit>(PullRequestListener.java:19) ~[na:na]
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) ~[spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
	... 4 common frames omitted
2014-01-21 17:12:48,268 ERROR [ThreadPoolAsyncTaskExecutor::Thread 16] admin 1032x8x0 1blz4pw 127.0.0.1 "POST /rest/plugins/1.0/ HTTP/1.1" o.s.o.e.i.a.ContextLoaderListener Application context refresh failed (NonValidatingOsgiBundleXmlApplicationContext(bundle=com.squareup.stash.group-mention-plugin, config=osgibundle:/META-INF/spring/*.xml))
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'PullRequestListener' defined in URL [bundle://96.0:0/META-INF/spring/atlassian-plugins-components.xml]: Instantiation of bean failed; nested exception is java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/apache/catalina/loader/WebappClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:254) ~[spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
	at java.security.AccessController.doPrivileged(Native Method) ~[na:1.6.0_65]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:728) ~[spring-context-3.2.5.RELEASE.jar:3.2.5.RELEASE]
	at java.lang.Thread.run(Thread.java:695) [na:1.6.0_65]
	... 18 frames trimmed
Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of org/apache/felix/framework/ModuleImpl$ModuleClassLoaderJava5) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/apache/catalina/loader/WebappClassLoader) for resolved class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
	at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:299) ~[slf4j-api-1.7.5.jar:1.7.5]
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269) ~[slf4j-api-1.7.5.jar:1.7.5]
	at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:281) ~[slf4j-api-1.7.5.jar:1.7.5]
	at com.squareup.stash.PullRequestListener.<clinit>(PullRequestListener.java:19) ~[na:na]
	at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:100) ~[spring-2.5.6.SEC02.jar:3.2.5.RELEASE]
	... 4 common frames omitted

Strangely, I have an old plugin lying around that uses the same logging classes/technique, but which installs fine. (It was created on a much older version of stash/atlas.)

I don't really know how to go about fixing this. Suggestions welcome!

My code:

package com.squareup.stash;

import com.atlassian.event.api.EventListener;
import com.atlassian.stash.event.pull.PullRequestUpdatedEvent;
import org.slf4j.LoggerFactory;
import org.slf4j.Logger;

public class PullRequestListener {
    private static final Logger log = LoggerFactory.getLogger(PullRequestListener.class);

    @EventListener
    public void myListener(PullRequestUpdatedEvent e) {
        log.debug("HOLA");
    }
}

Xavier

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 21, 2014

Hi Xavier,

What does your pom.xml look like? Make sure you use <scope>provided</scope> for importing SLF4J, otherwise you're going to run into weird classpath problems.

Cheers,

Charles

x January 21, 2014
I'm not explicitly importing SLF4J ... should I be?
https://gist.github.com/xaviershay/eab492d61998e8462cb5


x January 21, 2014

Adding the following to my pom appears to have fixed the issue:

&lt;dependency&gt;
            &lt;groupId&gt;.org.slf4j&lt;/groupId&gt;
            &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
            &lt;version&gt;1.7.5&lt;/version&gt;
            &lt;scope&gt;provided&lt;/scope&gt;
        &lt;/dependency&gt;

... though I don't really understand why.

Damian Skrodzki October 14, 2014

Adding dependency by hand worked for me also.

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 16, 2014

To add to the confusion Had the same problem. Adding the dependency on slf4j didn't resolve the problem, but changing the source and target version of the compiler did {code} <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> </configuration> </plugin> {code}

francis
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
October 16, 2014

(I changed it back from 1.7 to 1.6)

0 votes
x January 21, 2014

.... I don't know how to fix the formatting in this post.

TAGS
AUG Leaders

Atlassian Community Events