Buggy code:
@ Value ( "${messageTimeout}" ) long messageTimeout ; private ErrorSimulationMode errorSimulationMode = ErrorSimulationMode . NO_ERROR ; private ChainNodeStatsCollector chainNodeStatsCollector = new ChainNodeStatsCollector ( ) ; @ RequestMapping ( value = "//errSim" , method = RequestMethod . GET ) public ResponseEntity < ErrorSimulationMode > getErrorSimulationMode ( ) { } @ RequestMapping ( value = "//errSim" , method = RequestMethod . PUT ) public ResponseEntity < String > setErrorSimulationMode ( @ RequestParam ( required = true , value = "mode" ) ErrorSimulationMode newMode ) { } @ RequestMapping ( value = "//ping" , method = RequestMethod . GET ) public ResponseEntity < ChainNodeRoutingStats > ping ( ) { } @ RequestMapping ( value = "//request" , method = RequestMethod . POST ) @ ResponseBody public DeferredResult < Message > routeRequest ( @ RequestBody final Message msg , HttpServletResponse response ) throws IOException { final StopWatch stopWatch = new StopWatch ( ) ; stopWatch . start ( ) ; if ( ( this . errorSimulationMode ) == ( ErrorSimulationMode . RETURN_404 ) ) { logger . debug ( "simulating<seq2seq4repair_space>a<seq2seq4repair_space>404<seq2seq4repair_space>error<seq2seq4repair_space>(ERROR_404)" ) ; response . setStatus ( NOT_FOUND . value ( ) ) ; stopWatch . stop ( ) ; this . chainNodeStatsCollector . onMessageProcessingError ( stopWatch . getTotalTimeMillis ( ) ) ; return null ; } try { chainNodeStatsCollector . onMessageReceived ( ) ; logger . debug ( "received<seq2seq4repair_space>request<seq2seq4repair_space>with<seq2seq4repair_space>message<seq2seq4repair_space>{}" , msg ) ; String payload = msg . getPayload ( ) ; String decryptedPayload = cryptoService . decrypt ( payload ) ; if ( ( msg . getHopsToGo ( ) ) < 0 ) { throw new IllegalArgumentException ( "hopsToGo<seq2seq4repair_space>must<seq2seq4repair_space>not<seq2seq4repair_space>be<seq2seq4repair_space><0" ) ; } ListenableFuture < Message > msgFuture = null ; Message timeoutMessage = null ; if ( ( this . errorSimulationMode ) == ( ErrorSimulationMode . SLOW_ACCEPT ) ) { logger . debug ( "simulating<seq2seq4repair_space>slow<seq2seq4repair_space>accept<seq2seq4repair_space>(SLOW_ACCEPT)" ) ; Thread . sleep ( 5000 ) ; } if ( ( msg . getHopsToGo ( ) ) == 0 ) { logger . info ( "received<seq2seq4repair_space>exit<seq2seq4repair_space>request<seq2seq4repair_space>from<seq2seq4repair_space>{}" , msg . getSender ( ) ) ; logger . debug ( "//request:<seq2seq4repair_space>last<seq2seq4repair_space>hop,<seq2seq4repair_space>received<seq2seq4repair_space>payload<seq2seq4repair_space>{}" , decryptedPayload ) ; logger . debug ( "//request:<seq2seq4repair_space>sending<seq2seq4repair_space>exit<seq2seq4repair_space>request<seq2seq4repair_space>asynchronously" ) ; updateRoutingInfoForRequest ( msg , null ) ; msgFuture = this . asyncRequestService . sendExitRequestAndTunnelResponse ( msg . getRecipient ( ) , msg . getChainId ( ) , msg . getPublicKey ( ) , decryptedPayload ) ; timeoutMessage = new Message ( "CNC:routeRequest:hopsToGo==0,timeoutmsg" ) ; timeoutMessage . setChainId ( msg . getChainId ( ) ) ; timeoutMessage . setStatus ( TARGET_TIMEOUT ) ; timeoutMessage . setMisbehavingNode ( msg . getRecipient ( ) ) ; } else { Message nextMsg = JsonUtils . fromJSON ( decryptedPayload ) ; logger . info ( "received<seq2seq4repair_space>chain<seq2seq4repair_space>request<seq2seq4repair_space>from<seq2seq4repair_space>{}<seq2seq4repair_space>to<seq2seq4repair_space>{}" , msg . getSender ( ) , nextMsg . getRecipient ( ) ) ; logger . debug ( "//request:<seq2seq4repair_space>sending<seq2seq4repair_space>chain<seq2seq4repair_space>request<seq2seq4repair_space>asynchronously<seq2seq4repair_space>(hops<seq2seq4repair_space>to<seq2seq4repair_space>go:<seq2seq4repair_space>{})" , nextMsg . getHopsToGo ( ) ) ; updateRoutingInfoForRequest ( msg , nextMsg ) ; msgFuture = this . asyncRequestService . sendChainRequest ( nextMsg ) ; timeoutMessage = new Message ( "CNC:routeRequest:hopsToGo>0,timeoutmsg" ) ; timeoutMessage . setChainId ( msg . getChainId ( ) ) ; timeoutMessage . setStatus ( CHAIN_TIMEOUT ) ; timeoutMessage . setMisbehavingNode ( nextMsg . getRecipient ( ) ) ; } final DeferredResult deferredResult = new DeferredResult < Message > ( ( ( messageTimeout ) * ( ( msg . getHopsToGo ( ) ) + 1 ) ) , timeoutMessage ) ; msgFuture . addCallback ( new org . springframework . util . concurrent . ListenableFutureCallback < Message > ( ) { @ Override public void onFailure ( Throwable ex ) { logger . debug ( "//request:<seq2seq4repair_space>failure" , ex ) ; Message responseMessage = new Message ( "CNC:routeRequest:msgFuture.onFailure" ) ; responseMessage . setChainId ( msg . getChainId ( ) ) ; if ( ex instanceof OnionRoutingRequestException ) { responseMessage . setMisbehavingNode ( ( ( OnionRoutingRequestException ) ( ex ) ) . getMisbehavingNode ( ) ) ; responseMessage . setStatus ( CHAIN_ERROR ) ; } else if ( ex instanceof OnionRoutingTargetRequestException ) { responseMessage . setStatus ( TARGET_ERROR ) ; } else { responseMessage . setStatus ( CHAIN_ERROR ) ; } logger . info ( "An<seq2seq4repair_space>error<seq2seq4repair_space>occurred<seq2seq4repair_space>during<seq2seq4repair_space>request<seq2seq4repair_space>processing,<seq2seq4repair_space>sending<seq2seq4repair_space>back<seq2seq4repair_space>an<seq2seq4repair_space>error<seq2seq4repair_space>message" ) ; updateRoutingInfoForResponse ( msg , responseMessage ) ; stopWatch . stop ( ) ; chainNodeStatsCollector . onMessageProcessed ( stopWatch . getLastTaskTimeMillis ( ) ) ; deferredResult . setResult ( responseMessage ) ; } @ Override public void onSuccess ( Message responseMessage ) { logger . info ( "received<seq2seq4repair_space>response,<seq2seq4repair_space>routing<seq2seq4repair_space>it<seq2seq4repair_space>back" ) ; logger . debug ( "//request:<seq2seq4repair_space>done.<seq2seq4repair_space>result:<seq2seq4repair_space>{}" , responseMessage ) ; responseMessage . setDebugInfo ( ( ( responseMessage . getDebugInfo ( ) ) + "|<seq2seq4repair_space>CNC:routeRequest:msgFuture.onSuccess" ) ) ; updateRoutingInfoForResponse ( msg , responseMessage ) ; <START_BUG> if ( ( errorSimulationMode ) == ( ErrorSimulationMode . SLOW_ACCEPT ) ) { <END_BUG> try { logger . debug ( "simulating<seq2seq4repair_space>slow<seq2seq4repair_space>response<seq2seq4repair_space>(SLOW_RESPONSE)" ) ; Thread . sleep ( 5000 ) ; } catch ( InterruptedException e ) { logger . debug ( "caught<seq2seq4repair_space>exception<seq2seq4repair_space>during<seq2seq4repair_space>SLOW_RESPONSE<seq2seq4repair_space>sleep" , e ) ; } } stopWatch . stop ( ) ; chainNodeStatsCollector . onMessageProcessed ( stopWatch . getLastTaskTimeMillis ( ) ) ; deferredResult . setResult ( responseMessage ) ; } } ) ; return deferredResult ; } catch ( Throwable t ) { if ( logger . isDebugEnabled ( ) ) { logger . debug ( "//request:<seq2seq4repair_space>error<seq2seq4repair_space>-<seq2seq4repair_space>caught<seq2seq4repair_space>throwable<seq2seq4repair_space>during<seq2seq4repair_space>chain<seq2seq4repair_space>request:" , t ) ; } else { logger . info ( String . format ( "//request:<seq2seq4repair_space>error<seq2seq4repair_space>-<seq2seq4repair_space>caught<seq2seq4repair_space>throwable<seq2seq4repair_space>during<seq2seq4repair_space>chain<seq2seq4repair_space>request:<seq2seq4repair_space>%s<seq2seq4repair_space>(more<seq2seq4repair_space>info<seq2seq4repair_space>on<seq2seq4repair_space>loglevel<seq2seq4repair_space>DEBUG" , t . getMessage ( ) ) ) ; } DeferredResult < Message > errorResult = new DeferredResult < Message > ( ) ; Message responseMessage = new Message ( "CNC:routeRequest:finalCatch" ) ; responseMessage . setChainId ( msg . getChainId ( ) ) ; responseMessage . setStatus ( CHAIN_ERROR ) ; responseMessage . setMisbehavingNode ( msg . getRecipient ( ) ) ; responseMessage . setSender ( msg . getRecipient ( ) ) ; responseMessage . setRecipient ( msg . getSender ( ) ) ; responseMessage . setErrorMessage ( t . getMessage ( ) ) ; stopWatch . stop ( ) ; this . chainNodeStatsCollector . onMessageProcessingError ( stopWatch . getLastTaskTimeMillis ( ) ) ; errorResult . setResult ( responseMessage ) ;

Fix:
if ( ( errorSimulationMode ) == ( ErrorSimulationMode . SLOW_RESPONSE ) ) {