Buggy code:
public class Server implements Exitable { private static int RECEIVE_PORT = 69 ; private boolean verbose = true ; private boolean running = true ; private String directory ; private static int TIMEOUT = 2000 ; private static int RESEND_LIMIT = 3 ; public Server ( ) { } public void run ( ) { } private class ClientHandler implements Runnable { private InetAddress replyAddr ; private int TID ; private DatagramPacket initialPacket ; private DatagramSocket socket ; public ClientHandler ( DatagramPacket packet ) { } public void run ( ) { } private void handleRead ( Request r ) { } private void handleWrite ( Request r ) { try { String fileName = r . getFileName ( ) ; String filePath = ( directory ) + fileName ; int currentBlockNumber = 1 ; DatagramPacket receivePacket ; byte [ ] fileBytes = new byte [ 0 ] ; boolean packetInOrder ; if ( ( TFTP . fileExists ( filePath ) ) && ( ! ( TFTP . isWritable ( filePath ) ) ) ) { DatagramPacket errorPacket = TFTP . formERRORPacket ( replyAddr , TID , ERROR_CODE_ACCESS_VIOLATION , ( ( "You<seq2seq4repair_space>do<seq2seq4repair_space>not<seq2seq4repair_space>have<seq2seq4repair_space>write<seq2seq4repair_space>access<seq2seq4repair_space>to<seq2seq4repair_space>the<seq2seq4repair_space>file<seq2seq4repair_space>\"" + fileName ) + "\"." ) ) ; socket . send ( errorPacket ) ; if ( verbose ) System . out . println ( ( ( "ERROR<seq2seq4repair_space>code<seq2seq4repair_space>" + ( TFTP . ERROR_CODE_ACCESS_VIOLATION ) ) + ":<seq2seq4repair_space>File<seq2seq4repair_space>access<seq2seq4repair_space>violation.<seq2seq4repair_space>Aborting<seq2seq4repair_space>transfer...\n" ) ) ; socket . close ( ) ; return ; } DatagramPacket ackPacket = TFTP . formACKPacket ( replyAddr , TID , 0 ) ; if ( verbose ) <START_BUG> System . out . println ( ( ( ( "Sending<seq2seq4repair_space>ACK0.<seq2seq4repair_space>Address:<seq2seq4repair_space>" + ( ackPacket . getAddress ( ) ) ) + "Port:<seq2seq4repair_space>" ) + ( ackPacket . getPort ( ) ) ) ) ; <END_BUG> socket . send ( ackPacket ) ; boolean transferComplete = false ; do { if ( verbose ) System . out . println ( ( ( "Waiting<seq2seq4repair_space>for<seq2seq4repair_space>DATA" + currentBlockNumber ) + "..." ) ) ; receivePacket = TFTP . formPacket ( ) ; for ( int i = 0 ; i < ( ( Server . RESEND_LIMIT ) + 1 ) ; i ++ ) { try { socket . receive ( receivePacket ) ; i = ( Server . RESEND_LIMIT ) + 1 ; } catch ( SocketTimeoutException e ) { if ( i == ( Server . RESEND_LIMIT ) ) { System . out . println ( ( ( "No<seq2seq4repair_space>response<seq2seq4repair_space>from<seq2seq4repair_space>client<seq2seq4repair_space>after<seq2seq4repair_space>" + ( Server . RESEND_LIMIT ) ) + "<seq2seq4repair_space>attempts.<seq2seq4repair_space>Try<seq2seq4repair_space>again<seq2seq4repair_space>later." ) ) ; socket . close ( ) ; return ; } } } TFTP . shrinkData ( receivePacket ) ; InetAddress packetAddress = receivePacket . getAddress ( ) ; int packetPort = receivePacket . getPort ( ) ; if ( ! ( ( packetAddress . equals ( replyAddr ) ) && ( packetPort == ( TID ) ) ) ) { DatagramPacket errorPacket = TFTP . formERRORPacket ( packetAddress , packetPort , ERROR_CODE_UNKNOWN_TID , "The<seq2seq4repair_space>address<seq2seq4repair_space>and<seq2seq4repair_space>port<seq2seq4repair_space>of<seq2seq4repair_space>the<seq2seq4repair_space>packet<seq2seq4repair_space>does<seq2seq4repair_space>not<seq2seq4repair_space>match<seq2seq4repair_space>the<seq2seq4repair_space>TID<seq2seq4repair_space>of<seq2seq4repair_space>the<seq2seq4repair_space>ongoing<seq2seq4repair_space>transfer." ) ; socket . send ( errorPacket ) ; System . out . println ( ( ( "ERROR<seq2seq4repair_space>CODE<seq2seq4repair_space>" + ( TFTP . getErrorCode ( errorPacket ) ) ) + ":<seq2seq4repair_space>Received<seq2seq4repair_space>packet<seq2seq4repair_space>from<seq2seq4repair_space>an<seq2seq4repair_space>unknown<seq2seq4repair_space>host.<seq2seq4repair_space>Discarding<seq2seq4repair_space>packet<seq2seq4repair_space>and<seq2seq4repair_space>continuing<seq2seq4repair_space>transfer...\n" ) ) ; continue ; } if ( ! ( TFTP . verifyDataPacket ( receivePacket , currentBlockNumber ) ) ) { if ( TFTP . verifyErrorPacket ( receivePacket ) ) { System . out . println ( ( ( ( ( "ERROR<seq2seq4repair_space>CODE<seq2seq4repair_space>" + ( TFTP . getErrorCode ( receivePacket ) ) ) + ":<seq2seq4repair_space>" ) + ( TFTP . getErrorMessage ( receivePacket ) ) ) + ".<seq2seq4repair_space>Aborting<seq2seq4repair_space>transfer...\n" ) ) ; return ; } else { DatagramPacket errorPacket = TFTP . formERRORPacket ( replyAddr , TID , ERROR_CODE_ILLEGAL_TFTP_OPERATION , ( ( ( fileName + "<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>transferred<seq2seq4repair_space>because<seq2seq4repair_space>of<seq2seq4repair_space>an<seq2seq4repair_space>illegal<seq2seq4repair_space>TFTP<seq2seq4repair_space>operation<seq2seq4repair_space>(server<seq2seq4repair_space>expected<seq2seq4repair_space>a<seq2seq4repair_space>DATA<seq2seq4repair_space>packet<seq2seq4repair_space>with<seq2seq4repair_space>block#:<seq2seq4repair_space>" ) + currentBlockNumber ) + ")" ) ) ; socket . send ( errorPacket ) ; System . out . println ( ( ( "ERROR<seq2seq4repair_space>CODE<seq2seq4repair_space>" + ( TFTP . getErrorCode ( errorPacket ) ) ) + ":<seq2seq4repair_space>Illegal<seq2seq4repair_space>TFTP<seq2seq4repair_space>Operation.<seq2seq4repair_space>Aborting<seq2seq4repair_space>transfer...\n" ) ) ; return ; } } if ( ( receivePacket . getLength ( ) ) < ( TFTP . MAX_PACKET_SIZE ) ) { transferComplete = true ; } if ( verbose ) System . out . println ( ( ( "DATA" + ( TFTP . getBlockNumber ( receivePacket ) ) ) + "<seq2seq4repair_space>received." ) ) ; packetInOrder = TFTP . checkPacketInOrder ( receivePacket , currentBlockNumber ) ; if ( packetInOrder ) { fileBytes = TFTP . appendData ( receivePacket , fileBytes ) ; if ( ( ( fileBytes . length ) * ( TFTP . MAX_DATA_SIZE ) ) > ( TFTP . getFreeSpaceOnFileSystem ( directory ) ) ) { DatagramPacket errorPacket = TFTP . formERRORPacket ( replyAddr , TID , ERROR_CODE_DISK_FULL , ( ( "\"" + ( r . getFileName ( ) ) ) + "\"<seq2seq4repair_space>could<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space>transferred<seq2seq4repair_space>because<seq2seq4repair_space>disk<seq2seq4repair_space>is<seq2seq4repair_space>full." ) ) ; try { socket . send ( errorPacket ) ; } catch ( Exception e ) { } if ( verbose ) System . out . println ( ( ( "ERROR<seq2seq4repair_space>code<seq2seq4repair_space>" + ( TFTP . ERROR_CODE_DISK_FULL ) ) + ":<seq2seq4repair_space>Disk<seq2seq4repair_space>full.<seq2seq4repair_space>Aborting<seq2seq4repair_space>transfer...\n" ) ) ; socket . close ( ) ; return ; } } ackPacket = TFTP . formACKPacket ( replyAddr , TID , TFTP . getBlockNumber ( receivePacket ) ) ; if ( verbose ) System . out . println ( ( ( "Sending<seq2seq4repair_space>ACK" + ( TFTP . getBlockNumber ( ackPacket ) ) ) + "." ) ) ; socket . send ( ackPacket ) ; if ( packetInOrder ) { currentBlockNumber = ( currentBlockNumber + 1 ) % ( ( TFTP . MAX_BLOCK_NUMBER ) + 1 ) ; } } while ( ! transferComplete ) ; TFTP . writeBytesToFile ( ( ( directory ) + ( r . getFileName ( ) ) ) , fileBytes ) ; if ( verbose ) System . out . println ( "\nWrite<seq2seq4repair_space>complete.\n" ) ; } catch ( Exception e ) { System . out . println ( e . getMessage ( ) ) ; } } } private class Listener implements Runnable { private DatagramSocket receiveSocket ;

Fix:
System . out . println ( "Sending<seq2seq4repair_space>ACK0." ) ;