I have the following code snippet:
// using classes from javax.mail.* // Session / Store setup code // Store implementation class = com.sun.mail.imap.IMAPStore Folder folder = store.getFolder("INBOX"); // store setup previously folder.open(Folder.READ_WRITE); Message[] messages = folder.getMessages(); Folder anotherFolder = store.getFolder("F1"); if ( !anotherFolder.exists()) { [***] anotherFolder.create(Folder.HOLDS_MESSAGES); } folder.copyMessages(messages, anotherFolder);
Sometimes I get the following exception:
javax.mail.StoreClosedException: failed to create new store connection at com.sun.mail.imap.IMAPFolder.throwClosedException(IMAPFolder.java:2208) at com.sun.mail.imap.IMAPFolder.doCommand(IMAPFolder.java:2335) at com.sun.mail.imap.IMAPFolder.exists(IMAPFolder.java:427) at [***]
I am not sure if this is the result of improper use of the JavaMail API or a server problem. I have two observations:
A crash occurs when it checks for the existence of a folder, and not when getFolder is called.
getFolder is called more than once in code.
I believe it is possible that the connection to the mail server dies from time to time with the name folder.getMessages (), but it ALWAYS fails when calling exist (), and not in calling create ().
One solution is to first call store.isConnected () and reconnect, but I want to find out if there is something that I am doing wrong before resorting to this.
I would appreciate any understanding or advice on how to get deeper into the source of this exception. Thanks in advance!
source share