Expand my Community achievements bar.

SOLVED

How to debug LinkageError?

Avatar

Community Advisor

Hello Dear AEM community,

Trying to debug LinkageError I'm getting in one of the bundles.

Essentially, whenever I'm trying to send an email I'm getting following exception:

17.02.2016 17:03:31.448 *ERROR* [qtp86404370-62743] com.company.bundles.test [EmailService.TEST(9511)] The init method has thrown an exception (java.lang.LinkageError: javax/mail/Session)
java.lang.LinkageError: javax/mail/Session
        at com.sun.mail.util.PropUtil.getBooleanSessionProperty(PropUtil.java:86)
        at javax.mail.internet.MimeMessage.initStrict(MimeMessage.java:315)
        at javax.mail.internet.MimeMessage.<init>(MimeMessage.java:193)
        at org.apache.commons.mail.Email.createMimeMessage(Email.java:1216)
        at org.apache.commons.mail.Email.buildMimeMessage(Email.java:1097)
        at org.apache.commons.mail.MultiPartEmail.buildMimeMessage(MultiPartEmail.java:254)
        at org.apache.commons.mail.HtmlEmail.buildMimeMessage(HtmlEmail.java:513)
        at org.apache.commons.mail.Email.send(Email.java:1266)
        at com.day.cq.mailer.impl.DefaultMailService.send(DefaultMailService.java:289)
        at com.day.cq.mailer.impl.DefaultMailService.sendEmail(DefaultMailService.java:240)

Email email = new HtmlEmail(); try {     defaultMailService.sendEmail(email); LOG.info("Email send!"); } catch (EmailException e) { LOG.error("Unable to send an email due to," ,e); }

 

Following maven depenedencies are used:

<dependencies> <!-- Uber Jar --> <dependency> <groupId>com.adobe.aem</groupId> <artifactId>uber-jar</artifactId> <scope>provided</scope> <classifier>apis</classifier> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-email</artifactId> <version>1.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> </dependency> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <scope>provided</scope> </dependency> <!-- Logging --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.apache.felix.scr.annotations</artifactId> </dependency> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.osgi.foundation</artifactId> </dependency> <!-- OSGi Framework Dependencies --> <dependency> <groupId>org.osgi</groupId> <artifactId>org.osgi.core</artifactId> </dependency> <dependency> <groupId>org.apache.felix</groupId> <artifactId>org.osgi.compendium</artifactId> </dependency> </dependencies>

What can be done to figure out exactly why the LinkageError is occuring?

 

Thanks,

Peter

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hi,

This issue occurs when you compiled your classes with some dependency, but at run time, a version of that dependency is changed. This is a simple compatibility issue.

Do you have the same version of javax.mail in dependency and on OSGI Console?.

Jitendra

View solution in original post

8 Replies

Avatar

Level 10

Looks like something is missing in the OSGi service container. Is the OSGi bunlde a custom one that used to work, 

For testing purposes  --try writing a custom Email service using the Java Mail API. 

https://helpx.adobe.com/experience-manager/using/creating-custom-cq-email-services.html

There should be  no issues doing this.  

Avatar

Community Advisor

Yes, this is true the tutorial you have linked on OOTB works perfectly,

However, on the instance I am working on it does not work.

Looking through the -verbose:class output from JVM can see that javax.mail.Session is actually loaded twice

