Buggy code:
public class HAService { private static final Logger log = LoggerFactory . getLogger ( StoreLoggerName ) ; private final AtomicInteger connectionCount = new AtomicInteger ( 0 ) ; private final List < HAConnection > connectionList = new LinkedList < HAConnection > ( ) ; private final HAService . AcceptSocketService acceptSocketService ; private final DefaultMessageStore defaultMessageStore ; private final WaitNotifyObject waitNotifyObject = new WaitNotifyObject ( ) ; private final AtomicLong push2SlaveMaxOffset = new AtomicLong ( 0 ) ; private final HAService . GroupTransferService groupTransferService ; private final HAService . HAClient haClient ; private CRC32 checksum = new CRC32 ( ) ; public HAService ( final DefaultMessageStore defaultMessageStore ) throws IOException { } public void updateMasterAddress ( final String newAddr ) { } public void putRequest ( final GroupCommitRequest request ) { } public boolean isSlaveOK ( final long masterPutWhere ) { } public void notifyTransferSome ( final long offset ) { } public AtomicInteger getConnectionCount ( ) { } public void start ( ) { } public void addConnection ( final HAConnection conn ) { } public void removeConnection ( final HAConnection conn ) { } public void shutdown ( ) { } public void destroyConnections ( ) { } public DefaultMessageStore getDefaultMessageStore ( ) { } public WaitNotifyObject getWaitNotifyObject ( ) { } class AcceptSocketService extends ServiceThread { private ServerSocketChannel serverSocketChannel ; private Selector selector ; private SocketAddress socketAddressListen ; public AcceptSocketService ( final int port ) { } public void beginAccept ( ) { } @ Override public void run ( ) { } @ Override public String getServiceName ( ) { } } class GroupTransferService extends ServiceThread { private final WaitNotifyObject notifyTransferObject = new WaitNotifyObject ( ) ; private volatile List < GroupCommitRequest > requestsWrite = new ArrayList < GroupCommitRequest > ( ) ; private volatile List < GroupCommitRequest > requestsRead = new ArrayList < GroupCommitRequest > ( ) ; public void putRequest ( final GroupCommitRequest request ) { } public void notifyTransferSome ( ) { } private void swapRequests ( ) { } private void doWaitTransfer ( ) { if ( ! ( this . requestsRead . isEmpty ( ) ) ) { for ( GroupCommitRequest req : this . requestsRead ) { boolean transferOK = ( HAService . this . push2SlaveMaxOffset . get ( ) ) >= ( req . getNextOffset ( ) ) ; <START_BUG> for ( int i = 0 ; ( ! transferOK ) && ( i < 5 ) ; ) { <END_BUG> this . notifyTransferObject . waitForRunning ( 1000 ) ; transferOK = ( HAService . this . push2SlaveMaxOffset . get ( ) ) >= ( req . getNextOffset ( ) ) ; } if ( ! transferOK ) { HAService . log . warn ( ( "transfer<seq2seq4repair_space>message<seq2seq4repair_space>to<seq2seq4repair_space>slave<seq2seq4repair_space>timeout,<seq2seq4repair_space>" + ( req . getNextOffset ( ) ) ) ) ; } req . wakeupCustomer ( transferOK ) ; } this . requestsRead . clear ( ) ; } } public void run ( ) { } @ Override protected void onWaitEnd ( ) { } @ Override public String getServiceName ( ) { } } class HAClient extends ServiceThread { private static final int ReadMaxBufferSize = ( 1024 * 1024 ) * 4 ; private final AtomicReference < String > masterAddress = new AtomicReference < String > ( ) ; private final ByteBuffer reportOffset = ByteBuffer . allocate ( 8 ) ; private SocketChannel socketChannel ; private Selector selector ; private long lastWriteTimestamp = System . currentTimeMillis ( ) ; private long currentReportedOffset = 0 ; private int dispatchPosition = 0 ; private ByteBuffer byteBufferRead = ByteBuffer . allocate ( HAService . HAClient . ReadMaxBufferSize ) ; private ByteBuffer byteBufferBackup = ByteBuffer . allocate ( HAService . HAClient . ReadMaxBufferSize ) ; public HAClient ( ) throws IOException { } public void updateMasterAddress ( final String newAddr ) { } private boolean isTimeToReportOffset ( ) { } private boolean reportSlaveMaxOffset ( final long maxOffset ) { } private void reallocateByteBuffer ( ) { } private void swapByteBuffer ( ) { } private boolean processReadEvent ( ) { } private boolean dispatchReadRequest ( ) { } private boolean reportSlaveMaxOffsetPlus ( ) { } private boolean connectMaster ( ) throws ClosedChannelException { } private void closeMaster ( ) { } @ Override public void run ( ) { } @ Override public String getServiceName ( ) { } } public AtomicLong getPush2SlaveMaxOffset ( ) { } }

Fix:
for ( int i = 0 ; ( ! transferOK ) && ( i < 5 ) ; i ++ ) {