Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime errors when updating to jakarta.mail-api 2.1.0 and Angus #37

Closed
adamretter opened this issue Oct 23, 2022 · 13 comments
Closed

Runtime errors when updating to jakarta.mail-api 2.1.0 and Angus #37

adamretter opened this issue Oct 23, 2022 · 13 comments

Comments

@adamretter
Copy link

adamretter commented Oct 23, 2022

Describe the bug
I am trying to update the dependencies of the Greenmail Java Test library to use jakarta.mail-api 2.1.0 and the Eclipse Angus implementation. My attempt is in this very small Pull Request - greenmail-mail-test/greenmail#496

I am experiencing a problem in my Pull Request branch when I run the Greenmail test suite using mvn clean test.

I see the following errors (over and over for many tests):

java.lang.ArrayStoreException
	at java.lang.System.arraycopy(Native Method)
	at java.util.ArrayList.toArray(ArrayList.java:414)
	at jakarta.activation.MailcapCommandMap.<init>(MailcapCommandMap.java:181)
        ...

This comes about because MailcapCommandMap in the 2.1.0 API imports jakarta.activation.MailcapRegistry and creates an array of that type at line 180:

DB = new MailcapRegistry[dbv.size()];

However, the type added to the dbv list at line 172:

loadAllResources(dbv, "META-INF/mailcap");

is of type: com.sun.activation.registries.MailcapFile and hence this causes the above error and stacktrace at line 181:

DB = dbv.toArray(DB);

NOTE The packages of the two classes are different, i.e.:jakarta.activation.MailcapRegistry and com.sun.activation.registries.MailcapFile.

To Reproduce
Steps to reproduce the behavior:

  1. git clone https://github.com/evolvedbinary/greenmail.git
  2. cd greenmail
  3. git checkout update-jakarta-mail-api-2.1.0
  4. mvn clean verify -Dtest=ImapProtocolTest#testUidSearchTextWithCharset
  5. See error

Expected behavior
I expect the tests to pass.

Desktop (please complete the following information):

  • OS: macOS 12.6
  • OpenJDK 1.8.0_292
@jbescos
Copy link
Member

jbescos commented Oct 24, 2022

Hi @adamretter ,

Test is passing to me for some reason:

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.icegreen.greenmail.imap.commands.ImapProtocolTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.291 s - in com.icegreen.greenmail.imap.commands.ImapProtocolTest
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Anyway, this issue you have could be related to:
jakartaee/mail-api#599

Unfortunately this fix is not in maven central yet. But you can verify it doing the next:

Generate  jakarta.mail:jakarta.mail-api:2.1.1-SNAPSHOT:
git clone https://github.com/eclipse-ee4j/mail.git
cd mail/api
mvn clean install

Then update your pom.xml jakarta.mail:jakarta.mail-api to version 2.1.1-SNAPSHOT and run the test.

@adamretter
Copy link
Author

adamretter commented Oct 25, 2022

@jbescos Okay so just to confirm, I re-ran my original test on a new clean Ubuntu VM that I built, I still see the test failing. So as that is now two different machines failing the test I am certain it is failing.

As you suggested I built and installed the 2.2.1-SNAPSHOT of jakarta.mail:jakarta.mail-api and then updated my greenmail pom.xml files to use it. Unfortunately it made no difference and I still get the same errors.

@adamretter
Copy link
Author

adamretter commented Oct 25, 2022

I think I may have found something interesting...

I noticed that I was only able to build https://github.com/eclipse-ee4j/mail.git with JDK 11. However, the output produced targets Java 8 (i.e. Java Class file format 52.0) as I would expect.

When I run the greenmail tests against either jakarta.mail:jakarta.mail-api version 2.1.0 or 2.1.1-SNAPSHOT using Java 8, the tests fail as described. However, if I run the tests using Java 11 then all of the tests pass.

So it seems to me that Jakarta Mail 2.1.0 is incompatible with Java 8, this surprises me as it is currently compiled to target Java 8.

I also observe that the previous release version 2.0.1 is compiled with JDK 11 and produces output targeting Java 8, and yet that version works perfectly on Java 8 (and also with greenmail on Java 8).

So I guess the question is:

