mayurbm opened a new pull request, #25553: URL: https://github.com/apache/camel/pull/25553
## Summary Fixes [CAMEL-24403](https://issues.apache.org/jira/browse/CAMEL-24403). When an IMAP message is expunged between fetch time and the on-completion commit callback, `IMAPMessage.setFlag()` throws `MessageRemovedException` whose `getMessage()` returns `null`, producing a confusing log entry: ``` Caused by: [javax.mail.MessageRemovedException - null] ``` ## Root Cause `MessageRemovedException` extends `MessagingException` but is constructed without a message string so `getMessage()` returns `null`. The existing `catch (MessagingException e)` block in `processCommit()` passed it directly to the exception handler, which included the null in the formatted output. ## Fix Catch `MessageRemovedException` before the generic `MessagingException` handler in `processCommit()` and wrap it with an explicit description: ```java } catch (MessageRemovedException e) { MessagingException wrapped = new MessagingException( "Message already removed/expunged on server (no flag update possible)", e); getExceptionHandler().handleException( "Error occurred during committing mail message: " + mail, exchange, wrapped); } catch (MessagingException e) { getExceptionHandler().handleException( "Error occurred during committing mail message: " + mail, exchange, e); } ``` Expected log output after fix: ``` Caused by: [javax.mail.MessagingException - Message already removed/expunged on server (no flag update possible)] ``` ## Stack Trace (from CAMEL-24403) ``` javax.mail.MessageRemovedException at com.sun.mail.imap.IMAPMessage.checkExpunged(IMAPMessage.java:280) at com.sun.mail.imap.IMAPMessage.setFlags(IMAPMessage.java:1110) at javax.mail.Message.setFlag(Message.java:596) at org.apache.camel.component.mail.MailConsumer.processCommit(MailConsumer.java:506) at org.apache.camel.component.mail.MailConsumer$1.onComplete(MailConsumer.java:237) at org.apache.camel.support.UnitOfWorkHelper.doneSynchronization(UnitOfWorkHelper.java:104) at org.apache.camel.support.UnitOfWorkHelper.doneSynchronizations(UnitOfWorkHelper.java:89) at org.apache.camel.impl.engine.DefaultUnitOfWork.done(DefaultUnitOfWork.java:238) at org.apache.camel.support.UnitOfWorkHelper.doneUow(UnitOfWorkHelper.java:61) at org.apache.camel.impl.engine.CamelInternalProcessor$UnitOfWorkProcessorAdvice.after(CamelInternalProcessor.java:770) at org.apache.camel.impl.engine.CamelInternalProcessor$AsyncAfterTask.done(CamelInternalProcessor.java:263) at org.apache.camel.AsyncCallback.run(AsyncCallback.java:44) at org.apache.camel.impl.engine.DefaultReactiveExecutor$Worker.schedule(DefaultReactiveExecutor.java:193) at org.apache.camel.processor.Pipeline.process(Pipeline.java:185) at org.apache.camel.impl.engine.CamelInternalProcessor.process(CamelInternalProcessor.java:398) at org.apache.camel.component.mail.MailConsumer.processExchange(MailConsumer.java:449) at org.apache.camel.component.mail.MailConsumer.processBatch(MailConsumer.java:258) at org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:165) at org.apache.camel.support.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:202) at org.apache.camel.support.ScheduledPollConsumer.run(ScheduledPollConsumer.java:116) at org.apache.camel.pollconsumer.quartz.QuartzScheduledPollConsumerJob.execute(QuartzScheduledPollConsumerJob.java:61) at org.quartz.core.JobRunShell.run(JobRunShell.java:202) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) ``` ## Changes - `components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConsumer.java` — add `jakarta.mail.MessageRemovedException` import; split catch block - `components/camel-mail/src/test/java/org/apache/camel/component/mail/MailConsumerCommitExpungedMessageTest.java` (new) — 2 unit tests: - `testCommitWithExpungedMessageProducesNonNullCause` — verifies `MessageRemovedException` is wrapped with a non-null message and root cause preserved - `testCommitWithOtherMessagingExceptionPassedThroughAsIs` — verifies other `MessagingException` types pass through unchanged ## Test Results ``` Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 (JDK 21, Maven 3.9) ``` ## AI Attribution This contribution was developed with AI assistance using [Claude Code](https://github.com/anthropics/claude-code). ``` Co-authored-by: Claude <[email protected]> ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
