Buggy code:
public class OutboundTcpConnection extends Thread { private static final Logger logger = LoggerFactory . getLogger ( OutboundTcpConnection . class ) ; private static final String PREFIX = Config . PROPERTY_PREFIX ; private static final String INTRADC_TCP_NODELAY_PROPERTY = ( OutboundTcpConnection . PREFIX ) + "OTC_INTRADC_TCP_NODELAY" ; private static final boolean INTRADC_TCP_NODELAY = Boolean . valueOf ( System . getProperty ( OutboundTcpConnection . INTRADC_TCP_NODELAY_PROPERTY , "true" ) ) ; private static final String TIMESTAMP_UPDATE_INTERVAL_PROPERTY = ( OutboundTcpConnection . PREFIX ) + "OTC_TIMESTAMP_UPDATE_INTERVAL" ; private static final long TIMESTAMP_UPDATE_INTERVAL = Long . getLong ( OutboundTcpConnection . TIMESTAMP_UPDATE_INTERVAL_PROPERTY , 10000 ) ; private static volatile long [ ] TIMESTAMP_BASE = new long [ ] { System . currentTimeMillis ( ) , System . nanoTime ( ) } ; @ VisibleForTesting static final Object TIMESTAMP_UPDATE = new Object ( ) ; @ VisibleForTesting static final long convertNanoTimeToCurrentTimeMillis ( long nanoTime ) { } private static final String BUFFER_SIZE_PROPERTY = ( OutboundTcpConnection . PREFIX ) + "OTC_BUFFER_SIZE" ; private static final int BUFFER_SIZE = Integer . getInteger ( OutboundTcpConnection . BUFFER_SIZE_PROPERTY , ( 1024 * 64 ) ) ; private static final String COALESCING_WINDOW_PROPERTY = ( OutboundTcpConnection . PREFIX ) + "OTC_COALESCING_WINDOW_MICROSECONDS" ; private static final int COALESCING_WINDOW = Integer . getInteger ( OutboundTcpConnection . COALESCING_WINDOW_PROPERTY , 200 ) ; private static final String COALESCING_STRATEGY_PROPERTY = ( OutboundTcpConnection . PREFIX ) + "OTC_COALESCING_STRATEGY" ; private static final String COALESCING_STRATEGY = System . getProperty ( OutboundTcpConnection . COALESCING_STRATEGY_PROPERTY , "TIMEHORIZON" ) . trim ( ) . toUpperCase ( ) ; private static final String DEBUG_COALESCING_PROPERTY = ( OutboundTcpConnection . PREFIX ) + "OTC_DEBUG_COALESCING" ; private static final boolean DEBUG_COALESCING = ( Boolean . getBoolean ( OutboundTcpConnection . DEBUG_COALESCING_PROPERTY ) ) | ( OutboundTcpConnection . logger . isDebugEnabled ( ) ) ; private static void parkLoop ( long nanos ) { } private static boolean maybeSleep ( int messages , long averageGap , long maxCoalesceWindow ) { } @ VisibleForTesting interface CoalescingStrategy { void coalesce ( BlockingQueue < OutboundTcpConnection . QueuedMessage > input , List < OutboundTcpConnection . QueuedMessage > out , int outSize ) throws InterruptedException { } } @ VisibleForTesting static class TimeHorizonMovingAverageCoalescingStrategy implements OutboundTcpConnection . CoalescingStrategy { private static final int INDEX_SHIFT = 26 ; private static final long BUCKET_INTERVAL = 1L << 26 ; private static final int BUCKET_COUNT = 16 ; private static final long INTERVAL = ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . BUCKET_INTERVAL ) * ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . BUCKET_COUNT ) ; private static final long MEASURED_INTERVAL = ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . BUCKET_INTERVAL ) * ( ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . BUCKET_COUNT ) - 1 ) ; private long epoch = System . nanoTime ( ) ; private final int [ ] samples = new int [ OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . BUCKET_COUNT ] ; private long sum = 0 ; private final long maxCoalesceWindow ; public TimeHorizonMovingAverageCoalescingStrategy ( int maxCoalesceWindow ) { } private void logSample ( long nanos ) { } private long averageGap ( ) { } private long rollepoch ( long delta , long epoch , long nanos ) { } private long epoch ( long latestNanos ) { <START_BUG> return ( latestNanos - ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . INTERVAL ) ) & ( ~ ( ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . BUCKET_INTERVAL ) - 1 ) ) ; <END_BUG> } private int ix ( long nanos ) { } volatile boolean shouldLogAverage = false ; @ Override public void coalesce ( BlockingQueue < OutboundTcpConnection . QueuedMessage > input , List < OutboundTcpConnection . QueuedMessage > out , int outSize ) throws InterruptedException { } } @ VisibleForTesting static class MovingAverageCoalescingStrategy implements OutboundTcpConnection . CoalescingStrategy { private final int [ ] samples = new int [ 16 ] ; private long lastSample = 0 ; private int index = 0 ; private long sum = 0 ; private final long maxCoalesceWindow ; public MovingAverageCoalescingStrategy ( int maxCoalesceWindow ) { } private long logSample ( int value ) { } private long notifyOfSample ( long sample ) { } volatile boolean shouldLogAverage = false ; @ Override public void coalesce ( BlockingQueue < OutboundTcpConnection . QueuedMessage > input , List < OutboundTcpConnection . QueuedMessage > out , int outSize ) throws InterruptedException { } boolean sumMatches ( ) { } } @ VisibleForTesting static class FixedCoalescingStrategy implements OutboundTcpConnection . CoalescingStrategy { private final long coalesceWindow ; public FixedCoalescingStrategy ( int coalesceWindowMicros ) { } @ Override public void coalesce ( BlockingQueue < OutboundTcpConnection . QueuedMessage > input , List < OutboundTcpConnection . QueuedMessage > out , int outSize ) throws InterruptedException { } } @ VisibleForTesting static class DisabledCoalescingStrategy implements OutboundTcpConnection . CoalescingStrategy { @ Override public void coalesce ( BlockingQueue < OutboundTcpConnection . QueuedMessage > input , List < OutboundTcpConnection . QueuedMessage > out , int outSize ) throws InterruptedException { } } @ VisibleForTesting static class DisabledBrokenCoalescingStrategy implements OutboundTcpConnection . CoalescingStrategy { @ Override public void coalesce ( BlockingQueue < OutboundTcpConnection . QueuedMessage > input , List < OutboundTcpConnection . QueuedMessage > out , int outSize ) throws InterruptedException { } } private static OutboundTcpConnection . CoalescingStrategy newCoalescingStrategy ( ) { } private static final MessageOut CLOSE_SENTINEL = new MessageOut ( Verb . INTERNAL_RESPONSE ) ; private volatile boolean isStopped = false ; private static final int OPEN_RETRY_DELAY = 100 ; public static final int WAIT_FOR_VERSION_MAX_TIME = 5000 ; private static final int NO_VERSION = Integer . MIN_VALUE ; static final int LZ4_HASH_SEED = - 1756908916 ; private final BlockingQueue < OutboundTcpConnection . QueuedMessage > backlog = new LinkedBlockingQueue < > ( ) ; private final OutboundTcpConnectionPool poolReference ; private final OutboundTcpConnection . CoalescingStrategy cs = OutboundTcpConnection . newCoalescingStrategy ( ) ; private DataOutputStreamPlus out ; private Socket socket ; private volatile long completed ; private final AtomicLong dropped = new AtomicLong ( ) ; private volatile int currentMsgBufferCount = 0 ; private int targetVersion ; public OutboundTcpConnection ( OutboundTcpConnectionPool pool ) { } private static boolean isLocalDC ( InetAddress targetHost ) { }

Fix:
return ( latestNanos - ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . MEASURED_INTERVAL ) ) & ( ~ ( ( OutboundTcpConnection . TimeHorizonMovingAverageCoalescingStrategy . BUCKET_INTERVAL ) - 1 ) ) ;