Program: 81966
Project: 81966
Buggy source:
/** 
 * Removes all messages in the queue targeted to this specific MessageClient subscription(s) and returns them to be sent to the client. Overrides should be careful to only return messages for the specified MessageClient.
 * @param messageClient The specific MessageClient to return messages for.
 * @param outboundQueue The queue of outbound messages.
 * @return A FlushResult containing the messages that have been removed from the outbound queueto be written to the network for this MessageClient.
 */
public FlushResult flush(MessageClient messageClient,List<Message> outboundQueue){
  FlushResult flushResult=new FlushResult();
  List<Message> messagesToFlush=null;
  for (Iterator<Message> iter=outboundQueue.iterator(); iter.hasNext(); ) {
    Message message=iter.next();
    if (messageClient == null || (message.getClientId().equals(messageClient.getClientId()))) {
      if (isMessageExpired(message)) {
        iter.remove();
        continue;
      }
      messageClient=messageClient == null ? getMessageClient(message) : messageClient;
      ThrottleResult throttleResult=throttleOutgoingDestinationLevel(messageClient,message,false);
      Result result=throttleResult.getResult();
      if (Result.OK == result) {
        throttleResult=throttleOutgoingClientLevel(messageClient,message,false);
        result=throttleResult.getResult();
        if (Result.OK == result) {
          updateMessageFrequencyOutgoing(messageClient,message);
          if (messagesToFlush == null)           messagesToFlush=new ArrayList<Message>();
          messagesToFlush.add(message);
        }
      }
      iter.remove();
    }
  }
  flushResult.setMessages(messagesToFlush);
  return flushResult;
}

Fixed version (ground truth):
/** 
 * Removes all messages in the queue targeted to this specific MessageClient subscription(s) and returns them to be sent to the client. Overrides should be careful to only return messages for the specified MessageClient.
 * @param messageClient The specific MessageClient to return messages for.
 * @param outboundQueue The queue of outbound messages.
 * @return A FlushResult containing the messages that have been removed from the outbound queueto be written to the network for this MessageClient.
 */
public FlushResult flush(MessageClient messageClient,List<Message> outboundQueue){
  FlushResult flushResult=new FlushResult();
  List<Message> messagesToFlush=null;
  for (Iterator<Message> iter=outboundQueue.iterator(); iter.hasNext(); ) {
    Message message=iter.next();
    if (messageClient == null || (message.getClientId().equals(messageClient.getClientId()))) {
      if (isMessageExpired(message)) {
        iter.remove();
        continue;
      }
      MessageClient messageClientForCurrentMessage=messageClient == null ? getMessageClient(message) : messageClient;
      ThrottleResult throttleResult=throttleOutgoingDestinationLevel(messageClientForCurrentMessage,message,false);
      Result result=throttleResult.getResult();
      if (Result.OK == result) {
        throttleResult=throttleOutgoingClientLevel(messageClientForCurrentMessage,message,false);
        result=throttleResult.getResult();
        if (Result.OK == result) {
          updateMessageFrequencyOutgoing(messageClientForCurrentMessage,message);
          if (messagesToFlush == null)           messagesToFlush=new ArrayList<Message>();
          messagesToFlush.add(message);
        }
      }
      iter.remove();
    }
  }
  flushResult.setMessages(messagesToFlush);
  return flushResult;
}