9 Replies Latest reply: Feb 20, 2014 3:50 PM by Bill Shannon-Oracle RSS

    IMAPFolder.close bug ?

    Hamit Hasanhocaoglu

      Hi;

       

      According to source, IMAPFolder.close() method uses examine() command. If server returns a NO | BAD to this examine command, a protocol exception is thrown and in catch block, the protocol is being disconnected, after which is given back to IMAPStore connection pool in the finally block. If this closed protocol connection is reused by another operation, that command fails with "socket closed" and converted to SyntheticBye which causes all store connections to be cleaned up.

       

      Is this a bug ?

       

      // If the expunge flag is set or we're open read-only we
           // can just close the folder, otherwise open it read-only
           // before closing, or unselect it if supported.
                          if (!expunge && mode == READ_WRITE) {
                              try {
                               if (protocol != null &&
                                    protocol.hasCapability("UNSELECT"))
                                protocol.unselect();
                               else {
        if (protocol != null) {
           protocol.examine(fullName);  // ------------------------ if this examine fails
           if (protocol != null) // XXX - unnecessary?
        protocol.close();
        }
           }
                              } catch (ProtocolException pex2) { 
                                  if (protocol != null) /// ---------------------- here is the disconnect, causes the protocol object to be invalid
        protocol.disconnect();
                              }
                          } else {
        if (protocol != null)
           protocol.close();
           }
                      }
           } catch (ProtocolException pex) {
        throw new MessagingException(pex.getMessage(), pex);
           } finally {
        // cleanup if we haven't already
        if (opened)
           cleanup(true); /// -------------------------------- here invalid protocol is given back to IMAPStore in releaseProtocol()
           }