Fixed issue 40606: NPE if email timeout is not set
authorJavier Armendáriz <javier.armendariz@openbravo.com>
Mon, 15 Apr 2019 10:24:50 +0200
changeset 35684 1f23318a7a81
parent 35683 038c8b681054
child 35685 e735af032865
Fixed issue 40606: NPE if email timeout is not set

Adding another null check to verify not only in the case that the email config
does not exist, but also that the timeout value is empty. In both cases the
default timeout should be used.
src/org/openbravo/erpCommon/utility/poc/EmailManager.java
--- a/src/org/openbravo/erpCommon/utility/poc/EmailManager.java	Tue Mar 05 19:04:20 2019 +0530
+++ b/src/org/openbravo/erpCommon/utility/poc/EmailManager.java	Mon Apr 15 10:24:50 2019 +0200
@@ -9,7 +9,7 @@
  * either express or implied. See the License for the specific language
  * governing rights and limitations under the License. The Original Code is
  * Openbravo ERP. The Initial Developer of the Original Code is Openbravo SLU All
- * portions are Copyright (C) 2001-2018 Openbravo SLU All Rights Reserved.
+ * portions are Copyright (C) 2001-2019 Openbravo SLU All Rights Reserved.
  * Contributor(s): ______________________________________.
  * ***********************************************************************
  */
@@ -63,7 +63,7 @@
   public static void sendEmail(EmailServerConfiguration conf, EmailInfo email) throws Exception {
 
     String decryptedPassword = FormatUtilities.encryptDecrypt(conf.getSmtpServerPassword(), false);
-    Long timeoutMillis = TimeUnit.SECONDS.toMillis(conf.getSmtpConnectionTimeout());
+    Long timeoutMillis = getSmtpConnectionTimeout(conf);
 
     sendEmail(conf.getSmtpServer(), conf.isSMTPAuthentification(), conf.getSmtpServerAccount(),
         decryptedPassword, conf.getSmtpConnectionSecurity(), conf.getSmtpPort().intValue(),
@@ -84,14 +84,18 @@
 
     EmailServerConfiguration configuration = EmailUtils.getEmailConfiguration(OBContext
         .getOBContext().getCurrentOrganization());
-    Long timeoutMillis = (configuration != null) ? TimeUnit.SECONDS.toMillis(configuration
-        .getSmtpConnectionTimeout()) : DEFAULT_SMTP_TIMEOUT;
+    Long timeoutMillis = getSmtpConnectionTimeout(configuration);
 
     sendEmail(host, auth, username, password, connSecurity, port, senderAddress, recipientTO,
         recipientCC, recipientBCC, replyTo, subject, content, contentType, attachments, sentDate,
         headerExtras, timeoutMillis.intValue());
   }
 
+  private static Long getSmtpConnectionTimeout(EmailServerConfiguration configuration) {
+    return (configuration != null && configuration.getSmtpConnectionTimeout() != null) ? TimeUnit.SECONDS
+        .toMillis(configuration.getSmtpConnectionTimeout()) : DEFAULT_SMTP_TIMEOUT;
+  }
+
   private static void sendEmail(String host, boolean auth, String username, String password,
       String connSecurity, int port, String senderAddress, String recipientTO, String recipientCC,
       String recipientBCC, String replyTo, String subject, String content, String contentType,