Program: 61467
Project: 61467
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,boolean random,NGramManager manager){
  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];
  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 (random) {
      Collections.shuffle(sortedVariables,RandomManager.getRandom());
    }
 else     if (manager != null) {
      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)manager.getNgglobal().ngrams[1].getProbabilies().get(s1);
          Double p2=(Double)manager.getNgglobal().ngrams[1].getProbabilies().get(s2);
          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;
  }
  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());
  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,boolean random,NGramManager manager){
  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];
  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 (random) {
      Collections.shuffle(sortedVariables,RandomManager.getRandom());
    }
 else     if (manager != null) {
      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)manager.getNgglobal().ngrams[1].getProbabilies().get(s1);
          Double p2=(Double)manager.getNgglobal().ngrams[1].getProbabilies().get(s2);
          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;
  }
  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());
  return allCombinations;
}