You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/12/10 19:38:31 UTC

(commons-email) branch master updated (5016793 -> 12353c9)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git


    from 5016793  Use constant instead of magic string
     new afdf5bb  Remove redundant null check
     new cfd4977  Use compact array declaration
     new 69c511a  Remove trailing whitespace
     new a8f4dd8  Remove unused import
     new 75d7b36  Fix typos
     new e470556  Email.setMailSession(Session) throws the more precise exception NullPointerException
     new 91e3d22  Remove unused import
     new 12353c9  Avoid possible NullPointerException in DataSourceClassPathResolver.resolve(String, boolean)

The 8 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/changes/changes.xml                            |  6 ++--
 src/main/java/org/apache/commons/mail/Email.java   | 22 +++++++-------
 .../java/org/apache/commons/mail/EmailUtils.java   | 21 +------------
 .../mail/resolver/DataSourceClassPathResolver.java | 35 +++++++++++-----------
 .../commons/mail/util/MimeMessageParser.java       |  2 +-
 .../apache/commons/mail/util/MimeMessageUtils.java |  2 +-
 .../resolver/DataSourceCompositeResolverTest.java  |  2 --
 7 files changed, 37 insertions(+), 53 deletions(-)


(commons-email) 07/08: Remove unused import

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit 91e3d22003d9d197c774253555ad5a7c5cfe4da0
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:32:33 2023 -0500

    Remove unused import
---
 src/main/java/org/apache/commons/mail/EmailUtils.java | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/mail/EmailUtils.java b/src/main/java/org/apache/commons/mail/EmailUtils.java
index c2b614e..72cd503 100644
--- a/src/main/java/org/apache/commons/mail/EmailUtils.java
+++ b/src/main/java/org/apache/commons/mail/EmailUtils.java
@@ -21,7 +21,6 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.BitSet;
-import java.util.Objects;
 import java.util.Random;
 
 import javax.mail.MessagingException;


(commons-email) 05/08: Fix typos

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit 75d7b3606e949bfc7288ede73aa6960a2d581630
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:13:09 2023 -0500

    Fix typos
---
 src/main/java/org/apache/commons/mail/EmailUtils.java            | 2 +-
 src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/commons/mail/EmailUtils.java b/src/main/java/org/apache/commons/mail/EmailUtils.java
index 992d798..a0c9505 100644
--- a/src/main/java/org/apache/commons/mail/EmailUtils.java
+++ b/src/main/java/org/apache/commons/mail/EmailUtils.java
@@ -308,7 +308,7 @@ final class EmailUtils
     /**
      * Convenience method to write a MimeMessage into a file.
      *
-     * @param resultFile the file containing the MimeMessgae
+     * @param resultFile the file containing the MimeMessage
      * @param mimeMessage the MimeMessage to write
      * @throws IOException writing the MimeMessage failed
      * @throws MessagingException writing the MimeMessage failed
diff --git a/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java b/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
index 1cfa4c0..249ad8f 100644
--- a/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
+++ b/src/main/java/org/apache/commons/mail/util/MimeMessageUtils.java
@@ -124,7 +124,7 @@ public final class MimeMessageUtils
      * Writes a MimeMessage into a file.
      *
      * @param mimeMessage the MimeMessage to write
-     * @param resultFile  the file containing the MimeMessgae
+     * @param resultFile  the file containing the MimeMessage
      * @throws MessagingException accessing MimeMessage failed
      * @throws IOException        writing the MimeMessage failed
      */


(commons-email) 04/08: Remove unused import

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit a8f4dd8e64711755e600dc307476777687a1a436
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:11:53 2023 -0500

    Remove unused import
---
 .../apache/commons/mail/resolver/DataSourceCompositeResolverTest.java   | 2 --
 1 file changed, 2 deletions(-)

diff --git a/src/test/java/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java b/src/test/java/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
index d59cfe1..6eca5c8 100644
--- a/src/test/java/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
+++ b/src/test/java/org/apache/commons/mail/resolver/DataSourceCompositeResolverTest.java
@@ -22,8 +22,6 @@ import static org.junit.Assert.*;
 import org.apache.commons.mail.DataSourceResolver;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.jupiter.api.function.Executable;
-
 import java.io.IOException;
 import java.net.URL;
 


(commons-email) 06/08: Email.setMailSession(Session) throws the more precise exception NullPointerException

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit e470556e2b83df46e317f050915c5e83199df9b7
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:22:28 2023 -0500

    Email.setMailSession(Session) throws the more precise exception
    NullPointerException
---
 src/changes/changes.xml                              |  5 +++--
 src/main/java/org/apache/commons/mail/Email.java     | 18 ++++++++++--------
 .../java/org/apache/commons/mail/EmailUtils.java     | 20 +-------------------
 3 files changed, 14 insertions(+), 29 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index aec5dc1..12130d8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -41,8 +41,9 @@
       <action issue="EMAIL-205" dev="ggregory" type="fix" due-to="Dimitrios Efthymiou, Alex Herbert">
         Update conversion code #153.
       </action>
