Program: 61439
Project: 61439
Buggy source:
/** 
 * Method that finds all combination of variables mappings Ex: if var 'a' can be mapped to a1 and a2, and var 'b' to b1 and b2, the method return all combinations (a1,b1), (a2,b1), (a1,b2), (a2,b2)
 * @param mappedVars map of variables (out-of-scope) and candidate replacements of
 * @return
 */
public static List<Map<String,CtVariable>> findAllVarMappingCombination(Map<VarAccessWrapper,List<CtVariable>> mappedVars,NGramManager managerngram){
  if (mappedVars.isEmpty()) {
    return new ArrayList<Map<String,CtVariable>>();
  }
  List<VarAccessWrapper> varsNamesToCombine=new ArrayList<>(mappedVars.keySet());
  List<Map<String,CtVariable>> allCombinations=new ArrayList<>();
  allCombinations.add(new TreeMap<>());
  Number[] maxValues=getMaxCombination(mappedVars,varsNamesToCombine);
  long numberTotalComb=(long)maxValues[0];
  double maxPerVarLimit=(double)maxValues[1];
  try {
    for (    VarAccessWrapper currentVar : varsNamesToCombine) {
      if (allCombinations.size() > 0 && allCombinations.get(0).containsKey(currentVar.getVar().getVariable().getSimpleName())) {
        logger.debug("String_Node_Str" + currentVar.getVar().getVariable().getSimpleName());
        continue;
      }
      List<Map<String,CtVariable>> generationCombinations=new ArrayList<>();
      List<CtVariable> mapped=mappedVars.get(currentVar);
      List<CtVariable> sortedVariables=new ArrayList<>(mapped);
      if (managerngram == null) {
        logger.debug("String_Node_Str");
        Collections.shuffle(sortedVariables,RandomManager.getRandom());
      }
 else {
        logger.debug("String_Node_Str");
        Collections.sort(sortedVariables,new Comparator<CtVariable>(){
          @Override public int compare(          CtVariable v1,          CtVariable v2){
            String s1=v1.getSimpleName();
            String s2=v2.getSimpleName();
            Double p1=(Double)managerngram.getNgglobal().ngrams[1].getProbabilies().get(s1);
            Double p2=(Double)managerngram.getNgglobal().ngrams[1].getProbabilies().get(s2);
            if (p1 == null && p2 == null) {
              return 0;
            }
            if (p1 == null) {
              logger.error("String_Node_Str" + s1);
              return 1;
            }
            if (p2 == null) {
              logger.error("String_Node_Str" + s2);
              return -1;
            }
            return Double.compare(p2,p1);
          }
        }
);
      }
      int varsAnalyzed=0;
      for (      CtVariable varFromMap : sortedVariables) {
        for (        Map<String,CtVariable> previousCombination : allCombinations) {
          Map<String,CtVariable> newCombination=new TreeMap<>(previousCombination);
          newCombination.put(currentVar.getVar().getVariable().getSimpleName(),varFromMap);
          generationCombinations.add(newCombination);
        }
        varsAnalyzed++;
        if (varsAnalyzed >= ((int)(Math.ceil(maxPerVarLimit)))) {
          break;
        }
      }
      allCombinations=generationCombinations;
    }
  }
 catch (  Throwable e) {
    logger.error("String_Node_Str" + mappedVars.size() + "String_Node_Str"+ Arrays.toString(maxValues));
    logger.error(e);
    return new ArrayList<Map<String,CtVariable>>();
  }
  allCombinations=allCombinations.stream().filter(e -> !e.isEmpty()).collect(Collectors.toList());
  int maxNumberCombinations=ConfigurationProperties.getPropertyInt("String_Node_Str");
  logger.debug("String_Node_Str" + allCombinations.size());
  if (allCombinations.size() > maxNumberCombinations) {
    allCombinations=allCombinations.subList(0,maxNumberCombinations);
  }
  logger.debug("String_Node_Str" + allCombinations.size());
  for (  Map<String,CtVariable> map : allCombinations) {
    if (map.keySet().size() != varsNamesToCombine.size()) {
    }
  }
  return allCombinations;
}

