Buggy code:
public class ConnectionState { private static final String TAG = "ConnectionState" ; private static final Pattern mSemicolonSplitPattern = Pattern . compile ( ";" ) ; private final AtomicInteger currentConnectionGeneration = new AtomicInteger ( 0 ) ; @ IntDef ( { ConnectionState . DISCONNECTED , ConnectionState . CONNECTION_STARTED , ConnectionState . CONNECTION_FAILED , ConnectionState . CONNECTION_COMPLETED , ConnectionState . LOGIN_STARTED , ConnectionState . LOGIN_FAILED , ConnectionState . LOGIN_COMPLETED } ) @ Retention ( RetentionPolicy . SOURCE ) public @ interface ConnectionStates { } public static final int DISCONNECTED = 0 ; public static final int CONNECTION_STARTED = 1 ; public static final int CONNECTION_FAILED = 2 ; public static final int CONNECTION_COMPLETED = 3 ; public static final int LOGIN_STARTED = 4 ; public static final int LOGIN_FAILED = 5 ; public static final int LOGIN_COMPLETED = 6 ; @ ConnectionState . ConnectionStates private volatile int mConnectionState = ConnectionState . DISCONNECTED ; private final AtomicBoolean mCanFavorites = new AtomicBoolean ( false ) ; private final AtomicBoolean mCanMusicfolder = new AtomicBoolean ( false ) ; private final AtomicBoolean mCanMyApps = new AtomicBoolean ( false ) ; private final AtomicBoolean canRandomplay = new AtomicBoolean ( false ) ; private final AtomicReference < String > preferredAlbumSort = new AtomicReference < String > ( "album" ) ; private final AtomicReference < Socket > socketRef = new AtomicReference < Socket > ( ) ; private final AtomicReference < PrintWriter > socketWriter = new AtomicReference < PrintWriter > ( ) ; private final AtomicReference < String > currentHost = new AtomicReference < String > ( ) ; private final AtomicReference < Integer > httpPort = new AtomicReference < Integer > ( ) ; private final AtomicReference < Integer > cliPort = new AtomicReference < Integer > ( ) ; private final AtomicReference < String > userName = new AtomicReference < String > ( ) ; private final AtomicReference < String > password = new AtomicReference < String > ( ) ; private final AtomicReference < String [ ] > mediaDirs = new AtomicReference < String [ ] > ( ) ; void disconnect ( EventBus eventBus , boolean loginFailed ) { } void setConnectionState ( @ NonNull EventBus eventBus , @ ConnectionState . ConnectionStates int connectionState ) { } PrintWriter getSocketWriter ( ) { } void setHttpPort ( Integer port ) { } public String [ ] getMediaDirs ( ) { } public void setMediaDirs ( String dirs ) { } void setCanFavorites ( boolean value ) { } boolean canFavorites ( ) { } void setCanMusicfolder ( boolean value ) { } boolean canMusicfolder ( ) { } void setCanMyApps ( boolean value ) { } boolean canMyApps ( ) { } void setCanRandomplay ( boolean value ) { } boolean canRandomplay ( ) { } public void setPreferedAlbumSort ( String value ) { } public String getPreferredAlbumSort ( ) { } boolean isConnected ( ) { } boolean isConnectInProgress ( ) { } void startListeningThread ( @ NonNull EventBus eventBus , @ NonNull Executor executor , CliClient cli ) { } private class ListeningThread extends Thread { @ NonNull private final EventBus mEventBus ; @ NonNull private final Executor mExecutor ; private final Socket socket ; private final CliClient cli ; private final int generationNumber ; private ListeningThread ( @ NonNull EventBus eventBus , @ NonNull Executor executor , CliClient cli , Socket socket , int generationNumber ) { } @ Override public void run ( ) { Log . d ( ConnectionState . TAG , "Listening<seq2seq4repair_space>thread<seq2seq4repair_space>started" ) ; BufferedReader in ; try { in = new BufferedReader ( new InputStreamReader ( socket . getInputStream ( ) ) , 128 ) ; } catch ( IOException e ) { Log . v ( ConnectionState . TAG , ( "IOException<seq2seq4repair_space>while<seq2seq4repair_space>creating<seq2seq4repair_space>BufferedReader:<seq2seq4repair_space>" + e ) ) ; cli . disconnect ( false ) ; return ; } IOException exception = null ; while ( true ) { String line ; try { line = in . readLine ( ) ; } catch ( IOException e ) { line = null ; exception = e ; } if ( line == null ) { if ( ( currentConnectionGeneration . get ( ) ) == ( generationNumber ) ) { Log . v ( ConnectionState . TAG , ( "Server<seq2seq4repair_space>disconnected;<seq2seq4repair_space>exception=" + exception ) ) ; <START_BUG> cli . disconnect ( false ) ; <END_BUG> } else { Log . v ( ConnectionState . TAG , "Old<seq2seq4repair_space>generation<seq2seq4repair_space>connection<seq2seq4repair_space>disconnected,<seq2seq4repair_space>as<seq2seq4repair_space>expected." ) ; } return ; } final String inputLine = line ; if ( ( ( mConnectionState ) == ( ConnectionState . LOGIN_STARTED ) ) && ( ! ( inputLine . startsWith ( "login<seq2seq4repair_space>" ) ) ) ) { setConnectionState ( mEventBus , ConnectionState . LOGIN_COMPLETED ) ; } mExecutor . execute ( new Runnable ( ) { @ Override public void run ( ) { cli . onLineReceived ( inputLine ) ; } } ) ; } } } void startConnect ( final SqueezeService service , @ NonNull final EventBus eventBus , @ NonNull final Executor executor , final CliClient cli , String hostPort , final String userName , final String password ) { } void onCliPortConnectionEstablished ( final EventBus eventBus , final CliClient cli , final String userName , final String password ) { } Integer getHttpPort ( ) { } String getUserName ( ) { } String getPassword ( ) { } String getCurrentHost ( ) { } }

Fix:
cli . disconnect ( ( exception == null ) ) ;