-      <action type="fix" dev="sgoeschl" due-to="Alexander Lehmann">Email.setBounceAddress no longer accepts invalid email addresses.</action>
-      <action type="fix" dev="sgoeschl" due-to="Amir Behnam, Michael Osipov">Throw more specific exceptions in MimeMessageParser #11.</action>
+      <action type="fix" dev="ggregory" due-to="Alexander Lehmann">Email.setBounceAddress no longer accepts invalid email addresses.</action>
+      <action type="fix" dev="ggregory" due-to="Amir Behnam, Michael Osipov">Throw more specific exceptions in MimeMessageParser #11.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Email.setMailSession(Session) throws the more precise exception NullPointerException.</action>
       <!-- ADD -->
       <action type="add" due-to="Dependabot" dev="ggregory">
         Add github/codeql-action #75.
diff --git a/src/main/java/org/apache/commons/mail/Email.java b/src/main/java/org/apache/commons/mail/Email.java
index 553c148..bab4441 100644
--- a/src/main/java/org/apache/commons/mail/Email.java
+++ b/src/main/java/org/apache/commons/mail/Email.java
@@ -24,6 +24,7 @@ import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Properties;
 
 import javax.mail.Authenticator;
@@ -559,15 +560,15 @@ public abstract class Email
      * is supplied the implementation assumes that you have set a
      * authenticator and will use the existing mail session (as expected).
      *
-     * @param aSession mail session to be used
-     * @throws IllegalArgumentException if the session is {@code null}
+     * @param session mail session to be used
+     * @throws NullPointerException if {@code aSession} is {@code null}
      * @since 1.0
      */
-    public void setMailSession(final Session aSession)
+    public void setMailSession(final Session session)
     {
-        EmailUtils.notNull(aSession, "no mail session supplied");
+        Objects.requireNonNull(session, "no mail session supplied");
 
-        final Properties sessionProperties = aSession.getProperties();
+        final Properties sessionProperties = session.getProperties();
         final String auth = sessionProperties.getProperty(EmailConstants.MAIL_SMTP_AUTH);
 
         if ("true".equalsIgnoreCase(auth))
@@ -585,12 +586,12 @@ public abstract class Email
             else
             {
                 // assume that the given mail session contains a working authenticator
-                this.session = aSession;
+                this.session = session;
             }
         }
         else
         {
-            this.session = aSession;
+            this.session = session;
         }
     }
 
