This discussion is archived
7 Replies Latest reply: Jul 31, 2013 12:01 PM by bshannon RSS

ArrayIndexOutOfBoundsException when searching in ImapFolder

986597 Newbie
Currently Being Moderated
Hi,

Occasionally, some of my test fail with an ArrayIndexOutOfBoundsException:

java.lang.ArrayIndexOutOfBoundsException: message number (6) out of bounds (5)
     at com.sun.mail.imap.MessageCache.getMessage(MessageCache.java:132)
     at com.sun.mail.imap.MessageCache.getMessageBySeqnum(MessageCache.java:162)
     at com.sun.mail.imap.IMAPFolder.getMessageBySeqNumber(IMAPFolder.java:2809)
     at com.sun.mail.imap.IMAPFolder.search(IMAPFolder.java:1662)

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?

TIA, Heinz-Dieter
  • 1. Re: ArrayIndexOutOfBoundsException when searching in ImapFolder
    bshannon Pro
    Currently Being Moderated
    Are you using Exchange? If so, you may be running into the Exchange bug described here:
    http://kenai.com/projects/javamail/pages/Exchange

    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.
    http://www.oracle.com/technetwork/java/javamail/faq/index.html#debug
  • 2. Re: ArrayIndexOutOfBoundsException when searching in ImapFolder
    986597 Newbie
    Currently Being Moderated
    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.

    Thanks
  • 3. Re: ArrayIndexOutOfBoundsException when searching in ImapFolder
    986597 Newbie
    Currently Being Moderated
    Sorry for the delay.

    I would have attached a file, but could not figure out how to do that.
    The content of the surefire report incuding DEBUG output from the mail server is thus simply appended.

    Thank, Heinz-Dieter

    ------------------------------------------

    <?xml version="1.0" encoding="UTF-8" ?>
    <testsuite failures="0" time="4.702" errors="2" skipped="0" tests="6" name="com.icw.cdm.messaging.service.MessageServiceTest">
    <properties>
    <property name="java.runtime.name" value="Java(TM) SE Runtime Environment"/>
    <property name="sun.boot.library.path" value="/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/i386"/>
    <property name="java.vm.version" value="20.10-b01"/>
    <property name="java.vm.vendor" value="Sun Microsystems Inc."/>
    <property name="java.vendor.url" value="http://java.sun.com/"/>
    <property name="path.separator" value=":"/>
    <property name="guice.disable.misplaced.annotation.check" value="true"/>
    <property name="java.vm.name" value="Java HotSpot(TM) Server VM"/>
    <property name="file.encoding.pkg" value="sun.io"/>
    <property name="user.country" value="DE"/>
    <property name="sun.java.launcher" value="SUN_STANDARD"/>
    <property name="sun.os.patch.level" value="unknown"/>
    <property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
    <property name="user.dir" value="/home/conradi/dev/cm/trunk/cm/components/cdm-messaging"/>
    <property name="java.runtime.version" value="1.6.0_35-b10"/>
    <property name="java.awt.graphicsenv" value="sun.awt.X11GraphicsEnvironment"/>
    <property name="java.endorsed.dirs" value="/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/endorsed"/>
    <property name="os.arch" value="i386"/>
    <property name="java.io.tmpdir" value="/tmp"/>
    <property name="line.separator" value="
    "/>
    <property name="java.vm.specification.vendor" value="Sun Microsystems Inc."/>
    <property name="os.name" value="Linux"/>
    <property name="classworlds.conf" value="/usr/local/java/extensions/apache-maven-3.0.4/bin/m2.conf"/>
    <property name="sun.jnu.encoding" value="UTF-8"/>
    <property name="java.library.path" value="/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/i386/server:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/i386:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/../lib/i386:/usr/java/packages/lib/i386:/lib:/usr/lib"/>
    <property name="javax.net.ssl.trustStore" value="/home/conradi/.m2/maven.jks"/>
    <property name="java.specification.name" value="Java Platform API Specification"/>
    <property name="java.class.version" value="50.0"/>
    <property name="sun.management.compiler" value="HotSpot Tiered Compilers"/>
    <property name="maven.repo.local" value="/home/conradi/dev/cm/trunk/.m2/repository"/>
    <property name="os.version" value="2.6.37.6-24-desktop"/>
    <property name="user.home" value="/home/conradi"/>
    <property name="user.timezone" value="Europe/Berlin"/>
    <property name="java.awt.printerjob" value="sun.print.PSPrinterJob"/>
    <property name="java.specification.version" value="1.6"/>
    <property name="file.encoding" value="UTF-8"/>
    <property name="user.name" value="conradi"/>
    <property name="java.class.path" value="/usr/local/java/extensions/apache-maven-3.0.4/boot/plexus-classworlds-2.4.jar"/>
    <property name="java.vm.specification.version" value="1.0"/>
    <property name="sun.arch.data.model" value="32"/>
    <property name="java.home" value="/usr/local/java/sdk/jdk1.6.0_35-32bit/jre"/>
    <property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher --settings /home/conradi/dev/cm/trunk/settings.xml -Dmaven.repo.local=/home/conradi/dev/cm/trunk/.m2/repository clean install"/>
    <property name="java.specification.vendor" value="Sun Microsystems Inc."/>
    <property name="user.language" value="de"/>
    <property name="java.vm.info" value="mixed mode"/>
    <property name="java.version" value="1.6.0_35"/>
    <property name="java.ext.dirs" value="/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/ext:/usr/java/packages/lib/ext"/>
    <property name="securerandom.source" value="file:/dev/./urandom"/>
    <property name="sun.boot.class.path" value="/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/resources.jar:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/rt.jar:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/sunrsasign.jar:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/jsse.jar:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/jce.jar:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/charsets.jar:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/lib/modules/jdk.boot.jar:/usr/local/java/sdk/jdk1.6.0_35-32bit/jre/classes"/>
    <property name="java.vendor" value="Sun Microsystems Inc."/>
    <property name="maven.home" value="/usr/local/java/extensions/apache-maven-3.0.4"/>
    <property name="file.separator" value="/"/>
    <property name="java.vendor.url.bug" value="http://java.sun.com/cgi-bin/bugreport.cgi"/>
    <property name="sun.cpu.endian" value="little"/>
    <property name="sun.io.unicode.encoding" value="UnicodeLittle"/>
    <property name="javax.net.ssl.trustStorePassword" value="icwmaven"/>
    <property name="sun.cpu.isalist" value=""/>
    </properties>
    <testcase time="1.565" classname="com.icw.cdm.messaging.service.MessageServiceTest" name="testSend"/>
    <testcase time="0.466" classname="com.icw.cdm.messaging.service.MessageServiceTest" name="testSentFolder"/>
    <testcase time="0.808" classname="com.icw.cdm.messaging.service.MessageServiceTest" name="testSendMultipleUsers"/>
    <testcase time="0.487" classname="com.icw.cdm.messaging.service.MessageServiceTest" name="testSendToCmUser">
    <error message="message number (7) out of bounds (6)" type="java.lang.ArrayIndexOutOfBoundsException">java.lang.ArrayIndexOutOfBoundsException: message number (7) out of bounds (6)
         at com.sun.mail.imap.MessageCache.getMessage(MessageCache.java:135)
         at com.sun.mail.imap.MessageCache.getMessageBySeqnum(MessageCache.java:164)
         at com.sun.mail.imap.IMAPFolder.getMessageBySeqNumber(IMAPFolder.java:3005)
         at com.sun.mail.imap.IMAPFolder.search(IMAPFolder.java:1863)
         at com.icw.cdm.messaging.service.MessageServiceTest.retrieveMessages(MessageServiceTest.java:334)
         at com.icw.cdm.messaging.service.MessageServiceTest.retrieveMessages(MessageServiceTest.java:327)
         at com.icw.cdm.messaging.service.MessageServiceTest.testSendToCmUser(MessageServiceTest.java:190)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
         at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
         at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
         at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
         at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
         at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
         at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
         at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
         at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
         at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
         at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
    </error>
    <system-out>DEBUG: JavaMail version 1.4.6-rc1
    DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
    DEBUG: Tables of loaded providers
    DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
    DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: JavaMail version 1.4.6-rc1
    DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
    DEBUG: Tables of loaded providers
    DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
    DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
    DEBUG IMAP: mail.imap.fetchsize: 16384
    DEBUG IMAP: mail.imap.ignorebodystructuresize: false
    DEBUG IMAP: mail.imap.statuscachetimeout: 1000
    DEBUG IMAP: mail.imap.appendbuffersize: -1
    DEBUG IMAP: mail.imap.minidletime: 10
    DEBUG IMAP: trying to connect to host &quot;localhost&quot;, port 15143, isSSL false
    * OK JAMES IMAP4rev1 Server Server wdf-dex-0003 is ready.
    A0 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A0 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    DEBUG IMAP: protocolConnect login, host=localhost, user=all_mails@localhost.test, password=&lt;non-null&gt;
    DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
    DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK AUTHENTICATE completed.
    A2 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A2 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    DEBUG IMAP: connection available -- size: 1
    A3 EXAMINE INBOX
    * FLAGS (\Answered \Deleted \Draft \Flagged \Seen)
    * 6 EXISTS
    * 6 RECENT
    * OK [UIDVALIDITY 1299388474] UIDs valid
    * OK [UNSEEN 2] Message 2 is first unseen
    * OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen \*)] Limited
    * OK [HIGHESTMODSEQ 6] Highest
    * OK [UIDNEXT 7] Predicted next UID
    A3 OK [READ-ONLY] EXAMINE completed.
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: trying to connect to host &quot;localhost&quot;, port 15025, isSSL false
    220 wdf-dex-0003 JAMES SMTP Server Server (JAMES SMTP Server ) ready
    DEBUG SMTP: connected to host &quot;localhost&quot;, port: 15025

    EHLO wdf-dex-0003.icw.int
    250-wdf-dex-0003 Hello wdf-dex-0003.icw.int [127.0.0.1])
    250-PIPELINING
    250-ENHANCEDSTATUSCODES
    250 8BITMIME
    DEBUG SMTP: Found extension &quot;PIPELINING&quot;, arg &quot;&quot;
    DEBUG SMTP: Found extension &quot;ENHANCEDSTATUSCODES&quot;, arg &quot;&quot;
    DEBUG SMTP: Found extension &quot;8BITMIME&quot;, arg &quot;&quot;
    DEBUG SMTP: use8bit false
    MAIL FROM:&lt;testSendToCmUser@icw.cm.test&gt;
    250 2.1.0 Sender &lt;testSendToCmUser@icw.cm.test&gt; OK
    RCPT TO:&lt;user1@cm.test&gt;
    250 2.1.5 Recipient &lt;user1@cm.test&gt; OK
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP: user1@cm.test
    DATA
    354 Ok Send data ending with &lt;CRLF&gt;.&lt;CRLF&gt;
    Date: Mon, 4 Feb 2013 09:52:03 +0100 (CET)
    From: testSendToCmUser@icw.cm.test
    To: user1@cm.test
    Message-ID: &lt;4047035.3.1359967923407.JavaMail.conradi@wdf-dex-0003&gt;
    Subject: subject with random nr: 1359967923405 9
    MIME-Version: 1.0
    Content-Type: text/txt; charset=UTF-8
    Content-Transfer-Encoding: 7bit

    this is a to a specific user message
    .
    250 2.6.0 Message received
    QUIT
    221 2.0.0 wdf-dex-0003 Service closing transmission channel
    DEBUG IMAP: no connections in the pool, creating a new one
    * OK JAMES IMAP4rev1 Server Server wdf-dex-0003 is ready.
    A0 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A0 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
    DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK AUTHENTICATE completed.
    A2 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A2 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    A3 EXAMINE INBOX
    * FLAGS (\Answered \Deleted \Draft \Flagged \Seen)
    * 6 EXISTS
    * 6 RECENT
    * OK [UIDVALIDITY 1299388474] UIDs valid
    * OK [UNSEEN 2] Message 2 is first unseen
    * OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen \*)] Limited
    * OK [HIGHESTMODSEQ 6] Highest
    * OK [UIDNEXT 7] Predicted next UID
    A3 OK [READ-ONLY] EXAMINE completed.
    A4 SEARCH SUBJECT &quot;subject with random nr: 1359967923405 9&quot; ALL
    * SEARCH
    A4 OK SEARCH completed.
    A5 SEARCH SUBJECT &quot;subject with random nr: 1359967923405 9&quot; ALL
    * SEARCH 7
    A5 OK SEARCH completed.
    A6 CLOSE
    A6 OK CLOSE completed.
    DEBUG IMAP: added an Authenticated connection -- size: 1
    A7 LOGOUT
    * BYE IMAP4rev1 Server logging out
    A7 OK LOGOUT completed.
    DEBUG IMAP: IMAPStore connection dead
    DEBUG IMAP: IMAPStore cleanup, force false
    DEBUG IMAP: close folder
    A4 CLOSE
    A4 OK CLOSE completed.
    DEBUG IMAP: added an Authenticated connection -- size: 1
    A5 LOGOUT
    * BYE IMAP4rev1 Server logging out
    A5 OK LOGOUT completed.
    DEBUG IMAP: IMAPStore cleanup done
    </system-out>
    </testcase>
    <testcase time="0.497" classname="com.icw.cdm.messaging.service.MessageServiceTest" name="testSendWithXHeader">
    <error message="message number (8) out of bounds (7)" type="java.lang.ArrayIndexOutOfBoundsException">java.lang.ArrayIndexOutOfBoundsException: message number (8) out of bounds (7)
         at com.sun.mail.imap.MessageCache.getMessage(MessageCache.java:135)
         at com.sun.mail.imap.MessageCache.getMessageBySeqnum(MessageCache.java:164)
         at com.sun.mail.imap.IMAPFolder.getMessageBySeqNumber(IMAPFolder.java:3005)
         at com.sun.mail.imap.IMAPFolder.search(IMAPFolder.java:1863)
         at com.icw.cdm.messaging.service.MessageServiceTest.retrieveMessages(MessageServiceTest.java:334)
         at com.icw.cdm.messaging.service.MessageServiceTest.retrieveMessages(MessageServiceTest.java:327)
         at com.icw.cdm.messaging.service.MessageServiceTest.testSendWithXHeader(MessageServiceTest.java:219)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
         at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
         at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
         at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
         at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
         at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
         at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
         at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
         at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
         at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
         at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
         at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
         at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
         at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
         at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
         at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
         at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
         at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
         at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
         at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
         at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)
    </error>
    <system-out>DEBUG: JavaMail version 1.4.6-rc1
    DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
    DEBUG: Tables of loaded providers
    DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
    DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: JavaMail version 1.4.6-rc1
    DEBUG: successfully loaded resource: /META-INF/javamail.default.providers
    DEBUG: Tables of loaded providers
    DEBUG: Providers Listed By Class Name: {com.sun.mail.smtp.SMTPSSLTransport=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], com.sun.mail.smtp.SMTPTransport=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle], com.sun.mail.imap.IMAPSSLStore=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], com.sun.mail.pop3.POP3SSLStore=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], com.sun.mail.imap.IMAPStore=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], com.sun.mail.pop3.POP3Store=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle]}
    DEBUG: Providers Listed By Protocol: {imaps=javax.mail.Provider[STORE,imaps,com.sun.mail.imap.IMAPSSLStore,Oracle], imap=javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle], smtps=javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle], pop3=javax.mail.Provider[STORE,pop3,com.sun.mail.pop3.POP3Store,Oracle], pop3s=javax.mail.Provider[STORE,pop3s,com.sun.mail.pop3.POP3SSLStore,Oracle], smtp=javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]}
    DEBUG: successfully loaded resource: /META-INF/javamail.default.address.map
    DEBUG: getProvider() returning javax.mail.Provider[STORE,imap,com.sun.mail.imap.IMAPStore,Oracle]
    DEBUG IMAP: mail.imap.fetchsize: 16384
    DEBUG IMAP: mail.imap.ignorebodystructuresize: false
    DEBUG IMAP: mail.imap.statuscachetimeout: 1000
    DEBUG IMAP: mail.imap.appendbuffersize: -1
    DEBUG IMAP: mail.imap.minidletime: 10
    DEBUG IMAP: trying to connect to host &quot;localhost&quot;, port 15143, isSSL false
    * OK JAMES IMAP4rev1 Server Server wdf-dex-0003 is ready.
    A0 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A0 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    DEBUG IMAP: protocolConnect login, host=localhost, user=all_mails@localhost.test, password=&lt;non-null&gt;
    DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
    DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK AUTHENTICATE completed.
    A2 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A2 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    DEBUG IMAP: connection available -- size: 1
    A3 EXAMINE INBOX
    * FLAGS (\Answered \Deleted \Draft \Flagged \Seen)
    * 7 EXISTS
    * 7 RECENT
    * OK [UIDVALIDITY 1299388474] UIDs valid
    * OK [UNSEEN 2] Message 2 is first unseen
    * OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen \*)] Limited
    * OK [HIGHESTMODSEQ 7] Highest
    * OK [UIDNEXT 8] Predicted next UID
    A3 OK [READ-ONLY] EXAMINE completed.
    DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: useEhlo true, useAuth true
    DEBUG SMTP: trying to connect to host &quot;localhost&quot;, port 15025, isSSL false
    220 wdf-dex-0003 JAMES SMTP Server Server (JAMES SMTP Server ) ready
    DEBUG SMTP: connected to host &quot;localhost&quot;, port: 15025

    EHLO wdf-dex-0003.icw.int
    250-wdf-dex-0003 Hello wdf-dex-0003.icw.int [127.0.0.1])
    250-PIPELINING
    250-ENHANCEDSTATUSCODES
    250 8BITMIME
    DEBUG SMTP: Found extension &quot;PIPELINING&quot;, arg &quot;&quot;
    DEBUG SMTP: Found extension &quot;ENHANCEDSTATUSCODES&quot;, arg &quot;&quot;
    DEBUG SMTP: Found extension &quot;8BITMIME&quot;, arg &quot;&quot;
    DEBUG SMTP: use8bit false
    MAIL FROM:&lt;testSendWithXHeader@icw.cm.test&gt;
    250 2.1.0 Sender &lt;testSendWithXHeader@icw.cm.test&gt; OK
    RCPT TO:&lt;all_mails@localhost.test&gt;
    250 2.1.5 Recipient &lt;all_mails@localhost.test&gt; OK
    DEBUG SMTP: Verified Addresses
    DEBUG SMTP: all_mails@localhost.test
    DATA
    354 Ok Send data ending with &lt;CRLF&gt;.&lt;CRLF&gt;
    Date: Mon, 4 Feb 2013 09:52:03 +0100 (CET)
    From: testSendWithXHeader@icw.cm.test
    To: all_mails@localhost.test
    Message-ID: &lt;849515.4.1359967923901.JavaMail.conradi@wdf-dex-0003&gt;
    Subject: subject with random nr: 1359967923896 20
    MIME-Version: 1.0
    Content-Type: text/txt; charset=UTF-8
    Content-Transfer-Encoding: 7bit
    X-ICW-CM-PATIENT-ID: 4711

    this is a message with special X-Header
    .
    250 2.6.0 Message received
    QUIT
    221 2.0.0 wdf-dex-0003 Service closing transmission channel
    DEBUG IMAP: no connections in the pool, creating a new one
    * OK JAMES IMAP4rev1 Server Server wdf-dex-0003 is ready.
    A0 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A0 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    DEBUG IMAP: AUTHENTICATE PLAIN command trace suppressed
    DEBUG IMAP: AUTHENTICATE PLAIN command result: A1 OK AUTHENTICATE completed.
    A2 CAPABILITY
    * CAPABILITY SASL-IR IDLE LITERAL+ AUTH=PLAIN CONDSTORE ESEARCH CHILDREN UIDPLUS UNSELECT WITHIN ENABLE I18NLEVEL=1 SEARCHRES IMAP4rev1 NAMESPACE QRESYNC
    A2 OK CAPABILITY completed.
    DEBUG IMAP: AUTH: PLAIN
    A3 EXAMINE INBOX
    * FLAGS (\Answered \Deleted \Draft \Flagged \Seen)
    * 7 EXISTS
    * 7 RECENT
    * OK [UIDVALIDITY 1299388474] UIDs valid
    * OK [UNSEEN 2] Message 2 is first unseen
    * OK [PERMANENTFLAGS (\Answered \Deleted \Draft \Flagged \Seen \*)] Limited
    * OK [HIGHESTMODSEQ 7] Highest
    * OK [UIDNEXT 8] Predicted next UID
    A3 OK [READ-ONLY] EXAMINE completed.
    A4 SEARCH SUBJECT &quot;subject with random nr: 1359967923896 20&quot; ALL
    * SEARCH
    A4 OK SEARCH completed.
    A5 SEARCH SUBJECT &quot;subject with random nr: 1359967923896 20&quot; ALL
    * SEARCH 8
    A5 OK SEARCH completed.
    A6 CLOSE
    A6 OK CLOSE completed.
    DEBUG IMAP: added an Authenticated connection -- size: 1
    A7 LOGOUT
    * BYE IMAP4rev1 Server logging out
    A7 OK LOGOUT completed.
    DEBUG IMAP: IMAPStore connection dead
    DEBUG IMAP: IMAPStore cleanup, force false
    DEBUG IMAP: close folder
    A4 CLOSE
    A4 OK CLOSE completed.
    DEBUG IMAP: added an Authenticated connection -- size: 1
    A5 LOGOUT
    * BYE IMAP4rev1 Server logging out
    A5 OK LOGOUT completed.
    DEBUG IMAP: IMAPStore cleanup done
    </system-out>
    </testcase>
    <testcase time="0.879" classname="com.icw.cdm.messaging.service.MessageServiceTest" name="testSendRemoteMail"/>
    </testsuite>
  • 4. Re: ArrayIndexOutOfBoundsException when searching in ImapFolder
    bshannon Pro
    Currently Being Moderated
    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.
  • 5. Re: ArrayIndexOutOfBoundsException when searching in ImapFolder
    986597 Newbie
    Currently Being Moderated
    Please report the bug to the Apache James community.
    I will do that.

    Thanks again.
  • 6. Re: ArrayIndexOutOfBoundsException when searching in ImapFolder
    user2375912 Newbie
    Currently Being Moderated

    Do you mean the server should have send the following reply to the search instead:

     

    A5 SEARCH SUBJECT "subject with random nr: 1359967923405 9" ALL

    * EXISTS 7

    * SEARCH 7

     

    So the imap client would then first be aware of the existence of the message #7 ?

  • 7. Re: ArrayIndexOutOfBoundsException when searching in ImapFolder
    bshannon Pro
    Currently Being Moderated

    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.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points