[slf4j-user] How can I prevent this Linkage Error?

Joachim Durchholz jo at durchholz.org
Sat Oct 10 12:45:28 CEST 2020


We have too little information to be sure about anything, but the 
typical cause here is that your servlet runs in an environment that 
already has SLF4J loaded, but your code directly or indirectly load 
SFL4J on its own.

If that is indeed the cause:

You need to find out which of your dependencies pulls in SLF4J 
(jcifs.smb is likely the culprit because loggers aren't typically 
created in module A and passed on to module B, though that could 
happen), and tell your build system that the dependency should be 
ignored in your build.
E.g. with Maven, you'd use dependency:tree to see the dependencies, use 
<exclusions> on the direct dependency to get rid of the unwanted 
dependence, and add slf4j as a direct dependency with a "provided" scope 
(this should make your IDE include the module during debugging if it 
knows Maven, and make Maven include the module in the classpath during 
compilation but not when building the .war file).

If it's another cause, you'll need to give us more information :-)

Regards,
Jo

Am 09.10.20 um 23:19 schrieb larry.stamper at daimler.com:
> I am using an API which uses slf4j (it happens to be jcifs-ng, but I 
> don’t think that matters.) When I am able to define my classpath myself, 
> I can call this API with no problem – slf4j finds no bindings and falls 
> back on NOP. But when I call the API running under a service whose 
> classpath I can’t control, I get this error:
> 
> java.lang.LinkageError: loader constraint violation: when resolving 
> method 
> "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" 
> the class loader (instance of 
> chs/api/mgr/local/ExtraJarPluginClassLoader) of the current class, 
> org/slf4j/LoggerFactory, and the class loader (instance of <bootloader>) 
> for the method's defining 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:418)
> 
>         at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:357)
> 
>         at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:383)
> 
>         at 
> jcifs.smb.NtlmPasswordAuthenticator.<clinit>(NtlmPasswordAuthenticator.java:58)
> 
> I don’t use sl4j directly. Is there some way I can bind to NOP before I 
> make any calls to the API?
> 
> Larry Stamper
> 
> MP9-OCS
> 
> DISYS (Digital Intelligence Systems)
> 
> Consulting Software Engineer
> 
> Cell: (503) 560-7004
> 
> larry.stamper at daimler.com <mailto:larry.stamper at daimler.com>
> 
> Default Disclaimer Daimler AG
> If you are not the addressee, please inform us immediately that you have 
> received this e-mail by mistake, and delete it. We thank you for your 
> support.
> 
> 
> _______________________________________________
> slf4j-user mailing list
> slf4j-user at qos.ch
> http://mailman.qos.ch/mailman/listinfo/slf4j-user
> 



More information about the slf4j-user mailing list