powered by Jive Software

Synchronization issue in XMPPConnection

I found a synchronization issue in Smack’'s XMPPConnection class. When I try to login with a wrong username/password SASL authentication fails and the stream is closed by the server. This causes the PacketReader class to call disconnect. Since disconnect is not synchronized a NullPointerException can be thrown, when I call disconnect at the same time.

Some code to demonstrate the problem on the gtalk network:

import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.XMPPException; public class GTalk {      public static final String user = "abcde";
     public static final String pass = "fghij";      public static void main(String[] args) throws InterruptedException {
          XMPPConnection con = null;
          try {
               XMPPConnection.DEBUG_ENABLED = true;
               ConnectionConfiguration configuration = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
               con = new XMPPConnection(configuration);
               con.login(user, pass);
          } catch (XMPPException e) {
          } finally {
               if (con != null) {

And the output:

SASL authentication failed:      at org.jivesoftware.smack.SASLAuthentication.authenticate(SASLAuthentication.java:209)
     at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:341)
     at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:301)
     at org.jivesoftware.smack.XMPPConnection.login(XMPPConnection.java:283)
     at GTalk.main(GTalk.java:17)
Exception in thread "main" java.lang.NullPointerException
     at org.jivesoftware.smack.XMPPConnection.disconnect(XMPPConnection.java:652)
     at org.jivesoftware.smack.XMPPConnection.disconnect(XMPPConnection.java:618)
     at GTalk.main(GTalk.java:22)



Thanks for the bug report!

I have filed an issue: