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

orpiske 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 ffbce6a277e4 camel-mail: fix incorrect guard in MailConverters 
multipart loop
ffbce6a277e4 is described below

commit ffbce6a277e44bc2fbff7b1eaeac657484be31f3
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Mon Mar 30 12:42:53 2026 +0000

    camel-mail: fix incorrect guard in MailConverters multipart loop
    
    The inner while loop in toString(Multipart) was checking
    multipart.getCount() (the outer method parameter) instead of the
    inner MimeMultipart obtained from content. This made the guard
    dead code since the outer count is always >= 1 when reached.
    
    Fix the guard to check the inner MimeMultipart's count and apply
    instanceof pattern matching to eliminate the separate cast.
    
    Claude Code on behalf of Otavio R. Piske
    
    Co-Authored-By: Claude Opus 4.6 <[email protected]>
---
 .../java/org/apache/camel/component/mail/MailConverters.java     | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git 
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
 
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
index 846c8f181685..6d7852399adf 100644
--- 
a/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
+++ 
b/components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java
@@ -61,8 +61,7 @@ public final class MailConverters {
     @Converter
     public static String toString(Message message) throws MessagingException, 
IOException {
         Object content = message.getContent();
-        while (content instanceof MimeMultipart) {
-            MimeMultipart multipart = (MimeMultipart) content;
+        while (content instanceof MimeMultipart multipart) {
             if (multipart.getCount() > 0) {
                 BodyPart part = multipart.getBodyPart(0);
                 content = part.getContent();
@@ -85,11 +84,11 @@ public final class MailConverters {
             for (int i = 0; i < size; i++) {
                 BodyPart part = multipart.getBodyPart(i);
                 Object content = part.getContent();
-                while (content instanceof MimeMultipart) {
-                    if (multipart.getCount() < 1) {
+                while (content instanceof MimeMultipart mimeMultipart) {
+                    if (mimeMultipart.getCount() < 1) {
                         break;
                     }
-                    part = ((MimeMultipart) content).getBodyPart(0);
+                    part = mimeMultipart.getBodyPart(0);
                     content = part.getContent();
                 }
                 // Perform a case-insensitive "startsWith" check that works 
for different locales

Reply via email to