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 <garydgreg...@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>