Program: 61475
Project: 61475
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){
  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<>());
  int maxNumberCombinations=ConfigurationProperties.getPropertyInt("String_Node_Str");
  int numberTotalComb=1;
  int max=-1;
  for (  VarAccessWrapper currentVar : varsNamesToCombine) {
    List<CtVariable> mapped=mappedVars.get(currentVar);
    int numberCompVar=mapped.size();
    if (numberCompVar > max)     max=numberCompVar;
    logger.debug(String.format("String_Node_Str",currentVar.getVar().getVariable().getSimpleName(),numberCompVar));
    numberTotalComb*=numberCompVar;
  }
  logger.debug("String_Node_Str" + numberTotalComb);
  double maxPerVar=Math.pow(numberTotalComb,1.0 / varsNamesToCombine.size());
  double maxPerVarLimit=Math.pow(maxNumberCombinations,1.0 / varsNamesToCombine.size());
  logger.debug(String.format("String_Node_Str",maxPerVar,maxPerVarLimit));
  for (  VarAccessWrapper currentVar : varsNamesToCombine) {
    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());
    }
    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)maxPerVarLimit)) {
        break;
      }
    }
    allCombinations=generationCombinations;
  }
  allCombinations=allCombinations.stream().filter(e -> !e.isEmpty()).collect(Collectors.toList());
  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){
  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<>());
  int maxNumberCombinations=ConfigurationProperties.getPropertyInt("String_Node_Str");
  long numberTotalComb=1;
  int max=-1;
  Set<String> vars=new HashSet<>();
  for (  VarAccessWrapper currentVar : varsNamesToCombine) {
    if (vars.contains(currentVar.getVar().getVariable().getSimpleName())) {
      continue;
    }
    vars.add(currentVar.getVar().getVariable().getSimpleName());
    List<CtVariable> mapped=mappedVars.get(currentVar);
    int numberCompVar=mapped.size();
    if (numberCompVar > max)     max=numberCompVar;
    logger.debug(String.format("String_Node_Str",currentVar.getVar().getVariable().getSimpleName(),numberCompVar));
    numberTotalComb*=numberCompVar;
  }
  logger.debug("String_Node_Str" + numberTotalComb);
  double maxPerVar=Math.pow(numberTotalComb,1.0 / varsNamesToCombine.size());
  double maxPerVarLimit=Math.pow(maxNumberCombinations,1.0 / varsNamesToCombine.size());
  if (numberTotalComb < maxNumberCombinations) {
    maxPerVarLimit=max;
  }
  logger.debug(String.format("String_Node_Str",maxPerVar,maxPerVarLimit));
  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());
    }
    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)maxPerVarLimit)) {
        break;
      }
    }
    allCombinations=generationCombinations;
  }
  allCombinations=allCombinations.stream().filter(e -> !e.isEmpty()).collect(Collectors.toList());
  logger.debug("String_Node_Str" + allCombinations.size());
  return allCombinations;
}