Skip to content

Commit 44684a2

Browse files
mjd507spring-builds
authored andcommitted
GH-10100: Fix NPE in AbstractMailReceiver.obtainFolderInstance()
Fixes: #10083 Issue link: #10100 if `url` is not provided, use `store.getDefaultFolder()` instead. Signed-off-by: Jiandong Ma <[email protected]> (cherry picked from commit cbb0c6f)
1 parent c19c0f0 commit 44684a2

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

spring-integration-mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2024 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@
6969
* @author Yuxin Wang
7070
* @author Ngoc Nhan
7171
* @author Filip Hrisafov
72+
* @author Jiandong Ma
7273
*/
7374
public abstract class AbstractMailReceiver extends IntegrationObjectSupport implements MailReceiver, DisposableBean {
7475

@@ -370,6 +371,9 @@ protected void openFolder() throws MessagingException {
370371
}
371372

372373
private Folder obtainFolderInstance() throws MessagingException {
374+
if (this.url == null) {
375+
return this.store.getDefaultFolder();
376+
}
373377
return this.store.getFolder(this.url);
374378
}
375379

spring-integration-mail/src/test/java/org/springframework/integration/mail/MailReceiverTests.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2014-2022 the original author or authors.
2+
* Copyright 2014-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,7 +22,6 @@
2222
import jakarta.mail.Message;
2323
import jakarta.mail.Session;
2424
import jakarta.mail.Store;
25-
import jakarta.mail.URLName;
2625
import org.junit.jupiter.api.Test;
2726

2827
import org.springframework.beans.DirectFieldAccessor;
@@ -68,7 +67,7 @@ protected Message[] searchForNewMessages() {
6867
Folder folder = mock(Folder.class);
6968
when(folder.exists()).thenReturn(true);
7069
when(folder.isOpen()).thenReturn(false, true);
71-
doReturn(folder).when(store).getFolder((URLName) null);
70+
doReturn(folder).when(store).getDefaultFolder();
7271
doNothing().when(store).connect();
7372
receiver.openFolder();
7473
receiver.openFolder();

0 commit comments

Comments
 (0)