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

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


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

commit ac927a57f687c62b8caee8f0476a2db663dea59b
Author: Claus Ibsen <claus.ib...@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);

Reply via email to