jakartaee / jakartaee/mail-api

MailHandler should catch ServiceConfigurationError

Open
#548 0 comments 0 reactions 1 assignee Claimed by @jmehrens View on GitHub
Component: other
Dominant language
Java
Stars
285
Forks
109
Avg merge
15h 19m
Merged PRs (30d)
1

Description

JakaraMail 1.6.6 MailHandler test fails when running under JDK 1.7 with the following:
```
Testcase: testCloseContextClassLoader(com.sun.mail.util.logging.MailHandlerTest): Caused an ERROR
javax.mail.Provider: Provider com.sun.mail.imap.IMAPProvider not found
java.util.ServiceConfigurationError: javax.mail.Provider: Provider com.sun.mail.imap.IMAPProvider not found
at java.util.ServiceLoader.fail(ServiceLoader.java:231)
at java.util.ServiceLoader.access$300(ServiceLoader.java:181)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:365)
at java.util.ServiceLoader$1.next(ServiceLoader.java:445)
at javax.mail.Session.loadProviders(Session.java:964)
at javax.mail.Session.(Session.java:254)
at javax.mail.Session.getInstance(Session.java:281)
at com.sun.mail.util.logging.MailHandler.initSession(MailHandler.java:3448)
at com.sun.mail.util.logging.MailHandler.writeLogRecords0(MailHandler.java:2823)
at com.sun.mail.util.logging.MailHandler.writeLogRecords(MailHandler.java:2790)
at com.sun.mail.util.logging.MailHandler.close(MailHandler.java:853)
at com.sun.mail.util.logging.MailHandlerTest.testCloseContextClassLoader0(MailHandlerTest.java:2295)
at com.sun.mail.util.logging.MailHandlerTest.testCloseContextClassLoader(MailHandlerTest.java:2273)
```
Steps to reproduce the behavior:
1. Install JDK 7.
2. Run the logging-mailhander tests.

In the field, the workaround would be to add a MailHandler.verify property to the logging properties. The documentation already suggests this.

This appears to be a regression from `GH 323 Support loading protocol providers using ServiceLoader`. This does not occur under JDK8 and later due to https://bugs.openjdk.java.net/browse/JDK-7198496

The MailHandler should be patched to:

1. Catch ServiceConfigurationError and adapt it so it can be reported to the error manager. This is need to support JavaMail versions without the fix for https://github.com/eclipse-ee4j/mail/issues/548
2. The context classloader needs to be adjusted during close and other method to support the service loader.

Overall, this shows that there is a gap in testing because project is not running all tests under each major version of the JDK.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.