@@ -1454,7 +1455,8 @@ public abstract class Email
     public String sendMimeMessage()
        throws EmailException
     {
-        EmailUtils.notNull(this.message, "MimeMessage has not been created yet");
+        final Object object = this.message;
+        Objects.requireNonNull(object, "MimeMessage has not been created yet");
 
         try
         {
diff --git a/src/main/java/org/apache/commons/mail/EmailUtils.java b/src/main/java/org/apache/commons/mail/EmailUtils.java
index a0c9505..c2b614e 100644
--- a/src/main/java/org/apache/commons/mail/EmailUtils.java
+++ b/src/main/java/org/apache/commons/mail/EmailUtils.java
@@ -21,6 +21,7 @@ import java.io.File;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.BitSet;
+import java.util.Objects;
 import java.util.Random;
 
 import javax.mail.MessagingException;
@@ -132,25 +133,6 @@ final class EmailUtils
         return str != null && !str.isEmpty();
     }
 
-    /**
-     * Validate an argument, throwing {@code IllegalArgumentException}
-     * if the argument is {@code null}.
-     * <p>
-     * Copied from Commons Lang v2.1, svn 201930
-     * <p>
-     *
-     * @param object the object to check is not {@code null}
-     * @param message the exception message you would like to see if the object is {@code null}
-     * @throws IllegalArgumentException if the object is {@code null}
-     */
-    static void notNull(final Object object, final String message)
-    {
-        if (object == null)
-        {
-            throw new IllegalArgumentException(message);
-        }
-    }
-
     /**
      * Creates a random string whose length is the number of characters specified.
      * <p>


(commons-email) 02/08: Use compact array declaration

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit cfd4977cd1e50cec9e057ea800e88b707560e7d9
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:10:02 2023 -0500

    Use compact array declaration
---
 src/main/java/org/apache/commons/mail/Email.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/mail/Email.java b/src/main/java/org/apache/commons/mail/Email.java
index a410538..553c148 100644
--- a/src/main/java/org/apache/commons/mail/Email.java
+++ b/src/main/java/org/apache/commons/mail/Email.java
@@ -54,7 +54,7 @@ import org.apache.commons.mail.util.IDNEmailAddressConverter;
  */
 public abstract class Email
 {
-    private static final InternetAddress[] EMPTY_INTERNET_ADDRESS_ARRAY = new InternetAddress[0];
+    private static final InternetAddress[] EMPTY_INTERNET_ADDRESS_ARRAY = {};
 
     /** @deprecated since 1.3, use {@link EmailConstants#SENDER_EMAIL} instead */
     @Deprecated


(commons-email) 01/08: Remove redundant null check

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit afdf5bb9eea4390f3732c8041d25b2d366b96b13
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:09:39 2023 -0500

    Remove redundant null check
---
 src/main/java/org/apache/commons/mail/Email.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/mail/Email.java b/src/main/java/org/apache/commons/mail/Email.java
index 6239663..a410538 100644
--- a/src/main/java/org/apache/commons/mail/Email.java
+++ b/src/main/java/org/apache/commons/mail/Email.java
@@ -1917,7 +1917,7 @@ public abstract class Email
         {
             throw new IllegalArgumentException("name can not be null or empty");
         }
-        if (value == null || EmailUtils.isEmpty(value))
+        if (EmailUtils.isEmpty(value))
         {
             throw new IllegalArgumentException("value can not be null or empty");
         }


(commons-email) 08/08: Avoid possible NullPointerException in DataSourceClassPathResolver.resolve(String, boolean)

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit 12353c94f1c7c370a5639db4c85593cc1999e8a3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:38:26 2023 -0500

    Avoid possible NullPointerException in
    DataSourceClassPathResolver.resolve(String, boolean)
---
 src/changes/changes.xml                            |  1 +
 .../mail/resolver/DataSourceClassPathResolver.java | 35 +++++++++++-----------
 2 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 12130d8..bbef085 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -44,6 +44,7 @@
       <action type="fix" dev="ggregory" due-to="Alexander Lehmann">Email.setBounceAddress no longer accepts invalid email addresses.</action>
       <action type="fix" dev="ggregory" due-to="Amir Behnam, Michael Osipov">Throw more specific exceptions in MimeMessageParser #11.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Email.setMailSession(Session) throws the more precise exception NullPointerException.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Avoid possible NullPointerException in DataSourceClassPathResolver.resolve(String, boolean).</action>
       <!-- ADD -->
       <action type="add" due-to="Dependabot" dev="ggregory">
         Add github/codeql-action #75.
diff --git a/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java b/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
index b85a994..7a302c2 100644
--- a/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
+++ b/src/main/java/org/apache/commons/mail/resolver/DataSourceClassPathResolver.java
@@ -22,6 +22,7 @@ import javax.mail.util.ByteArrayDataSource;
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 
 /**
  * Creates a {@code DataSource} based on an class path.
@@ -82,35 +83,35 @@ public class DataSourceClassPathResolver extends DataSourceBaseResolver
 
     /** {@inheritDoc} */
     @Override
-    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException
-    {
-        try
-        {
-            if (!isCid(resourceLocation) && !isHttpUrl(resourceLocation))
-            {
+    public DataSource resolve(final String resourceLocation, final boolean isLenient) throws IOException {
+        try {
+            if (!isCid(resourceLocation) && !isHttpUrl(resourceLocation)) {
                 final String mimeType = FileTypeMap.getDefaultFileTypeMap().getContentType(resourceLocation);
                 final String resourceName = getResourceName(resourceLocation);
-                try (InputStream is = DataSourceClassPathResolver.class.getResourceAsStream(resourceName)){
-                    if (is == null) {
-                        if (isLenient)
-                        {
+                try (InputStream inputStream = DataSourceClassPathResolver.class.getResourceAsStream(resourceName)) {
+                    if (inputStream == null) {
+                        if (isLenient) {
                             return null;
                         }
                         throw new IOException("The following class path resource was not found : " + resourceLocation);
                     }
-                    final ByteArrayDataSource ds = new ByteArrayDataSource(is, mimeType);
+                    final ByteArrayDataSource ds = new ByteArrayDataSource(inputStream, mimeType);
                     // EMAIL-125: set the name of the DataSource to the normalized resource URL
                     // similar to other DataSource implementations, e.g. FileDataSource, URLDataSource
-                    ds.setName(DataSourceClassPathResolver.class.getResource(resourceName).toString());
+                    final URL resource = DataSourceClassPathResolver.class.getResource(resourceName);
+                    if (resource != null) {
+                        ds.setName(resource.toString());
+                    } else if (isLenient) {
+                        return null;
+                    } else {
+                        throw new IOException("The following class path resource was not found : " + resourceName);
+                    }
                     return ds;
                 }
             }
             return null;
-        }
-        catch (final IOException e)
-        {
-            if (isLenient)
-            {
+        } catch (final IOException e) {
+            if (isLenient) {
                 return null;
             }
             throw e;


(commons-email) 03/08: Remove trailing whitespace

Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git

commit 69c511a1235dafe1dc1db8e091efa20801fdaa93
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 14:10:21 2023 -0500

    Remove trailing whitespace
---
 src/main/java/org/apache/commons/mail/util/MimeMessageParser.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java b/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
index 01af957..a2aa2a8 100644
--- a/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
+++ b/src/main/java/org/apache/commons/mail/util/MimeMessageParser.java
@@ -272,7 +272,7 @@ public class MimeMessageParser
         final DataSource dataSource = dataHandler.getDataSource();
         final String contentType = getBaseMimeType(dataSource.getContentType());
         byte[] content;
-        try (InputStream inputStream = dataSource.getInputStream()) 
+        try (InputStream inputStream = dataSource.getInputStream())
         {
             content = this.getContent(inputStream);
         }