jakartaee / jakartaee/mail-api

Session should not throw java.util.ServiceConfigurationError

Open
#550 5 comments 1 reaction 1 assignee View on GitHub

@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:

  1. Not let ServiceConfigurationError be thrown to the caller. Session was retrofitted to use service loader in GH 323 Support loading protocol providers using ServiceLoader and the behavior change of throwing was not added to the spec. Instead SCE should be logged to the debug logger and continue.
  2. 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.
  3. Providers that are default providers should use the classloader of the Provider.class then failback to the given cl.
  4. The service loader iterator must run until fully exhausted. This will ensure that a single failure doesn't prevent other providers from being loaded.

https://github.com/eclipse-ee4j/mail/blob/31688b7e1860e83292ec32fb656808447fe13ccb/mail/src/main/java/javax/mail/Session.java#L976

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.