Buggy code:
public AppLauncher env ( Map < String , String > env ) { } public AppLauncher debug ( boolean debug ) { } public AppLauncher forward ( int localPort ) { } public AppLauncher appLauncherCallback ( AppLauncherCallback callback ) { } public AppLauncher xcodePath ( String xcodePath ) { } public AppLauncher launchOnLockedRetries ( int launchOnLockedRetries ) { } public AppLauncher secondsBetweenLaunchOnLockedRetries ( int secondsBetweenLaunchOnLockedRetries ) { } public void kill ( ) { } private static String toHex ( String s ) { } private static byte fromHex ( char c1 , char c2 ) { } private static byte [ ] fromHex ( String s ) { } private static byte [ ] fromHex ( byte [ ] buffer , int offset , int length ) { } private String encode ( String cmd ) { } private String decode ( String packet ) { } private void debugGdb ( String s ) { } protected void log ( String s , Object ... args ) { } private void sendGdbPacket ( IDeviceConnection conn , String packet ) throws IOException { } private String receiveGdbPacket ( IDeviceConnection conn ) throws IOException , TimeoutException { } private String receiveGdbPacket ( IDeviceConnection conn , long timeout ) throws IOException , TimeoutException { } private boolean receiveGdbAck ( IDeviceConnection conn ) throws IOException { } private void sendReceivePacket ( IDeviceConnection conn , String packet , String expectedResponse , boolean ackMode ) throws IOException , TimeoutException { } private void kill ( IDeviceConnection conn ) throws IOException , TimeoutException { } private String encodeArgs ( String appPath ) { } private String getAppPath ( LockdowndClient lockdowndClient , String appId ) throws IOException { } public void install ( ) throws IOException { } private File getXcodePath ( ) throws Exception { } static File findDeveloperImage ( File dsDir , String productVersion , String buildVersion ) throws FileNotFoundException { } private static String [ ] getProductVersionParts ( String productVersion ) { } private void mountDeveloperImage ( LockdowndClient lockdowndClient ) throws Exception { } private int launchInternal ( ) throws Exception { } private int pipeStdOut ( IDeviceConnection conn , String appPath ) throws Exception { log ( "App<seq2seq4repair_space>Path:<seq2seq4repair_space>%s" , appPath ) ; sendGdbPacket ( conn , "+" ) ; sendReceivePacket ( conn , encode ( "QStartNoAckMode" ) , "OK" , true ) ; sendGdbPacket ( conn , "+" ) ; sendReceivePacket ( conn , encode ( "QEnvironment:NSUnbufferedIO=YES" ) , "OK" , false ) ; for ( Map . Entry < String , String > entry : env . entrySet ( ) ) { String cmd = String . format ( "QEnvironment:%s=%s" , entry . getKey ( ) , entry . getValue ( ) ) ; sendReceivePacket ( conn , encode ( cmd ) , "OK" , false ) ; } sendReceivePacket ( conn , encode ( "QListThreadsInStopReply" ) , "OK" , false ) ; sendReceivePacket ( conn , encode ( ( "A" + ( encodeArgs ( appPath ) ) ) ) , "OK" , false ) ; sendReceivePacket ( conn , encode ( "qLaunchSuccess" ) , "OK" , false ) ; sendGdbPacket ( conn , encode ( "c" ) ) ; boolean wasInterrupted = false ; try { StringBuilder messages = new StringBuilder ( ) ; while ( true ) { try { String response = receiveGdbPacket ( conn ) ; String payload = decode ( response ) ; if ( ( payload . charAt ( 0 ) ) == 'W' ) { int exitCode = Integer . parseInt ( payload . substring ( 1 ) , 16 ) ; return exitCode ; } else if ( ( payload . charAt ( 0 ) ) == 'O' ) { byte [ ] msg = AppLauncher . fromHex ( payload . substring ( 1 ) ) ; if ( ( appLauncherCallback ) != null ) { try { String str = new String ( msg , "UTF-8" ) ; messages . append ( str ) ; String [ ] lines = messages . toString ( ) . split ( "\n" ) ; for ( String line : lines ) { if ( line . startsWith ( "[DEBUG]<seq2seq4repair_space>hooks:<seq2seq4repair_space>debugPort=" ) ) { <START_BUG> if ( line == ( lines [ ( ( lines . length ) - 1 ) ] ) ) <END_BUG> break ; int debugPort = Integer . parseInt ( line . substring ( "[DEBUG]<seq2seq4repair_space>hooks:<seq2seq4repair_space>debugPort=" . length ( ) ) . trim ( ) ) ; appLauncherCallback . setDebugPort ( debugPort ) ; appLauncherCallback = null ; } } } catch ( Throwable t ) { } } stdout . write ( msg ) ; } else if ( ( payload . charAt ( 0 ) ) == 'T' ) { String signal = payload . substring ( 1 , 3 ) ; String data = payload . substring ( 3 ) ; String threadId = data . replaceAll ( ".*thread:([0-9a-fA-F]+).*" , "$1" ) ; String allThreadIds = data . replaceAll ( ".*threads:([0-9a-fA-F,]+).*" , "$1" ) ; Set < String > ids = new TreeSet < > ( Arrays . asList ( allThreadIds . split ( "," ) ) ) ; ids . remove ( threadId ) ; StringBuilder sb = new StringBuilder ( "vCont;" ) ; for ( String id : ids ) { sb . append ( "c:" ) . append ( id ) . append ( ';' ) ; } sb . append ( 'C' ) . append ( signal ) . append ( ':' ) . append ( threadId ) ; sendGdbPacket ( conn , encode ( sb . toString ( ) ) ) ; } else if ( ( payload . charAt ( 0 ) ) == 'X' ) { int signal = Integer . parseInt ( payload . substring ( 1 , 3 ) , 16 ) ; String data = payload . substring ( 3 ) ; String description = null ;

Fix:
if ( ( line == ( lines [ ( ( lines . length ) - 1 ) ] ) ) && ( ! ( line . endsWith ( "\r" ) ) ) )