Skip to content

Commit

Permalink
ServiceLoader loads default providers ahead of application providers -
Browse files Browse the repository at this point in the history
…fix #350
  • Loading branch information
bshannon committed Mar 22, 2019
1 parent 1e29579 commit 7ca5b33
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 98 deletions.
1 change: 1 addition & 0 deletions doc/release/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ longer available.
----------------------------
The following bugs have been fixed in the 1.6.4 release.

E 350 ServiceLoader loads default providers ahead of application providers
E 361 Support the NTLMv2 authentication protocol
E 363 Multipart message sent with headers but no body
E 366 NPE when recipients not set
Expand Down
15 changes: 15 additions & 0 deletions doc/release/COMPAT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ with this release of the JavaMail API.
but if this causes compatibility problems it can be disabled by
setting the property "mail.<protocol>.auth.ntlm.v2" to "false".

- Protocol providers now always loaded using ServiceLoader and config files

The changes in JavaMail 1.6.2 to use ServiceLoader introduced
an incompatibility with some commonn use cases. To resolve that
incompatibility, the load order for providers has changed to:

1. Non-default providers available as services.
2. Providers configured via javamail.providers.
3. Providers configured via javamail.default.providers.
4. Default providers available as services.

An implementation-specific @DefaultProvider annotation is used
to mark the providers included with JavaMail (#4 above), and
should not be used by applications.


-- JavaMail 1.6.3 --

Expand Down
5 changes: 4 additions & 1 deletion gimap/src/main/java/com/sun/mail/gimap/GmailProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The Gmail IMAP protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class GmailProvider extends Provider {
public GmailProvider() {
super(Provider.Type.STORE, "gimap", GmailStore.class.getName(),
Expand Down
5 changes: 4 additions & 1 deletion gimap/src/main/java/com/sun/mail/gimap/GmailSSLProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The Gmail IMAP protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class GmailSSLProvider extends Provider {
public GmailSSLProvider() {
super(Provider.Type.STORE, "gimaps", GmailSSLStore.class.getName(),
Expand Down
5 changes: 4 additions & 1 deletion mail/src/main/java/com/sun/mail/imap/IMAPProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The IMAP protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class IMAPProvider extends Provider {
public IMAPProvider() {
super(Provider.Type.STORE, "imap", IMAPStore.class.getName(),
Expand Down
5 changes: 4 additions & 1 deletion mail/src/main/java/com/sun/mail/imap/IMAPSSLProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The IMAP SSL protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class IMAPSSLProvider extends Provider {
public IMAPSSLProvider() {
super(Provider.Type.STORE, "imaps", IMAPSSLStore.class.getName(),
Expand Down
5 changes: 4 additions & 1 deletion mail/src/main/java/com/sun/mail/pop3/POP3Provider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The POP3 protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class POP3Provider extends Provider {
public POP3Provider() {
super(Provider.Type.STORE, "pop3", POP3Store.class.getName(),
Expand Down
5 changes: 4 additions & 1 deletion mail/src/main/java/com/sun/mail/pop3/POP3SSLProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The POP3 SSL protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class POP3SSLProvider extends Provider {
public POP3SSLProvider() {
super(Provider.Type.STORE, "pop3s", POP3SSLStore.class.getName(),
Expand Down
5 changes: 4 additions & 1 deletion mail/src/main/java/com/sun/mail/smtp/SMTPProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The SMTP protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class SMTPProvider extends Provider {
public SMTPProvider() {
super(Provider.Type.TRANSPORT, "smtp", SMTPTransport.class.getName(),
Expand Down
5 changes: 4 additions & 1 deletion mail/src/main/java/com/sun/mail/smtp/SMTPSSLProvider.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,9 +18,12 @@

import javax.mail.Provider;

import com.sun.mail.util.DefaultProvider;

/**
* The SMTP SSL protocol provider.
*/
@DefaultProvider // Remove this annotation if you copy this provider
public class SMTPSSLProvider extends Provider {
public SMTPSSLProvider() {
super(Provider.Type.TRANSPORT, "smtps",
Expand Down
31 changes: 31 additions & 0 deletions mail/src/main/java/com/sun/mail/util/DefaultProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (c) 2019 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/

package com.sun.mail.util;

import java.lang.annotation.Target;
import java.lang.annotation.ElementType;

/**
* Annotation to mark the default providers that are part of JavaMail.
* DO NOT use this on any provider made available independently.
*
* @author Bill Shannon
* @since JavaMail 1.6.4
*/
@Target(ElementType.TYPE)
public @interface DefaultProvider {
}

0 comments on commit 7ca5b33

Please sign in to comment.