jakartaee / jakartaee/mail-api
Session should not throw java.util.ServiceConfigurationError
@jmehrens is already working on this.
Since Apr 1, 2021.
- Dominant language
- Java
- Stars
- 285
- Forks
- 109
- Avg merge
- 15h 19m
- Merged PRs (30d)
- 1
Description
Running the test suite under JDK7 produces 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.<init>(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)
This does not occur under JDK8 and later due to https://bugs.openjdk.java.net/browse/JDK-7198496
The session should:
- Not let ServiceConfigurationError be thrown to the caller. Session was retrofitted to use service loader in
GH 323 Support loading protocol providers using ServiceLoaderand the behavior change of throwing was not added to the spec. Instead SCE should be logged to the debug logger and continue. - Providers that are not default providers should be loaded by context class loader then failback to the given classloader, then ClassLoader.getSystemClassLoader(), and finally ignore.
- Providers that are default providers should use the classloader of the Provider.class then failback to the given cl.
- The service loader iterator must run until fully exhausted. This will ensure that a single failure doesn't prevent other providers from being loaded.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.