Buggy code:
nodeOut . writeObject ( nodeJoinMsg ) ; success = true ; break ; case Message . SUCCESS_MSG : success = true ; break ; case Message . ERROR_MSG : PastryNode . LOGGER . severe ( ( ( ErrorMsg ) ( replyMsg ) ) . getMsg ( ) ) ; id = PastryNode . generateRandomID ( PastryNode . ID_BYTES ) ; continue ; default : PastryNode . LOGGER . severe ( ( ( "Recieved<seq2seq4repair_space>an<seq2seq4repair_space>unexpected<seq2seq4repair_space>message<seq2seq4repair_space>type<seq2seq4repair_space>'" + ( replyMsg . getMsgType ( ) ) ) + "'." ) ) ; return ; } } while ( true ) { Socket socket = serverSocket . accept ( ) ; PastryNode . LOGGER . fine ( ( ( ( ( "Received<seq2seq4repair_space>connection<seq2seq4repair_space>from<seq2seq4repair_space>'" + ( socket . getInetAddress ( ) ) ) + ":" ) + ( socket . getPort ( ) ) ) + "'." ) ) ; new Thread ( new PastryNode . PastryNodeWorker ( socket ) ) . start ( ) ; } } catch ( Exception e ) { e . printStackTrace ( ) ; PastryNode . LOGGER . severe ( e . getMessage ( ) ) ; } } private static byte [ ] generateRandomID ( int length ) { } protected short convertBytesToShort ( byte [ ] bytes ) { } protected int getSingleHexDistance ( String s1 , String s2 ) { } private int convertSingleHexToInt ( String str ) { } protected int lessThanDistance ( short s1 , short s2 ) { } protected int greaterThanDistance ( short s1 , short s2 ) { } protected NodeAddress searchRoutingTableExact ( byte [ ] nodeID , int prefixLength ) { } protected NodeAddress searchRoutingTableClosest ( byte [ ] nodeID , int prefixLength ) { } protected NodeAddress searchLeafSetClosest ( byte [ ] nodeID ) { } protected Map < byte [ ] , NodeAddress > getRelevantLeafSet ( ) { } protected Map < String , NodeAddress > getRelevantRoutingTable ( int prefixLength ) { } protected boolean updateLeafSet ( byte [ ] addID , NodeAddress nodeAddress ) { } protected boolean updateRoutingTable ( String addIDStr , NodeAddress nodeAddress , int prefixLength ) { } protected void printRoutingInfo ( ) { } protected String getFilename ( String storageDirectory , String filename ) { } protected class PastryNodeWorker extends Thread { protected Socket socket ; public PastryNodeWorker ( Socket socket ) { } @ Override public void run ( ) { try { ObjectInputStream in = new ObjectInputStream ( socket . getInputStream ( ) ) ; Message requestMsg = ( ( Message ) ( in . readObject ( ) ) ) ; Message replyMsg = null ; switch ( requestMsg . getMsgType ( ) ) { case Message . NODE_JOIN_MSG : NodeJoinMsg nodeJoinMsg = ( ( NodeJoinMsg ) ( requestMsg ) ) ; if ( ( nodeJoinMsg . getNodeAddress ( ) . getInetAddress ( ) ) == null ) { nodeJoinMsg . getNodeAddress ( ) . setInetAddress ( socket . getInetAddress ( ) ) ; } PastryNode . LOGGER . info ( ( ( "Recieved<seq2seq4repair_space>node<seq2seq4repair_space>join<seq2seq4repair_space>message<seq2seq4repair_space>'" + ( nodeJoinMsg . toString ( ) ) ) + "'." ) ) ; int p = nodeJoinMsg . getPrefixLength ( ) ; NodeAddress nodeAddress = searchRoutingTableExact ( nodeJoinMsg . getID ( ) , p ) ; if ( nodeAddress != null ) { nodeJoinMsg . setLongestPrefixMatch ( ( ( nodeJoinMsg . getPrefixLength ( ) ) + 1 ) ) ; } if ( nodeAddress == null ) { nodeAddress = searchRoutingTableClosest ( nodeJoinMsg . getID ( ) , p ) ; } <START_BUG> if ( nodeAddress == null ) { <END_BUG> nodeAddress = searchLeafSetClosest ( nodeJoinMsg . getID ( ) ) ; } Socket joinNodeSocket = new Socket ( nodeJoinMsg . getNodeAddress ( ) . getInetAddress ( ) , nodeJoinMsg . getNodeAddress ( ) . getPort ( ) ) ; ObjectOutputStream joinNodeOut = new ObjectOutputStream ( joinNodeSocket . getOutputStream ( ) ) ; joinNodeOut . writeObject ( new RoutingInfoMsg ( getRelevantLeafSet ( ) , p , getRelevantRoutingTable ( p ) , ( ( nodeAddress . getInetAddress ( ) ) == null ) ) ) ; joinNodeSocket . close ( ) ; if ( ( nodeAddress . getInetAddress ( ) ) != null ) { PastryNode . LOGGER . info ( ( ( ( ( "Forwarding<seq2seq4repair_space>node<seq2seq4repair_space>join<seq2seq4repair_space>message<seq2seq4repair_space>with<seq2seq4repair_space>id<seq2seq4repair_space>'" + ( HexConverter . convertBytesToHex ( nodeJoinMsg . getID ( ) ) ) ) + "'<seq2seq4repair_space>to<seq2seq4repair_space>'" ) + nodeAddress ) + "'" ) ) ; nodeJoinMsg . addHop ( nodeAddress ) ; Socket nodeSocket = new Socket ( nodeAddress . getInetAddress ( ) , nodeAddress . getPort ( ) ) ; ObjectOutputStream nodeOut = new ObjectOutputStream ( nodeSocket . getOutputStream ( ) ) ; nodeOut . writeObject ( nodeJoinMsg ) ; nodeSocket . close ( ) ; } break ; case Message . ROUTING_INFO_MSG : RoutingInfoMsg routingInfoMsg = ( ( RoutingInfoMsg ) ( requestMsg ) ) ; PastryNode . LOGGER . fine ( ( ( "Recieved<seq2seq4repair_space>routing<seq2seq4repair_space>info<seq2seq4repair_space>message<seq2seq4repair_space>with<seq2seq4repair_space>" + ( routingInfoMsg . getLeafSet ( ) . size ( ) ) ) + "<seq2seq4repair_space>routes." ) ) ; boolean changed = false ; for ( Map . Entry < byte [ ] , NodeAddress > entry : routingInfoMsg . getLeafSet ( ) . entrySet ( ) ) { if ( ( entry . getValue ( ) . getInetAddress ( ) ) == null ) { changed = ( updateLeafSet ( entry . getKey ( ) , new NodeAddress ( socket . getInetAddress ( ) , entry . getValue ( ) . getPort ( ) ) ) ) || changed ; } else { changed = ( updateLeafSet ( entry . getKey ( ) , entry . getValue ( ) ) ) || changed ; } if ( ! ( Arrays . equals ( entry . getKey ( ) , id ) ) ) { String nodeIDStr = HexConverter . convertBytesToHex ( entry . getKey ( ) ) ; int i = 0 ; for ( i = 0 ; i < 4 ;

Fix:
if ( ( nodeAddress == null ) || ( nodeJoinMsg . hopContains ( nodeAddress ) ) ) {