Skip to content

Commit ffbce6a

Browse files
orpiskeclaude
andcommitted
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 <noreply@anthropic.com>
1 parent dba5a0f commit ffbce6a

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

components/camel-mail/src/main/java/org/apache/camel/component/mail/MailConverters.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ private MailConverters() {
6161
@Converter
6262
public static String toString(Message message) throws MessagingException, IOException {
6363
Object content = message.getContent();
64-
while (content instanceof MimeMultipart) {
65-
MimeMultipart multipart = (MimeMultipart) content;
64+
while (content instanceof MimeMultipart multipart) {
6665
if (multipart.getCount() > 0) {
6766
BodyPart part = multipart.getBodyPart(0);
6867
content = part.getContent();
@@ -85,11 +84,11 @@ public static String toString(Multipart multipart) throws MessagingException, IO
8584
for (int i = 0; i < size; i++) {
8685
BodyPart part = multipart.getBodyPart(i);
8786
Object content = part.getContent();
88-
while (content instanceof MimeMultipart) {
89-
if (multipart.getCount() < 1) {
87+
while (content instanceof MimeMultipart mimeMultipart) {
88+
if (mimeMultipart.getCount() < 1) {
9089
break;
9190
}
92-
part = ((MimeMultipart) content).getBodyPart(0);
91+
part = mimeMultipart.getBodyPart(0);
9392
content = part.getContent();
9493
}
9594
// Perform a case-insensitive "startsWith" check that works for different locales

0 commit comments

Comments
 (0)