Program: 132148
Project: 132148
Buggy source:
/** 
 * This method finds out name of the Service Function closest to Service Function preSfName per serviceFunctionType. <p>
 * @param serviceFunctionType Type of Service Function to find
 * @param preSfName Name of previous Service Function in Service Function Path
 * @param sfcProviderGraph Topology graph comprised of all the SFs and SFFs
 * @return String Name of the Service Function with type serviceFunctionType
 */
private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType,String preSfName,SfcProviderGraph sfcProviderGraph){
  String sfcProviderTopologyNodeName=null;
  List<SftServiceFunctionName> sftServiceFunctionNameList=serviceFunctionType.getSftServiceFunctionName();
  if (sftServiceFunctionNameList.size() == 0) {
    LOG.debug("String_Node_Str",serviceFunctionType);
    return null;
  }
  if (preSfName == null) {
    Random rad=new Random();
    sfcProviderTopologyNodeName=sftServiceFunctionNameList.get(rad.nextInt(sftServiceFunctionNameList.size())).getName();
    LOG.debug("String_Node_Str",sfcProviderTopologyNodeName);
    return sfcProviderTopologyNodeName;
  }
  SfcProviderTopologyNode preSfcProviderTopologyNode=sfcProviderGraph.getNode(preSfName);
  if (preSfcProviderTopologyNode == null) {
    LOG.debug("String_Node_Str",preSfName);
    return null;
  }
  int minLength=Integer.MAX_VALUE;
  int length=0;
  sfcProviderTopologyNodeName=null;
  for (  SftServiceFunctionName sftServiceFunctionName : sftServiceFunctionNameList) {
    String curSfName=sftServiceFunctionName.getName();
    List<SfcProviderTopologyNode> sfcProviderTopologyNodeList=sfcProviderGraph.getShortestPath(preSfName,curSfName);
    length=sfcProviderTopologyNodeList.size();
    if (length <= 1) {
      LOG.debug("String_Node_Str",preSfName,curSfName);
      continue;
    }
    if (minLength > length) {
      minLength=length;
      sfcProviderTopologyNodeName=curSfName;
    }
  }
  if (sfcProviderTopologyNodeName == null) {
    LOG.debug("String_Node_Str",preSfName);
  }
  return sfcProviderTopologyNodeName;
}

Fixed version (ground truth):
/** 
 * This method finds out name of the Service Function closest to Service Function preSfName per serviceFunctionType. <p>
 * @param serviceFunctionType Type of Service Function to find
 * @param preSfName Name of previous Service Function in Service Function Path
 * @param sfcProviderGraph Topology graph comprised of all the SFs and SFFs
 * @return String Name of the Service Function with type serviceFunctionType
 */
private String getServiceFunctionByType(ServiceFunctionType serviceFunctionType,String preSfName,SfcProviderGraph sfcProviderGraph){
  String sfcProviderTopologyNodeName=null;
  List<SftServiceFunctionName> sftServiceFunctionNameList=serviceFunctionType.getSftServiceFunctionName();
  int maxTries=sftServiceFunctionNameList.size();
  if (sftServiceFunctionNameList.size() == 0) {
    LOG.debug("String_Node_Str",serviceFunctionType);
    return null;
  }
  if (preSfName == null) {
    Random rad=new Random();
    int start=rad.nextInt(sftServiceFunctionNameList.size());
    SfcProviderTopologyNode firstHopNode=null;
    while (maxTries > 0) {
      sfcProviderTopologyNodeName=sftServiceFunctionNameList.get(start).getName();
      firstHopNode=sfcProviderGraph.getNode(sfcProviderTopologyNodeName);
      if (firstHopNode != null) {
        break;
      }
 else {
        LOG.debug("String_Node_Str",sfcProviderTopologyNodeName);
        sfcProviderTopologyNodeName=null;
        start=(start + 1) % sftServiceFunctionNameList.size();
        maxTries--;
      }
    }
    LOG.debug("String_Node_Str",sfcProviderTopologyNodeName);
    return sfcProviderTopologyNodeName;
  }
  SfcProviderTopologyNode preSfcProviderTopologyNode=sfcProviderGraph.getNode(preSfName);
  if (preSfcProviderTopologyNode == null) {
    LOG.debug("String_Node_Str",preSfName);
    return null;
  }
  int minLength=Integer.MAX_VALUE;
  int length=0;
  sfcProviderTopologyNodeName=null;
  for (  SftServiceFunctionName sftServiceFunctionName : sftServiceFunctionNameList) {
    String curSfName=sftServiceFunctionName.getName();
    SfcProviderTopologyNode curSfcProviderTopologyNode=sfcProviderGraph.getNode(curSfName);
    if (curSfcProviderTopologyNode == null) {
      continue;
    }
    List<SfcProviderTopologyNode> sfcProviderTopologyNodeList=sfcProviderGraph.getShortestPath(preSfName,curSfName);
    length=sfcProviderTopologyNodeList.size();
    if (length <= 1) {
      LOG.debug("String_Node_Str",preSfName,curSfName);
      continue;
    }
    if (minLength > length) {
      minLength=length;
      sfcProviderTopologyNodeName=curSfName;
    }
  }
  if (sfcProviderTopologyNodeName == null) {
    LOG.debug("String_Node_Str",preSfName);
  }
  return sfcProviderTopologyNodeName;
}