Do you intend that version 2.1.0 and newer only support Java 11+ at runtime?

  • If so, perhaps it would be better not to target Java 8 as the output format, so it is more obvious to users that that is the case. Perhaps also some documentation to this effect would have helped here too.
  • If not, it seems like there is a bug with version 2.1.0+ on Java 8... I note your GitHub Actions CI only tests Java 11 and 17.

@jbescos
Copy link
Member

jbescos commented Oct 25, 2022

So it works when you use JDK 11 in runtime. I was actually using JDK 11 when I run your test.

There is an open PR where we move to JDK 11. After this is merged it should be solved, because it will not allow to use JDK8 in runtime.

The error is coming from Jakarta Activation. Probably I will not investigate this if previous PR is merged because whatever the error is, it works when using JDK 11.

Regarding the compilation questions, I don't know the full story but JDK 8 was to make it work with Android I think. And additionally it was compiled with JDK11 to make it work with modules.

@adamretter
Copy link
Author

@jbescos Okay, so if I understand correctly -

  1. The published jakarta.mail-api 2.1.0 does not work at runtime with Java 8.
  2. You don't consider that a bug. Your intention was for it to require Java 11.

If that is the case... can you please document somewhere that version 2.1.0 and newer require Java 11 (even though compiled for Java 8)? I think that would have saved myself, yourself, and likely others, quite some time.

Kind regards.

@jbescos
Copy link
Member

jbescos commented Oct 27, 2022

@adamretter you motivated me to investigate a bit further 😄

The real issue is java.lang.ClassCastException: com.sun.activation.registries.MailcapFile cannot be cast to jakarta.activation.MailcapRegistry
Basically JDK8 contains a class com.sun.activation.registries.MailcapFile that does not extend MailcapRegistry
This class does not exist in JDK11, and this is why it works with JDK11.

Angus-Activation has its own definition of this class: https://github.com/eclipse-ee4j/angus-activation/blob/master/activation-registry/src/main/java/com/sun/activation/registries/MailcapFile.java

As you can see it implements MailcapRegistry, so no issues here.

I am not expert in Activation yet, but it seems this is something to investigate in Activation. I will open an issue there and possibly I will get into the details. Maybe the solution is just to use JDK11, we will see.

@up2-date
Copy link

I have the same ProblemI had the same problem. I tried to switch to angus-mail and get the same error message. Our project also uses Java 8, it would be a pity to end the support of Java 8.

@jbescos
Copy link
Member

jbescos commented Nov 1, 2022

This issue should be solved with this PR:
eclipse-ee4j/angus-activation#11

I verified it with the steps provided by @adamretter . You can try it too downloading my branch https://github.com/jbescos/angus-activation/tree/jafIssue103 , compiling it with mvn clean install and setting your angus-activation dependency to:

      <dependency>
        <groupId>org.eclipse.angus</groupId>
        <artifactId>angus-activation</artifactId>
        <version>1.0.0-SNAPSHOT</version>
      </dependency>

Regarding keeping mail to support JDK8, I will update my other PR #36 to still support it.

@lukasj
Copy link
Member

lukasj commented Nov 1, 2022

loading jakarta.activation-api+angus-activation through endorsed on SE 8 should help. Can you try it, please (either use -Djava.endorsed.dirs=... or copy both jars to $JAVA_HOME/lib/endorsed)?

@adamretter
Copy link
Author

@jbescos Thank you :-)
Using your branch of angus-activation, I can confirm that with version 1.0.0-SNAPSHOT of angus-activation set in my PR to Greenmail - greenmail-mail-test/greenmail#496 then all tests now pass

Silly question maybe... but any idea of when angus-activation and angus-mail might see a release version that addresses this (I am not in a rush - just curious).

@up2-date
Copy link

up2-date commented Nov 2, 2022

I would be interested in that too, I am updating our libs and I would like to use stable versions. Thanks for the effort

@lukasj
Copy link
Member

lukasj commented Jan 13, 2023

use angus-activation 2.0.0 instead of 1.x

@lukasj
Copy link
Member

lukasj commented Jan 19, 2023

I believe this is fixed with angus-activation 2.0.0 in master for angus-mail 2.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants