powered by Jive Software

An exception is thrown when suddenly disconnecting


I’m developing a XMPP client which connects to a XMPP server.

I’m using smack 3.2.1 and Maven.

When the server suddenly disconnects, an exception is thrown and you can not catch it.

What causes this is the line:


which prints the exception to the console, in the class “PacketReader” in this method:

void notifyConnectionError(Exception e) {

    done =** true**;

    // Closes the connection temporary. A reconnection is possible

    connection.shutdown(**new** Presence(Presence.Type.*unavailable*));

    // Print the stack trace to help catch the problem

** **e.printStackTrace();

    // Notify connection listeners of the error.

   ** for** (ConnectionListener listener : connection.getConnectionListeners()) {

       ** try** {



       ** catch** (Exception e2) {

            // Catch and print any exception so we can recover

            // from a faulty listener





The exception is:

java.net.SocketException: Connection reset

at java.net.SocketInputStream.read(SocketInputStream.java:168)

at com.sun.net.ssl.internal.ssl.InputRecord.readFully(InputRecord.java:293)

at com.sun.net.ssl.internal.ssl.InputRecord.read(InputRecord.java:331)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:798)

at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:755)

at com.sun.net.ssl.internal.ssl.AppInputStream.read(AppInputStream.java:75)

at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264)

at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306)

at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158)

at java.io.InputStreamReader.read(InputStreamReader.java:167)

at java.io.BufferedReader.fill(BufferedReader.java:136)

at java.io.BufferedReader.read1(BufferedReader.java:187)

at java.io.BufferedReader.read(BufferedReader.java:261)

at org.jivesoftware.smack.util.ObservableReader.read(ObservableReader.java:42)

at org.xmlpull.mxp1.MXParser.fillBuf(MXParser.java:2992)

at org.xmlpull.mxp1.MXParser.more(MXParser.java:3046)

at org.xmlpull.mxp1.MXParser.nextImpl(MXParser.java:1144)

at org.xmlpull.mxp1.MXParser.next(MXParser.java:1093)

at org.jivesoftware.smack.PacketReader.parsePackets(PacketReader.java:325)

at org.jivesoftware.smack.PacketReader.access$000(PacketReader.java:43)

at org.jivesoftware.smack.PacketReader$1.run(PacketReader.java:70)

How can I resolve the problem?

Hi there,

This is all part of the socket exception handling and is used to notify the conection and also the reconnectionManager (if allowed) that an exception has occured on Read (or write in packetWriter)

One great thing to do to understand this would be to see where notifyConnectionError is called from.

As you say it’s called from PacketReader (I have smack 3.3.0 at the moment accessible to me, could be different in 3.2.1)

So when there is an exception on packet read or write, it is caught in those classes and passes to Connection.notifyConnectionError() which shutsdown the connection and let’s the listeners know about the particular error… and if reconnection is allowed an attempt will be made.

Make sense?

So this exception is caught already in PacketReader.parsePackets() it’s just passed to other methods to let other classes know there’s been an unexpected disconnect.

From PacketReader.parsePackets()

} catch (Exception e) {

// The exception can be ignored if the the connection is ‘done’

// or if the it was caused because the socket got closed

if (!(done || connection.isSocketClosed())) {

// Close the connection and notify connection listeners of the

// error.