Program: 130244
Project: 130244
Buggy source:
/** 
 * This is the class which analyzes the logs created after instrumentation and returns cluster-wide result in form of a JSON String.
 * @param dirPath the path of directory where log files are stored
 * @return String the JSON String containing the final result of loganalysis
 * @throws ExecutionException
 * @throws JumbuneException the HTF exception
 * @throws IOException
 */
public final String processLogs(final String dirPath,boolean isPartitionerEnabled,Loader loader,HadoopJobCounters hadoopJobCounters) throws JumbuneException, InterruptedException, ExecutionException, IOException {
  InputStream in=ConfigurationUtil.readFile(dirPath.substring(0,dirPath.indexOf("String_Node_Str")) + SYMBOL_TABLE_NAME);
  if (in == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  props.load(in);
  LOGGER.debug("String_Node_Str");
  Map<String,Map<String,List<String>>> mrChainSortedMap=createNodeFileMap(dirPath);
  final int numOfNodes=nodeFileMap.size();
  if (maxNumOfThreads > numOfNodes || maxNumOfThreads == 0) {
    maxNumOfThreads=numOfNodes;
  }
  LOGGER.debug("String_Node_Str" + maxNumOfThreads + "String_Node_Str");
  LOGGER.debug("String_Node_Str");
  ExecutorService pool=null;
  try {
    pool=Executors.newFixedThreadPool(maxNumOfThreads);
    final List<Future<Map<String,JobBean>>> analysisResults=new ArrayList<Future<Map<String,JobBean>>>();
    Callable<Map<String,JobBean>> nodeAnalysisTask;
    for (    Map.Entry<String,Map<String,List<String>>> nodeFilePairs : nodeFileMap.entrySet()) {
      nodeAnalysisTask=new LogAnalyzerCallable(nodeFilePairs.getKey(),nodeFilePairs.getValue());
      analysisResults.add(pool.submit(nodeAnalysisTask));
    }
    Map<String,JobBean> nodeAnalysisResult;
    final Iterator<Future<Map<String,JobBean>>> iterator=analysisResults.iterator();
    while (iterator.hasNext()) {
      nodeAnalysisResult=(iterator.next()).get();
      addToLogMap(nodeAnalysisResult);
      iterator.remove();
    }
  }
  finally {
    if (pool != null) {
      pool.shutdown();
    }
    if (in != null) {
      in.close();
    }
  }
  DebugAnalysisBean debugAnalysisBean=new DebugAnalysisBean();
  debugAnalysisBean.setLogMap(logMap);
  if (jobChain != null) {
    setJobChainCounters();
    debugAnalysisBean.setJobChain(jobChain);
  }
  if (mrChainSortedMap != null) {
    Map<String,Map<String,List<ChainingInfoBean>>> mrChain=setMRChainCounters(mrChainSortedMap);
    debugAnalysisBean.setMrChain(mrChain);
  }
  if (isPartitionerEnabled) {
    Map<String,List<PartitionerInfoBean>> partitionerMap=getPartitionCounters(mrChainSortedMap);
    debugAnalysisBean.setPartitionerMap(partitionerMap);
  }
  YamlLoader yamlLoader=(YamlLoader)loader;
  List<Validation> validations=yamlLoader.getRegex();
  for (  Validation validation : validations) {
    regexValidationsClasses.add(validation.getClassname());
  }
  validations=yamlLoader.getUserValidations();
  for (  Validation validation : validations) {
    userDefValidationClasses.add(validation.getClassname());
  }
  List<String> classesRequiredInResult=new ArrayList<String>(regexValidationsClasses);
  classesRequiredInResult.addAll(userDefValidationClasses);
  Map<String,JobBean> logMap=debugAnalysisBean.getLogMap();
  Set<String> logMapKeys=logMap.keySet();
  List<String> jobList=new ArrayList<String>();
  List<JobCounterBean> jobCounterBeans=hadoopJobCounters.getJobCounterBeans();
  for (  JobCounterBean jobCounterBean : jobCounterBeans) {
    jobList.add(jobCounterBean.getJobName());
  }
  for (  String jobId : logMapKeys) {
    Set<String> jobMapKeys=logMap.get(jobId).getJobMap().keySet();
    Iterator<String> jobKeys=jobMapKeys.iterator();
    String mapperReducerName=null;
    while (jobKeys.hasNext()) {
      mapperReducerName=jobKeys.next();
      if (!classesRequiredInResult.contains(mapperReducerName)) {
        jobKeys.remove();
      }
    }
    if (jobList.contains(jobId)) {
      logMap.get(jobId).setTotalInputKeys(Integer.valueOf(hadoopJobCounters.getValueByJobNameAndProperty(jobCounterBeans,jobId,Constants.MAP_INPUT_RECORD)));
      logMap.get(jobId).setTotalContextWrites(Integer.valueOf(hadoopJobCounters.getValueByJobNameAndProperty(jobCounterBeans,jobId,Constants.REDUCE_OUTPUT_RECORD)));
    }
  }
  Map<String,DebugAnalysisBean> debugAnalysisMap=new HashMap<String,DebugAnalysisBean>();
  debugAnalysisMap.put(LPConstants.DEBUG_ANALYSIS,debugAnalysisBean);
  return getJsonFromDebugReport(debugAnalysisMap,debugAnalysisBean);
}

Fixed version (ground truth):
/** 
 * This is the class which analyzes the logs created after instrumentation and returns cluster-wide result in form of a JSON String.
 * @param dirPath the path of directory where log files are stored
 * @return String the JSON String containing the final result of loganalysis
 * @throws ExecutionException
 * @throws JumbuneException the HTF exception
 * @throws IOException
 */
public final String processLogs(final String dirPath,boolean isPartitionerEnabled,Loader loader,HadoopJobCounters hadoopJobCounters) throws JumbuneException, InterruptedException, ExecutionException, IOException {
  InputStream in=ConfigurationUtil.readFile(dirPath.substring(0,dirPath.indexOf("String_Node_Str")) + SYMBOL_TABLE_NAME);
  if (in == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  props.load(in);
  LOGGER.debug("String_Node_Str");
  Map<String,Map<String,List<String>>> mrChainSortedMap=createNodeFileMap(dirPath);
  final int numOfNodes=nodeFileMap.size();
  if (maxNumOfThreads > numOfNodes || maxNumOfThreads == 0) {
    maxNumOfThreads=numOfNodes;
  }
  LOGGER.debug("String_Node_Str" + maxNumOfThreads + "String_Node_Str");
  LOGGER.debug("String_Node_Str");
  ExecutorService pool=null;
  try {
    pool=Executors.newFixedThreadPool(maxNumOfThreads);
    final List<Future<Map<String,JobBean>>> analysisResults=new ArrayList<Future<Map<String,JobBean>>>();
    Callable<Map<String,JobBean>> nodeAnalysisTask;
    for (    Map.Entry<String,Map<String,List<String>>> nodeFilePairs : nodeFileMap.entrySet()) {
      nodeAnalysisTask=new LogAnalyzerCallable(nodeFilePairs.getKey(),nodeFilePairs.getValue());
      analysisResults.add(pool.submit(nodeAnalysisTask));
    }
    Map<String,JobBean> nodeAnalysisResult;
    final Iterator<Future<Map<String,JobBean>>> iterator=analysisResults.iterator();
    while (iterator.hasNext()) {
      nodeAnalysisResult=(iterator.next()).get();
      addToLogMap(nodeAnalysisResult);
      iterator.remove();
    }
  }
  finally {
    if (pool != null) {
      pool.shutdown();
    }
    if (in != null) {
      in.close();
    }
  }
  DebugAnalysisBean debugAnalysisBean=new DebugAnalysisBean();
  debugAnalysisBean.setLogMap(logMap);
  if (jobChain != null) {
    setJobChainCounters();
    debugAnalysisBean.setJobChain(jobChain);
  }
  if (mrChainSortedMap != null) {
    Map<String,Map<String,List<ChainingInfoBean>>> mrChain=setMRChainCounters(mrChainSortedMap);
    debugAnalysisBean.setMrChain(mrChain);
  }
  if (isPartitionerEnabled) {
    Map<String,List<PartitionerInfoBean>> partitionerMap=getPartitionCounters(mrChainSortedMap);
    debugAnalysisBean.setPartitionerMap(partitionerMap);
  }
  YamlLoader yamlLoader=(YamlLoader)loader;
  List<Validation> validations=yamlLoader.getRegex();
  for (  Validation validation : validations) {
    regexValidationsClasses.add(validation.getClassname());
  }
  validations=yamlLoader.getUserValidations();
  for (  Validation validation : validations) {
    userDefValidationClasses.add(validation.getClassname());
  }
  List<String> classesRequiredInResult=new ArrayList<String>(regexValidationsClasses);
  classesRequiredInResult.addAll(userDefValidationClasses);
  Map<String,JobBean> logMap=debugAnalysisBean.getLogMap();
  Set<String> logMapKeys=logMap.keySet();
  List<String> jobList=new ArrayList<String>();
  List<JobCounterBean> jobCounterBeans=hadoopJobCounters.getJobCounterBeans();
  for (  JobCounterBean jobCounterBean : jobCounterBeans) {
    jobList.add(jobCounterBean.getJobName());
  }
  for (  String jobId : logMapKeys) {
    Set<String> jobMapKeys=logMap.get(jobId).getJobMap().keySet();
    Iterator<String> jobKeys=jobMapKeys.iterator();
    String mapperReducerName=null;
    while (jobKeys.hasNext()) {
      mapperReducerName=jobKeys.next();
      if (!classesRequiredInResult.contains(mapperReducerName)) {
        jobKeys.remove();
      }
    }
    if (jobList.contains(jobId)) {
      logMap.get(jobId).setTotalInputKeys(Integer.valueOf(hadoopJobCounters.getValueByJobNameAndProperty(jobId,Constants.MAP_INPUT_RECORD)));
      logMap.get(jobId).setTotalContextWrites(Integer.valueOf(hadoopJobCounters.getValueByJobNameAndProperty(jobId,Constants.REDUCE_OUTPUT_RECORD)));
    }
  }
  Map<String,DebugAnalysisBean> debugAnalysisMap=new HashMap<String,DebugAnalysisBean>();
  debugAnalysisMap.put(LPConstants.DEBUG_ANALYSIS,debugAnalysisBean);
  return getJsonFromDebugReport(debugAnalysisMap,debugAnalysisBean);
}