Program: 173100
Project: 173100
Buggy source:
/** 
 * Progress the serializations
 */
public void progress(){
  lock.lock();
  try {
    for (    Map.Entry<Integer,ArrayBlockingQueue<Pair<Object,MPISendMessage>>> e : pendingSendMessagesPerSource.entrySet()) {
      Queue<Pair<Object,MPISendMessage>> pendingSendMessages=e.getValue();
      boolean canProgress=true;
      while (pendingSendMessages.size() > 0 && canProgress) {
        Pair<Object,MPISendMessage> pair=pendingSendMessages.peek();
        MPISendMessage mpiSendMessage=pair.getValue();
        Object messageObject=pair.getKey();
        if (mpiSendMessage.serializedState() == MPISendMessage.SendState.INIT) {
          for (          Integer i : mpiSendMessage.getInternalSends()) {
            boolean receiveAccepted;
            if (isStoreBased && isLastReceiver) {
              serializeAndWriteToMemoryManager(mpiSendMessage,messageObject);
              receiveAccepted=receiver.receiveSendInternally(mpiSendMessage.getSource(),i,mpiSendMessage.getPath(),mpiSendMessage.getFlags(),operationMemoryManager);
            }
 else {
              receiveAccepted=receiver.receiveSendInternally(mpiSendMessage.getSource(),i,mpiSendMessage.getPath(),mpiSendMessage.getFlags(),messageObject);
            }
            if (!receiveAccepted) {
              canProgress=false;
              int attempt=updateAttemptMap(sendMessageInternalAttempts,i,1);
              if (debug && attempt > MAX_ATTEMPTS) {
                LOG.info(String.format("String_Node_Str",executor,attempt));
              }
              break;
            }
 else {
              updateAttemptMap(sendMessageInternalAttempts,i,-1);
            }
          }
          if (canProgress) {
            mpiSendMessage.setSendState(MPISendMessage.SendState.SENT_INTERNALLY);
          }
        }
        if (canProgress) {
          if (mpiSendMessage.getExternalSends().size() == 0) {
            pendingSendMessages.poll();
            continue;
          }
          MPISendMessage message=(MPISendMessage)messageSerializer.build(pair.getKey(),mpiSendMessage);
          if (message.serializedState() == MPISendMessage.SendState.SERIALIZED) {
            List<Integer> exRoutes=new ArrayList<>(mpiSendMessage.getExternalSends());
            int startOfExternalRouts=mpiSendMessage.getAcceptedExternalSends();
            int noOfExternalSends=startOfExternalRouts;
            for (int i=startOfExternalRouts; i < exRoutes.size(); i++) {
              boolean sendAccepted=sendMessageToTarget(message.getMPIMessage(),exRoutes.get(i));
              if (!sendAccepted) {
                canProgress=false;
                sendMessageToTargetAttempts++;
                if (sendMessageToTargetAttempts > MAX_ATTEMPTS) {
                  LOG.info(String.format("String_Node_Str",executor,sendMessageToTargetAttempts));
                }
                break;
              }
 else {
                if (sendMessageToTargetAttempts > 0) {
                  sendMessageToTargetAttempts--;
                }
                mpiSendMessage.incrementAcceptedExternalSends();
                noOfExternalSends++;
              }
            }
            if (noOfExternalSends == exRoutes.size()) {
              mpiSendMessage.setSendState(MPISendMessage.SendState.FINISHED);
              pendingSendMessages.poll();
            }
          }
 else {
            break;
          }
        }
      }
    }
    for (    Map.Entry<Integer,Queue<MPIMessage>> it : pendingReceiveDeSerializations.entrySet()) {
      MPIMessage currentMessage=it.getValue().poll();
      if (currentMessage == null) {
        continue;
      }
      int id=currentMessage.getOriginatingId();
      if (isStoreBased && isLastReceiver) {
        writeToMemoryManager(currentMessage);
        currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
        if (!receiver.receiveMessage(currentMessage,operationMemoryManager)) {
          int attempt=updateAttemptMap(receiveMessageAttempts,id,1);
          if (debug && attempt > MAX_ATTEMPTS) {
            LOG.info(String.format("String_Node_Str",executor,attempt));
          }
          continue;
        }
 else {
          updateAttemptMap(receiveMessageAttempts,id,-1);
        }
      }
 else {
        Object object=messageDeSerializer.build(currentMessage,currentMessage.getHeader().getEdge());
        Queue<Pair<Object,MPIMessage>> pendingReceiveMessages=pendingReceiveMessagesPerSource.get(id);
        currentMessage.setReceivedState(MPIMessage.ReceivedState.INIT);
        if (pendingReceiveMessages.size() > 0) {
          if (!pendingReceiveMessages.offer(new ImmutablePair<>(object,currentMessage))) {
            throw new RuntimeException(executor + "String_Node_Str" + pendingReceiveMessages.size());
          }
        }
 else {
          currentMessage.incrementRefCount();
          currentMessage.setReceivedState(MPIMessage.ReceivedState.DOWN);
          if (!receiver.passMessageDownstream(object,currentMessage)) {
            if (!pendingReceiveMessages.offer(new ImmutablePair<>(object,currentMessage))) {
              throw new RuntimeException(executor + "String_Node_Str" + pendingReceiveMessages.size());
            }
            continue;
          }
          currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
          if (!receiver.receiveMessage(currentMessage,object)) {
            if (!pendingReceiveMessages.offer(new ImmutablePair<>(object,currentMessage))) {
              throw new RuntimeException(executor + "String_Node_Str" + pendingReceiveMessages.size());
            }
            int attempt=updateAttemptMap(receiveMessageAttempts,id,1);
            if (debug && attempt > MAX_ATTEMPTS) {
              LOG.info(String.format("String_Node_Str",executor,attempt));
            }
            continue;
          }
 else {
            updateAttemptMap(receiveMessageAttempts,id,-1);
          }
        }
        currentMessage.release();
      }
    }
    for (    Map.Entry<Integer,Queue<Pair<Object,MPIMessage>>> e : pendingReceiveMessagesPerSource.entrySet()) {
      Queue<Pair<Object,MPIMessage>> pendingReceiveMessages=e.getValue();
      while (pendingReceiveMessages.size() > 0) {
        Pair<Object,MPIMessage> pair=pendingReceiveMessages.peek();
        MPIMessage.ReceivedState state=pair.getRight().getReceivedState();
        MPIMessage currentMessage=pair.getRight();
        Object object=pair.getLeft();
        if (state == MPIMessage.ReceivedState.INIT) {
          currentMessage.incrementRefCount();
        }
        if (state == MPIMessage.ReceivedState.DOWN || state == MPIMessage.ReceivedState.INIT) {
          currentMessage.setReceivedState(MPIMessage.ReceivedState.DOWN);
          if (!receiver.passMessageDownstream(object,currentMessage)) {
            break;
          }
          currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
          if (!receiver.receiveMessage(currentMessage,object)) {
            int attempt=updateAttemptMap(receiveMessageAttempts,0,1);
            if (debug && attempt > MAX_ATTEMPTS) {
              LOG.info(String.format("String_Node_Str",executor,attempt));
            }
            break;
          }
 else {
            updateAttemptMap(receiveMessageAttempts,0,-1);
          }
          currentMessage.release();
          pendingReceiveMessages.poll();
        }
 else         if (state == MPIMessage.ReceivedState.RECEIVE) {
          currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
          if (!receiver.receiveMessage(currentMessage,object)) {
            int attempt=updateAttemptMap(receiveMessageAttempts,0,1);
            if (debug && attempt > MAX_ATTEMPTS) {
              LOG.info(String.format("String_Node_Str",executor,attempt));
            }
            break;
          }
 else {
            updateAttemptMap(receiveMessageAttempts,0,-1);
          }
          currentMessage.release();
          pendingReceiveMessages.poll();
        }
      }
    }
  }
  finally {
    lock.unlock();
  }
}

