Program: 172858
Project: 172858
Buggy source:
private boolean sendProgress(Queue<Pair<Object,OutMessage>> pendingSendMessages,int sendId){
  boolean canProgress=true;
  while (pendingSendMessages.size() > 0 && canProgress) {
    Pair<Object,OutMessage> pair=pendingSendMessages.peek();
    OutMessage outMessage=pair.getValue();
    Object messageObject=pair.getKey();
    if (outMessage.serializedState() == OutMessage.SendState.INIT) {
      int startOfInternalRouts=outMessage.getAcceptedInternalSends();
      List<Integer> inRoutes=new ArrayList<>(outMessage.getInternalSends());
      for (int i=startOfInternalRouts; i < outMessage.getInternalSends().size(); i++) {
        boolean receiveAccepted;
        lock.lock();
        try {
          receiveAccepted=receiver.receiveSendInternally(outMessage.getSource(),inRoutes.get(i),outMessage.getPath(),outMessage.getFlags(),messageObject);
        }
  finally {
          lock.unlock();
        }
        if (!receiveAccepted) {
          canProgress=false;
          break;
        }
        outMessage.incrementAcceptedInternalSends();
      }
      if (canProgress) {
        outMessage.setSendState(OutMessage.SendState.SENT_INTERNALLY);
      }
    }
    if (canProgress) {
      if (outMessage.getExternalSends().size() == 0) {
        pendingSendMessages.poll();
        continue;
      }
      OutMessage message=(OutMessage)messageSerializer.get(sendId).build(pair.getKey(),outMessage);
      if (message.serializedState() == OutMessage.SendState.SERIALIZED) {
        List<Integer> exRoutes=new ArrayList<>(outMessage.getExternalSends());
        int startOfExternalRouts=outMessage.getAcceptedExternalSends();
        int noOfExternalSends=startOfExternalRouts;
        lock.lock();
        try {
          if (!outMessage.isOutCountUpdated()) {
            outMessage.getChannelMessage().incrementRefCount(outMessage.getExternalSends().size());
            outMessage.setOutCountUpdated(true);
          }
          for (int i=startOfExternalRouts; i < exRoutes.size(); i++) {
            boolean sendAccepted=sendMessageToTarget(message.getChannelMessage(),exRoutes.get(i));
            if (!sendAccepted) {
              canProgress=false;
              break;
            }
 else {
              noOfExternalSends=outMessage.incrementAcceptedExternalSends();
              externalSendsPending.incrementAndGet();
            }
          }
        }
  finally {
          lock.unlock();
        }
        if (noOfExternalSends == exRoutes.size()) {
          outMessage.setSendState(OutMessage.SendState.FINISHED);
          pendingSendMessages.poll();
        }
      }
 else       if (message.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED) {
        if (message.getChannelMessage().getBuffers().size() == 0) {
          break;
        }
        List<Integer> exRoutes=new ArrayList<>(outMessage.getExternalSends());
        int startOfExternalRouts=outMessage.getAcceptedExternalSends();
        ChannelMessage sendCopy=createChannelMessageCopy(message.getChannelMessage());
        lock.lock();
        try {
          if (!outMessage.isOutCountUpdated()) {
            sendCopy.incrementRefCount(outMessage.getExternalSends().size());
            outMessage.setOutCountUpdated(true);
          }
          for (int i=startOfExternalRouts; i < exRoutes.size(); i++) {
            boolean sendAccepted=sendMessageToTarget(sendCopy,exRoutes.get(i));
            if (!sendAccepted) {
              canProgress=false;
              break;
            }
          }
        }
  finally {
          outMessage.setOutCountUpdated(false);
          lock.unlock();
        }
      }
 else {
        break;
      }
    }
  }
  return canProgress;
}

Fixed version (ground truth):
private boolean sendProgress(Queue<Pair<Object,OutMessage>> pendingSendMessages,int sendId){
  boolean canProgress=true;
  while (pendingSendMessages.size() > 0 && canProgress) {
    Pair<Object,OutMessage> pair=pendingSendMessages.peek();
    OutMessage outMessage=pair.getValue();
    Object messageObject=pair.getKey();
    if (outMessage.serializedState() == OutMessage.SendState.INIT) {
      int startOfInternalRouts=outMessage.getAcceptedInternalSends();
      List<Integer> inRoutes=new ArrayList<>(outMessage.getInternalSends());
      for (int i=startOfInternalRouts; i < outMessage.getInternalSends().size(); i++) {
        boolean receiveAccepted;
        lock.lock();
        try {
          receiveAccepted=receiver.receiveSendInternally(outMessage.getSource(),inRoutes.get(i),outMessage.getPath(),outMessage.getFlags(),messageObject);
        }
  finally {
          lock.unlock();
        }
        if (!receiveAccepted) {
          canProgress=false;
          break;
        }
        outMessage.incrementAcceptedInternalSends();
      }
      if (canProgress) {
        outMessage.setSendState(OutMessage.SendState.SENT_INTERNALLY);
      }
    }
    if (canProgress) {
      if (outMessage.getExternalSends().size() == 0) {
        pendingSendMessages.poll();
        continue;
      }
      OutMessage message=(OutMessage)messageSerializer.get(sendId).build(pair.getKey(),outMessage);
      if (message.serializedState() == OutMessage.SendState.SERIALIZED) {
        List<Integer> exRoutes=new ArrayList<>(outMessage.getExternalSends());
        int startOfExternalRouts=outMessage.getAcceptedExternalSends();
        int noOfExternalSends=startOfExternalRouts;
        lock.lock();
        try {
          if (!outMessage.isOutCountUpdated()) {
            outMessage.getChannelMessage().incrementRefCount(outMessage.getExternalSends().size());
            outMessage.setOutCountUpdated(true);
          }
          for (int i=startOfExternalRouts; i < exRoutes.size(); i++) {
            boolean sendAccepted=sendMessageToTarget(message.getChannelMessage(),exRoutes.get(i));
            if (!sendAccepted) {
              canProgress=false;
              break;
            }
 else {
              noOfExternalSends=outMessage.incrementAcceptedExternalSends();
              externalSendsPending.incrementAndGet();
            }
          }
        }
  finally {
          lock.unlock();
        }
        if (noOfExternalSends == exRoutes.size()) {
          outMessage.setSendState(OutMessage.SendState.FINISHED);
          pendingSendMessages.poll();
        }
      }
 else       if (message.serializedState() == OutMessage.SendState.PARTIALLY_SERIALIZED) {
        if (message.getChannelMessage().getBuffers().size() == 0) {
          break;
        }
        List<Integer> exRoutes=new ArrayList<>(outMessage.getExternalSends());
        int startOfExternalRouts=outMessage.getAcceptedExternalSends();
        ChannelMessage sendCopy=createChannelMessageCopy(message.getChannelMessage());
        lock.lock();
        try {
          if (!outMessage.isOutCountUpdated()) {
            sendCopy.incrementRefCount(outMessage.getExternalSends().size());
            outMessage.setOutCountUpdated(true);
          }
          for (int i=startOfExternalRouts; i < exRoutes.size(); i++) {
            boolean sendAccepted=sendMessageToTarget(sendCopy,exRoutes.get(i));
            if (!sendAccepted) {
              canProgress=false;
              break;
            }
 else {
              externalSendsPending.incrementAndGet();
            }
          }
        }
  finally {
          outMessage.setOutCountUpdated(false);
          lock.unlock();
        }
      }
 else {
        break;
      }
    }
  }
  return canProgress;
}