2 Replies Latest reply on Sep 11, 2017 9:26 AM by Flow

    ReconnectionManager.reconnect() can throw NotConnectedException

    Jennifer Kitson

      If you disable automatic reconnection while Smack is already attempting to reconnect, it can cause the reconnect runnable to hit a NotConnectedException. This happens in the following code:

      if (isReconnectionPossible(connection)) {
         try {
        } catch (SmackException.AlreadyConnectedException e) {
        LOGGER.log(Level.FINER, "Connection was already connected on reconnection attempt", e);
         // TODO Starting with Smack 4.2, connect() will no
        // longer login automatically. So change this and the
        // previous lines to connection.connect().login() in the
        // 4.2, or any later, branch.
         if (!connection.isAuthenticated()) {
         // Successfully reconnected.
         attempts = 0;

      isReconnectionPossible(connection) returns false because automatic reconnection is disabled, so connect() is not called. But then connection.login() is called on the unconnected connection, causing the exception.


      I think that if automatic reconnection is disabled Smack shouldn't try to connect or log in during the reconnect code.


      The full stack trace is:

      09-07 11:29:44.914 29325-29449/<app_name> D/SMACK: Reconnection failed due to an exception (XMPPTCPConnection[<user@domain>] (0))

                                                                     org.jivesoftware.smack.SmackException$NotConnectedException: Client is not, or no longer, connected. Did you call connect() before login()?

                                                                         at org.jivesoftware.smack.AbstractXMPPConnection.throwNotConnectedExceptionIfAppro priate(AbstractXMPPConnection.java:643)

                                                                         at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java :486)

                                                                         at org.jivesoftware.smack.AbstractXMPPConnection.login(AbstractXMPPConnection.java :448)

                                                                         at org.jivesoftware.smack.ReconnectionManager$2.run(ReconnectionManager.java:254)

                                                                         at java.lang.Thread.run(Thread.java:761)