Occasionally, some of my test fail with an ArrayIndexOutOfBoundsException:
java.lang.ArrayIndexOutOfBoundsException: message number (6) out of bounds (5)
The test is rather simple: I create a Message and do 'Transport.send(message)' and then I try to verify if the mail can be found on the server with 'folder.search(searchTerm);'.
The folder is opened with 'folder.open(Folder.READ_ONLY);'.
I am using javax.mail:mail:1.4.5.
I would guess that the mailbox is being updated while the search is done.
This seems to be the same issue as in http://stackoverflow.com/questions/13082349/java-lang-arrayindexoutofboundsexceptionat-com-sun-mail-imap-messagecache-getme
Should I open a bug, or am I doing something wrong?
Are you using Exchange? If so, you may be running into the Exchange bug described here:
If that's the case, please open a bug with Microsoft and let me know if they have a fix.
If you're not using Exchange, a protocol trace would help to diagnose the problem.
No, it's not exchange, but apache-james-3.0-beta4.
However, james classes do not appear anywhere in the stacktrace - the lines in my last post were pretty complete (only my test classes and junit stuff missing).
I will give the debug trace, when I hit the bug the next time.
It's definitely a bug in the server. You can see it here:
You open the INBOX and it tells you there's 6 messages in the INBOX:
A3 EXAMINE INBOX
* FLAGS (\Answered \Deleted \Draft \Flagged \Seen)
* 6 EXISTS
Then you do a search and it matches message number 7!
A5 SEARCH SUBJECT "subject with random nr: 1359967923405 9" ALL
* SEARCH 7
There was also another search for the same message right before that, and it returned nothing.
Presumably the message just showed up in the INBOX between those two searches, which is
fine, but the IMAP protocol requires the server to notify the client of the new message before
it can return that message as the result of a search.
Please report the bug to the Apache James community.
I would need to read the IMAP spec carefully to determine if the untagged EXISTS response is allowed there, but yes, that's the general idea. The client needs to see the EXISTS response announcing the new message before any other responses reference that message.