You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/08/03 10:12:50 UTC

[camel] branch main updated: CAMEL-18338: camel-mail - Fix NPE in camel-mail consumer

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

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 58a3b430853 CAMEL-18338: camel-mail - Fix NPE in camel-mail consumer
58a3b430853 is described below

commit 58a3b430853fb0acc3a094aefcc4ecbf10cf5c5a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Wed Aug 3 12:12:19 2022 +0200

    CAMEL-18338: camel-mail - Fix NPE in camel-mail consumer
---
 .../org/apache/camel/component/mail/MailConsumer.java     | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
index 3c41fdb9bbd..82617223d2b 100644
--- a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
+++ b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java
@@ -156,6 +156,7 @@ public class MailConsumer extends ScheduledBatchPollingConsumer {
                 LOG.debug(msg, e);
             }
             disconnect();
+            return 0; // return since we cannot poll mail messages, but will re-connect on next poll.
         }
 
         try {
@@ -176,12 +177,12 @@ public class MailConsumer extends ScheduledBatchPollingConsumer {
         } finally {
             // need to ensure we release resources, but only if closeFolder or disconnect = true
             if (getEndpoint().getConfiguration().isCloseFolder() || getEndpoint().getConfiguration().isDisconnect()) {
-                if (LOG.isDebugEnabled()) {
-                    LOG.debug("Close mailbox folder {} from {}", folder.getName(),
-                            getEndpoint().getConfiguration().getMailStoreLogInformation());
-                }
                 try {
-                    if (folder.isOpen()) {
+                    if (folder != null && folder.isOpen()) {
+                        if (LOG.isDebugEnabled()) {
+                            LOG.debug("Close mailbox folder {} from {}", folder.getName(),
+                                    getEndpoint().getConfiguration().getMailStoreLogInformation());
+                        }
                         folder.close(true);
                     }
                 } catch (Exception e) {
@@ -205,7 +206,9 @@ public class MailConsumer extends ScheduledBatchPollingConsumer {
             LOG.debug("Disconnecting from {}", getEndpoint().getConfiguration().getMailStoreLogInformation());
         }
         try {
-            store.close();
+            if (store != null) {
+                store.close();
+            }
         } catch (Exception e) {
             LOG.debug("Could not disconnect from {}. This exception is ignored.",
                     getEndpoint().getConfiguration().getMailStoreLogInformation(), e);