simple-java-mail icon indicating copy to clipboard operation
simple-java-mail copied to clipboard

Possible Issue with Dependencies and Linux

Open Faelean opened this issue 3 years ago • 4 comments

Hi,

after we've updated from 6.6.1 to 7.4.0 we ran into an issue with the dependencies included.

The core-module has jakarta.activation:2.0.1 and jakarta.mail:2.0.1 as direct dependencies. The smime-module has jakarta.activation-api:2.1.0 and jakarta.mail-api:2.1.0 as dependencies (via utils-mail-smime:2.0.1 --> bcjmail-jdk15to18:1.70).

On the website for Jakarta Mail it says that

The Jakarta Mail API definitions only, suitable for compiling against; use only with a Maven “provided” dependency scope

The Maven Page for Bouncy Castle Jakarta S/MIME API lists them as compile dependencies, so in theory they should not be needed at runtime and therefore shouldn't be included when building the project with Maven (same with bcprov, bcutil and bcpkix but that's not an issue so far).

The issue this causes seems to be the following: On a Windows machine the Java classloader adds the jakarta.activation-2.0.1.jar first and after that the jakarta.activation-api-2.1.0.jar. Your batch file for the standalone version also adds the jakarta.activation-2.0.1.jar first (line 75 in the sjm.bat in the cli-module-7.4.0-standalone-cli.zip). If you do the same thing on a linux machine (Ubuntu 20.04 in this case) the classloader adds the jakarta.activation-api-2.1.0.jar first which leads to this error:

java.lang.ExceptionInInitializerError
java.lang.ExceptionInInitializerError: null
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:135) ~[simple-java-mail-7.4.0.jar:?]
	at org.simplejavamail.converter.EmailConverter.mimeMessageToEmailBuilder(EmailConverter.java:122) ~[simple-java-mail-7.4.0.jar:?]
	at org.simplejavamail.converter.EmailConverter.emlToEmailBuilder(EmailConverter.java:390) ~[simple-java-mail-7.4.0.jar:?]
	at org.simplejavamail.converter.EmailConverter.emlToEmailBuilder(EmailConverter.java:369) ~[simple-java-mail-7.4.0.jar:?]
	at org.simplejavamail.converter.EmailConverter.emlToEmail(EmailConverter.java:303) ~[simple-java-mail-7.4.0.jar:?]
	at org.simplejavamail.converter.EmailConverter.emlToEmail(EmailConverter.java:295) ~[simple-java-mail-7.4.0.jar:?]
...

Caused by: java.lang.RuntimeException: Provider for jakarta.activation.spi.MailcapRegistryProvider cannot be found
	at jakarta.activation.FactoryFinder.find(FactoryFinder.java:90) ~[jakarta.activation-api-2.1.0.jar:?]
	at jakarta.activation.MailcapCommandMap.getImplementation(MailcapCommandMap.java:696) ~[jakarta.activation-api-2.1.0.jar:?]
	at jakarta.activation.MailcapCommandMap.loadFile(MailcapCommandMap.java:284) ~[jakarta.activation-api-2.1.0.jar:?]
	at jakarta.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:154) ~[jakarta.activation-api-2.1.0.jar:?]
	at jakarta.activation.CommandMap.getDefaultCommandMap(CommandMap.java:60) ~[jakarta.activation-api-2.1.0.jar:?]
	at org.simplejavamail.converter.internal.mimemessage.MimeMessageParser.<clinit>(MimeMessageParser.java:127) ~[simple-java-mail-7.4.0.jar:?]
	... 59 more

Renaming the jakarta.activation-2.0.1.jar to for example jakarta.activation-zzz-2.0.1.jar leads to the same issue on a windows machine.

We solved this on our end by completely removing both the jakarta.activation-api-2.1.0.jar and the jakarta.mail-api-2.1.0.jar from our project, but given that at the moment they are included when building the project we're not entirely sure if this has any consequences during runtime (allthough we haven't found any so far).

Faelean avatar Jul 29 '22 12:07 Faelean

The non-api jars have exactly the same classes in it so in runtime this should be fine. I'm wondering why smime-module relies on the -api version, though. Can't remember that being intentional, but I'll have a look.

bbottema avatar Jul 29 '22 15:07 bbottema

Ok so bouncy castle pulls it in, as you said. I've tested ands verified the following doesn't pose any problems:

<exclusions>
   <exclusion>
      <groupId>jakarta.mail</groupId>
      <artifactId>jakarta.mail-api</artifactId>
   </exclusion>
   <exclusion>
      <groupId>jakarta.activation</groupId>
      <artifactId>jakarta.activation-api</artifactId>
   </exclusion>
</exclusions>

Would this solve your issue?

Note: compile time dependency implies runtime dependency as well, it just won't compile at all without it. But in this case, the -api jars are redunant if you include the Jakarta implementation, like Simple Java Mail does.

bbottema avatar Jul 29 '22 17:07 bbottema

https://github.com/bcgit/bc-java/issues/1199

grafik

kozi avatar Jul 30 '22 07:07 kozi

Ok so bouncy castle pulls it in, as you said. I've tested ands verified the following doesn't pose any problems:

<exclusions>
   <exclusion>
      <groupId>jakarta.mail</groupId>
      <artifactId>jakarta.mail-api</artifactId>
   </exclusion>
   <exclusion>
      <groupId>jakarta.activation</groupId>
      <artifactId>jakarta.activation-api</artifactId>
   </exclusion>
</exclusions>

Would this solve your issue?

Since the primary issue is with Bouncy Castle and not your project this workaround should solve our issue until they have fixed in on their end.

Faelean avatar Aug 05 '22 08:08 Faelean

Closing as nothing more I can do here.

bbottema avatar Jan 24 '23 17:01 bbottema