First from the: [Loaded javax.mail.Session from jar:bundle://519.0:0/!/]

Then from the: [Loaded javax.mail.Session from http://felix.extensions:9/]

Looking further at 519 I can see that it is my javax.mail bundle:

        
519
 
1.5.0.b01 Active

However, http://felix.extensions:9 is a bit unexpected.

Where are felix.extensions defined?

How to find out which felix extension is pulling in this class?

 

Thanks,

Peter

Avatar

Level 10

Looks like something that loads OSGi classes is out of sync - not working properly.  I will ask support to look at this to see if this is a known issue. 

Avatar

Level 10

Are you using any application server like jboss or tomcat ....  If so the issue happened becuse container also exposes same api.    Delete OOB provided bundle JavaMail API (compat)javax.mail 1.5.0.b01. Build the own matching your container provided mail jar by following http://helpx.adobe.com/experience-manager/kb/CreatingExtension.html

Avatar

Community Advisor

@Sham it's a stand alone instance that has gone through the standard upgrade from 5.6.1 to 6.1, we do not use jboss or tomcat with AEM.

@Scott thank you, looking forward to hear back from you on this

Avatar

Correct answer by
Level 9

Hi,

This issue occurs when you compiled your classes with some dependency, but at run time, a version of that dependency is changed. This is a simple compatibility issue.

Do you have the same version of javax.mail in dependency and on OSGI Console?.

Jitendra

Avatar

Community Advisor

Hi Jitendra,

In the code posted I am not even refering to javax.mail, refering to com.day.cq.mailer.impl.DefaultMailService which is being resolved from the uber-jar.

DefaultMailService in turn tries to resolve the dependency.

Now, looking at the cq-mailer via /system/console/bundles, it consumes javax.mail from the javax.mail.internet,version=1.5.0 from javax.mail (209).

CQ mailer has following Import statement:

Import-Package: com.adobe.granite.crypto; version="[1.1, 2)", com.adobe.granite.security.user; version="[1.2, 2)", com.day.cq.commons.jcr, com.day.cq.mailer; version="[5.9, 5.10)", com.day.cq.mailer.email; version="[5.7, 5.8)", com.day.cq.retriever, com.day.cq.security, com.day.cq.security.profile, javax.activation, javax.jcr; version="[2.0, 3)", javax.mail.internet, org.apache.commons.collections, org.apache.commons.io; version="[1.4, 2)", org.apache.commons.lang; version="[2.4, 3)", org.apache.commons.lang.text; version="[2.4, 3)", org.apache.commons.mail; version="[1.2, 2)", org.apache.http, org.apache.http.auth; version="[4.3, 5)", org.apache.http.client; version="[4.3, 5)", org.apache.http.client.methods; version="[4.3, 5)", org.apache.http.impl.client; version="[4.3, 5)", org.apache.jackrabbit.api.security.user; version="[2.3, 3)", org.apache.jackrabbit.util; version="[2.4, 3)", org.apache.sling.api.resource; version="[2.1, 3)", org.apache.sling.commons.osgi; version="[2.0, 3)", org.apache.sling.jcr.api; version="[2.0, 3)", org.osgi.framework; version="[1.4, 2)", org.osgi.service.cm; version="[1.2, 2)", org.osgi.service.component; version="[1.0, 2)", org.slf4j; version="[1.5, 2)", org.xml.sax

Javax.mail package has following exports:

Export-Package: javax.mail.internet; uses:="com.sun.mail.util, javax.mail, javax.activation, javax.mail.util"; version="1.5", javax.mail.util; uses:="javax.activation, javax.mail.internet"; version="1.5", javax.mail.search; uses:="javax.mail.internet, javax.mail"; version="1.5", javax.mail; uses:="javax.mail.event, javax.mail.search, javax.activation, com.sun.mail.util"; version="1.5", javax.mail.event; uses:="javax.mail"; version="1.5", com.sun.mail.imap; uses:="com.sun.mail.iap, javax.mail, com.sun.mail.imap.protocol, javax.activation, com.sun.mail.util, javax.mail.internet, javax.mail.search, javax.mail.event"; version="1.5.0", com.sun.mail.imap.protocol; uses:="com.sun.mail.iap, com.sun.mail.util, javax.mail.internet, javax.mail, com.sun.mail.imap, javax.mail.search, javax.security.sasl, javax.security.auth.callback"; version="1.5.0", com.sun.mail.iap; uses:="com.sun.mail.util, javax.net.ssl"; version="1.5.0", com.sun.mail.pop3; uses:="javax.mail, com.sun.mail.util, javax.mail.internet, javax.net.ssl, javax.mail.util"; version="1.5.0", com.sun.mail.smtp; uses:="com.sun.mail.util, javax.mail.internet, javax.mail, javax.security.sasl, javax.security.auth.callback, javax.net.ssl"; version="1.5.0", com.sun.mail.util; uses:="javax.mail, javax.net.ssl, javax.mail.internet, javax.mail.util, javax.net, javax.security.auth.x500"; version="1.5.0", com.sun.mail.util.logging; uses:="javax.mail, javax.mail.internet, javax.mail.util, javax.activation, com.sun.mail.smtp"; version="1.5.0", com.sun.mail.handlers; uses:="javax.activation, javax.mail.internet, javax.mail, javax.xml.transform, javax.xml.transform.stream"; version="1.5.0"

Thanks,

Peter

     
 
 

Avatar

Level 2

Sorry for replying in this thread.

Seems like it was closed but want to maintain the context of the issue. can anyone please tell what was the final solution.

We have CQ on Jboss 6.2 so my assumption is, there is conflict with what is OOTB in Jboss modules with what CQ provide OOTB.

@Scott any update from your side, would love to hear it from experts on this