Buggy code:
private boolean resetNeeded ; private final Runnable sendMessagesWaitingForSpaceTask = new Runnable ( ) { @ Override public void run ( ) { } } ; private final Runnable expireMessagesTask = new Runnable ( ) { @ Override public void run ( ) { } } ; private final Object iteratingMutex = new Object ( ) ; class TimeoutMessage implements Delayed { Message message ; ConnectionContext context ; long trigger ; public TimeoutMessage ( Message message , ConnectionContext context , long delay ) { } @ Override public long getDelay ( TimeUnit unit ) { } @ Override public int compareTo ( Delayed delayed ) { } } DelayQueue < Queue . TimeoutMessage > flowControlTimeoutMessages = new DelayQueue < Queue . TimeoutMessage > ( ) ; class FlowControlTimeoutTask extends Thread { @ Override public void run ( ) { } } private final Queue . FlowControlTimeoutTask flowControlTimeoutTask = new Queue . FlowControlTimeoutTask ( ) ; private final Comparator < Subscription > orderedCompare = new Comparator < Subscription > ( ) { @ Override public int compare ( Subscription s1 , Subscription s2 ) { } } ; public Queue ( BrokerService brokerService , final ActiveMQDestination destination , MessageStore store , DestinationStatistics parentStats , TaskRunnerFactory taskFactory ) throws Exception { } @ Override public List < Subscription > getConsumers ( ) { } final class QueueThread extends Thread { final Queue queue ; public QueueThread ( Runnable runnable , String name , Queue queue ) { } } class BatchMessageRecoveryListener implements MessageRecoveryListener { final LinkedList < Message > toExpire = new LinkedList < Message > ( ) ; final double totalMessageCount ; int recoveredAccumulator = 0 ; int currentBatchCount ; BatchMessageRecoveryListener ( int totalMessageCount ) { } @ Override public boolean recoverMessage ( Message message ) { } @ Override public boolean recoverMessageReference ( MessageId messageReference ) throws Exception { } @ Override public boolean hasSpace ( ) { } @ Override public boolean isDuplicate ( MessageId id ) { } public void reset ( ) { } public void processExpired ( ) { } public boolean done ( ) { } } @ Override public void setPrioritizedMessages ( boolean prioritizedMessages ) { } @ Override public void initialize ( ) throws Exception { if ( ( this . messages ) == null ) { if ( ( ( destination . isTemporary ( ) ) || ( ( broker ) == null ) ) || ( ( store ) == null ) ) { this . messages = new VMPendingMessageCursor ( isPrioritizedMessages ( ) ) ; } else { this . messages = new org . apache . activemq . broker . region . cursors . StoreQueueCursor ( broker , this ) ; } } if ( ( messages ) instanceof VMPendingMessageCursor ) { this . systemUsage = brokerService . getSystemUsage ( ) ; memoryUsage . setParent ( systemUsage . getMemoryUsage ( ) ) ; } this . taskRunner = taskFactory . createTaskRunner ( this , ( "Queue:" + ( destination . getPhysicalName ( ) ) ) ) ; super . initialize ( ) ; if ( ( store ) != null ) { messages . setSystemUsage ( systemUsage ) ; messages . setEnableAudit ( isEnableAudit ( ) ) ; messages . setMaxAuditDepth ( getMaxAuditDepth ( ) ) ; messages . setMaxProducersToAudit ( getMaxProducersToAudit ( ) ) ; messages . setUseCache ( isUseCache ( ) ) ; messages . setMemoryUsageHighWaterMark ( getCursorMemoryHighWaterMark ( ) ) ; final int messageCount = store . getMessageCount ( ) ; if ( ( messageCount > 0 ) && ( messages . isRecoveryRequired ( ) ) ) { Queue . BatchMessageRecoveryListener listener = new Queue . BatchMessageRecoveryListener ( messageCount ) ; do { listener . reset ( ) ; store . recoverNextMessages ( getMaxPageSize ( ) , listener ) ; listener . processExpired ( ) ; } while ( ! ( listener . done ( ) ) ) ; } else { <START_BUG> destinationStatistics . getMessages ( ) . setCount ( messageCount ) ; <END_BUG> } } } class BrowserDispatch { QueueBrowserSubscription browser ; public BrowserDispatch ( QueueBrowserSubscription browserSubscription ) { } void done ( ) { } public QueueBrowserSubscription getBrowser ( ) { } } ConcurrentLinkedQueue < Queue . BrowserDispatch > browserDispatches = new ConcurrentLinkedQueue < Queue . BrowserDispatch > ( ) ; @ Override public void addSubscription ( ConnectionContext context , Subscription sub ) throws Exception { } @ Override public void removeSubscription ( ConnectionContext context , Subscription sub , long lastDeiveredSequenceId ) throws Exception { } @ Override public void send ( final ProducerBrokerExchange producerExchange , final Message message ) throws Exception { } private void registerCallbackForNotFullNotification ( ) { } private final LinkedList < MessageContext > indexOrderedCursorUpdates = new LinkedList < > ( ) ; @ Override public void onAdd ( MessageContext messageContext ) { } private void doPendingCursorAdditions ( ) throws Exception { } final class CursorAddSync extends Synchronization { private final MessageContext messageContext ; CursorAddSync ( MessageContext messageContext ) { } @ Override public void afterCommit ( ) throws Exception { } @ Override public void afterRollback ( ) throws Exception { } } void doMessageSend ( final ProducerBrokerExchange producerExchange , final Message message ) throws IOException , Exception { } private void orderedCursorAdd ( Message message , ConnectionContext context ) throws Exception { } private void checkUsage ( ConnectionContext context , ProducerBrokerExchange producerBrokerExchange , Message message ) throws IOException , InterruptedException , ResourceAllocationException { } private void expireMessages ( ) { } @ Override public void gc ( ) { } @ Override public void acknowledge ( ConnectionContext context , Subscription sub , MessageAck ack , MessageReference node ) throws IOException { } Message loadMessage ( MessageId messageId ) throws IOException { } @ Override public String toString ( ) { } @ Override public void start ( ) throws Exception { } @ Override public void stop ( ) throws Exception { } @ Override public ActiveMQDestination getActiveMQDestination ( ) { } public MessageGroupMap getMessageGroupOwners ( ) { }

Fix:
destinationStatistics . getMessages ( ) . add ( messageCount ) ;