Fixed version (ground truth):
/** 
 * Progress the serializations
 */
public void progress(){
  lock.lock();
  try {
    for (    Map.Entry<Integer,ArrayBlockingQueue<Pair<Object,MPISendMessage>>> e : pendingSendMessagesPerSource.entrySet()) {
      Queue<Pair<Object,MPISendMessage>> pendingSendMessages=e.getValue();
      boolean canProgress=true;
      while (pendingSendMessages.size() > 0 && canProgress) {
        Pair<Object,MPISendMessage> pair=pendingSendMessages.peek();
        MPISendMessage mpiSendMessage=pair.getValue();
        Object messageObject=pair.getKey();
        if (mpiSendMessage.serializedState() == MPISendMessage.SendState.INIT) {
          for (          Integer i : mpiSendMessage.getInternalSends()) {
            boolean receiveAccepted;
            if (isStoreBased && isLastReceiver) {
              serializeAndWriteToMemoryManager(mpiSendMessage,messageObject);
              receiveAccepted=receiver.receiveSendInternally(mpiSendMessage.getSource(),i,mpiSendMessage.getPath(),mpiSendMessage.getFlags(),operationMemoryManager);
            }
 else {
              receiveAccepted=receiver.receiveSendInternally(mpiSendMessage.getSource(),i,mpiSendMessage.getPath(),mpiSendMessage.getFlags(),messageObject);
            }
            if (!receiveAccepted) {
              canProgress=false;
              int attempt=updateAttemptMap(sendMessageInternalAttempts,i,1);
              if (debug && attempt > MAX_ATTEMPTS) {
                LOG.info(String.format("String_Node_Str",executor,attempt));
              }
              break;
            }
 else {
              updateAttemptMap(sendMessageInternalAttempts,i,-1);
            }
          }
          if (canProgress) {
            mpiSendMessage.setSendState(MPISendMessage.SendState.SENT_INTERNALLY);
          }
        }
        if (canProgress) {
          if (mpiSendMessage.getExternalSends().size() == 0) {
            pendingSendMessages.poll();
            continue;
          }
          MPISendMessage message=(MPISendMessage)messageSerializer.build(pair.getKey(),mpiSendMessage);
          if (message.serializedState() == MPISendMessage.SendState.SERIALIZED) {
            List<Integer> exRoutes=new ArrayList<>(mpiSendMessage.getExternalSends());
            int startOfExternalRouts=mpiSendMessage.getAcceptedExternalSends();
            int noOfExternalSends=startOfExternalRouts;
            for (int i=startOfExternalRouts; i < exRoutes.size(); i++) {
              boolean sendAccepted=sendMessageToTarget(message.getMPIMessage(),exRoutes.get(i));
              if (!sendAccepted) {
                canProgress=false;
                sendMessageToTargetAttempts++;
                if (sendMessageToTargetAttempts > MAX_ATTEMPTS) {
                  LOG.info(String.format("String_Node_Str",executor,sendMessageToTargetAttempts));
                }
                break;
              }
 else {
                if (sendMessageToTargetAttempts > 0) {
                  sendMessageToTargetAttempts--;
                }
                mpiSendMessage.incrementAcceptedExternalSends();
                noOfExternalSends++;
              }
            }
            if (noOfExternalSends == exRoutes.size()) {
              mpiSendMessage.setSendState(MPISendMessage.SendState.FINISHED);
              pendingSendMessages.poll();
            }
          }
 else {
            break;
          }
        }
      }
    }
    for (    Map.Entry<Integer,Queue<MPIMessage>> it : pendingReceiveDeSerializations.entrySet()) {
      MPIMessage currentMessage=it.getValue().poll();
      if (currentMessage == null) {
        continue;
      }
      int id=currentMessage.getOriginatingId();
      if (isStoreBased && isLastReceiver) {
        LOG.info("String_Node_Str");
        writeToMemoryManager(currentMessage);
        currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
        if (!receiver.receiveMessage(currentMessage,operationMemoryManager)) {
          int attempt=updateAttemptMap(receiveMessageAttempts,id,1);
          if (debug && attempt > MAX_ATTEMPTS) {
            LOG.info(String.format("String_Node_Str",executor,attempt));
          }
          continue;
        }
 else {
          updateAttemptMap(receiveMessageAttempts,id,-1);
        }
      }
 else {
        Object object=messageDeSerializer.build(currentMessage,currentMessage.getHeader().getEdge());
        Queue<Pair<Object,MPIMessage>> pendingReceiveMessages=pendingReceiveMessagesPerSource.get(id);
        currentMessage.setReceivedState(MPIMessage.ReceivedState.INIT);
        if (pendingReceiveMessages.size() > 0) {
          if (!pendingReceiveMessages.offer(new ImmutablePair<>(object,currentMessage))) {
            throw new RuntimeException(executor + "String_Node_Str" + pendingReceiveMessages.size());
          }
        }
 else {
          currentMessage.incrementRefCount();
          currentMessage.setReceivedState(MPIMessage.ReceivedState.DOWN);
          if (!receiver.passMessageDownstream(object,currentMessage)) {
            if (!pendingReceiveMessages.offer(new ImmutablePair<>(object,currentMessage))) {
              throw new RuntimeException(executor + "String_Node_Str" + pendingReceiveMessages.size());
            }
            continue;
          }
          currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
          if (!receiver.receiveMessage(currentMessage,object)) {
            if (!pendingReceiveMessages.offer(new ImmutablePair<>(object,currentMessage))) {
              throw new RuntimeException(executor + "String_Node_Str" + pendingReceiveMessages.size());
            }
            int attempt=updateAttemptMap(receiveMessageAttempts,id,1);
            if (debug && attempt > MAX_ATTEMPTS) {
              LOG.info(String.format("String_Node_Str",executor,attempt));
            }
            continue;
          }
 else {
            updateAttemptMap(receiveMessageAttempts,id,-1);
          }
          currentMessage.release();
        }
      }
    }
    for (    Map.Entry<Integer,Queue<Pair<Object,MPIMessage>>> e : pendingReceiveMessagesPerSource.entrySet()) {
      Queue<Pair<Object,MPIMessage>> pendingReceiveMessages=e.getValue();
      while (pendingReceiveMessages.size() > 0) {
        Pair<Object,MPIMessage> pair=pendingReceiveMessages.peek();
        MPIMessage.ReceivedState state=pair.getRight().getReceivedState();
        MPIMessage currentMessage=pair.getRight();
        Object object=pair.getLeft();
        if (state == MPIMessage.ReceivedState.INIT) {
          currentMessage.incrementRefCount();
        }
        if (state == MPIMessage.ReceivedState.DOWN || state == MPIMessage.ReceivedState.INIT) {
          currentMessage.setReceivedState(MPIMessage.ReceivedState.DOWN);
          if (!receiver.passMessageDownstream(object,currentMessage)) {
            break;
          }
          currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
          if (!receiver.receiveMessage(currentMessage,object)) {
            int attempt=updateAttemptMap(receiveMessageAttempts,0,1);
            if (debug && attempt > MAX_ATTEMPTS) {
              LOG.info(String.format("String_Node_Str",executor,attempt));
            }
            break;
          }
 else {
            updateAttemptMap(receiveMessageAttempts,0,-1);
          }
          currentMessage.release();
          pendingReceiveMessages.poll();
        }
 else         if (state == MPIMessage.ReceivedState.RECEIVE) {
          currentMessage.setReceivedState(MPIMessage.ReceivedState.RECEIVE);
          if (!receiver.receiveMessage(currentMessage,object)) {
            int attempt=updateAttemptMap(receiveMessageAttempts,0,1);
            if (debug && attempt > MAX_ATTEMPTS) {
              LOG.info(String.format("String_Node_Str",executor,attempt));
            }
            break;
          }
 else {
            updateAttemptMap(receiveMessageAttempts,0,-1);
          }
          currentMessage.release();
          pendingReceiveMessages.poll();
        }
      }
    }
  }
  finally {
    lock.unlock();
  }
}