Fixed version (ground truth):
/** 
 * Method that finds all combination of variables mappings Ex: if var 'a' can be mapped to a1 and a2, and var 'b' to b1 and b2, the method return all combinations (a1,b1), (a2,b1), (a1,b2), (a2,b2)
 * @param mappedVars map of variables (out-of-scope) and candidate replacements of
 * @return
 */
public static List<Map<String,CtVariable>> findAllVarMappingCombination(Map<VarAccessWrapper,List<CtVariable>> mappedVars,NGramManager managerngram){
  if (mappedVars.isEmpty()) {
    return new ArrayList<Map<String,CtVariable>>();
  }
  List<VarAccessWrapper> varsNamesToCombine=new ArrayList<>(mappedVars.keySet());
  List<Map<String,CtVariable>> allCombinations=new ArrayList<>();
  allCombinations.add(new TreeMap<>());
  Number[] maxValues=getMaxCombination(mappedVars,varsNamesToCombine);
  long numberTotalComb=(long)maxValues[0];
  double maxPerVarLimit=(double)maxValues[1];
  try {
    for (    VarAccessWrapper currentVar : varsNamesToCombine) {
      if (allCombinations.size() > 0 && allCombinations.get(0).containsKey(currentVar.getVar().getVariable().getSimpleName())) {
        logger.debug("String_Node_Str" + currentVar.getVar().getVariable().getSimpleName());
        continue;
      }
      List<Map<String,CtVariable>> generationCombinations=new ArrayList<>();
      List<CtVariable> mapped=mappedVars.get(currentVar);
      List<CtVariable> sortedVariables=new ArrayList<>(mapped);
      if (managerngram == null) {
        logger.debug("String_Node_Str" + sortedVariables.size());
        Collections.shuffle(sortedVariables,RandomManager.getRandom());
      }
 else {
        logger.debug("String_Node_Str");
        Collections.sort(sortedVariables,new Comparator<CtVariable>(){
          @Override public int compare(          CtVariable v1,          CtVariable v2){
            String s1=v1.getSimpleName();
            String s2=v2.getSimpleName();
            Double p1=(Double)managerngram.getNgglobal().ngrams[1].getProbabilies().get(s1);
            Double p2=(Double)managerngram.getNgglobal().ngrams[1].getProbabilies().get(s2);
            if (p1 == null && p2 == null) {
              return 0;
            }
            if (p1 == null) {
              logger.error("String_Node_Str" + s1);
              return 1;
            }
            if (p2 == null) {
              logger.error("String_Node_Str" + s2);
              return -1;
            }
            return Double.compare(p2,p1);
          }
        }
);
      }
      int varsAnalyzed=0;
      for (      CtVariable varFromMap : sortedVariables) {
        for (        Map<String,CtVariable> previousCombination : allCombinations) {
          Map<String,CtVariable> newCombination=new TreeMap<>(previousCombination);
          newCombination.put(currentVar.getVar().getVariable().getSimpleName(),varFromMap);
          generationCombinations.add(newCombination);
        }
        varsAnalyzed++;
        if (varsAnalyzed >= ((int)(Math.ceil(maxPerVarLimit)))) {
          break;
        }
      }
      allCombinations=generationCombinations;
    }
  }
 catch (  Throwable e) {
    logger.error("String_Node_Str" + mappedVars.size() + "String_Node_Str"+ Arrays.toString(maxValues));
    logger.error(e);
    return new ArrayList<Map<String,CtVariable>>();
  }
  allCombinations=allCombinations.stream().filter(e -> !e.isEmpty()).collect(Collectors.toList());
  int maxNumberCombinations=ConfigurationProperties.getPropertyInt("String_Node_Str");
  logger.debug("String_Node_Str" + allCombinations.size());
  if (allCombinations.size() > maxNumberCombinations) {
    allCombinations=allCombinations.subList(0,maxNumberCombinations);
  }
  logger.debug("String_Node_Str" + allCombinations.size());
  for (  Map<String,CtVariable> map : allCombinations) {
    if (map.keySet().size() != varsNamesToCombine.size()) {
    }
  }
  return allCombinations;
}