Program: 31637
Project: 31637
Buggy source:
/** 
 * Compute correlation value according to correlation statistics from correlation MR job.
 * @param corrMap CorrelationWritable map read from MR job output file
 * @throws IOException any IOException to write correlation value to csv file.
 */
private void computeCorrValue(SortedMap<Integer,CorrelationWritable> corrMap) throws IOException {
  boolean hasCandidates=CommonUtils.hasCandidateColumns(this.columnConfigList);
  String localCorrelationCsv=super.pathFinder.getLocalCorrelationCsvPath();
  ShifuFileUtils.createFileIfNotExists(localCorrelationCsv,SourceType.LOCAL);
  BufferedWriter writer=null;
  Map<Integer,double[]> finalCorrMap=new HashMap<Integer,double[]>();
  try {
    writer=ShifuFileUtils.getWriter(localCorrelationCsv,SourceType.LOCAL);
    writer.write(getColumnIndexes());
    writer.newLine();
    writer.write(getColumnNames());
    writer.newLine();
    for (    Entry<Integer,CorrelationWritable> entry : corrMap.entrySet()) {
      ColumnConfig xColumnConfig=this.columnConfigList.get(entry.getKey());
      if (xColumnConfig.getColumnFlag() == ColumnFlag.Meta || (hasCandidates && !ColumnFlag.Candidate.equals(xColumnConfig.getColumnFlag()))) {
        continue;
      }
      CorrelationWritable xCw=corrMap.get(entry.getKey());
      double[] corrArray=new double[this.columnConfigList.size()];
      for (int i=0; i < corrArray.length; i++) {
        ColumnConfig yColumnConfig=this.columnConfigList.get(i);
        if (yColumnConfig.getColumnFlag() == ColumnFlag.Meta) {
          continue;
        }
        if (entry.getKey() > i) {
          double[] reverseDoubleArray=finalCorrMap.get(i);
          if (reverseDoubleArray != null) {
            corrArray[i]=reverseDoubleArray[entry.getKey()];
          }
 else {
            corrArray[i]=0d;
          }
          continue;
        }
        double numerator=xCw.getAdjustCount()[i] * xCw.getXySum()[i] - xCw.getAdjustSumX()[i] * xCw.getAdjustSumY()[i];
        double denominator1=Math.sqrt(xCw.getAdjustCount()[i] * xCw.getXxSum()[i] - xCw.getAdjustSumX()[i] * xCw.getAdjustSumX()[i]);
        double denominator2=Math.sqrt(xCw.getAdjustCount()[i] * xCw.getYySum()[i] - xCw.getAdjustSumY()[i] * xCw.getAdjustSumY()[i]);
        if (Double.compare(denominator1,Double.valueOf(0d)) == 0 || Double.compare(denominator2,Double.valueOf(0d)) == 0) {
          corrArray[i]=0d;
        }
 else {
          corrArray[i]=numerator / (denominator1 * denominator2);
        }
      }
      finalCorrMap.put(entry.getKey(),corrArray);
      String corrStr=Arrays.toString(corrArray);
      String adjustCorrStr=corrStr.substring(1,corrStr.length() - 1);
      writer.write(entry.getKey() + "String_Node_Str" + this.columnConfigList.get(entry.getKey()).getColumnName()+ "String_Node_Str"+ adjustCorrStr);
      writer.newLine();
    }
  }
  finally {
    IOUtils.closeQuietly(writer);
  }
}

Fixed version (ground truth):
/** 
 * Compute correlation value according to correlation statistics from correlation MR job.
 * @param corrMap CorrelationWritable map read from MR job output file
 * @throws IOException any IOException to write correlation value to csv file.
 */
private void computeCorrValue(SortedMap<Integer,CorrelationWritable> corrMap) throws IOException {
  boolean hasCandidates=CommonUtils.hasCandidateColumns(this.columnConfigList);
  String localCorrelationCsv=super.pathFinder.getLocalCorrelationCsvPath();
  ShifuFileUtils.createFileIfNotExists(localCorrelationCsv,SourceType.LOCAL);
  BufferedWriter writer=null;
  Map<Integer,double[]> finalCorrMap=new HashMap<Integer,double[]>();
  try {
    writer=ShifuFileUtils.getWriter(localCorrelationCsv,SourceType.LOCAL);
    writer.write(getColumnIndexes());
    writer.newLine();
    writer.write(getColumnNames());
    writer.newLine();
    for (    Entry<Integer,CorrelationWritable> entry : corrMap.entrySet()) {
      ColumnConfig xColumnConfig=this.columnConfigList.get(entry.getKey());
      if (xColumnConfig.getColumnFlag() == ColumnFlag.Meta || (hasCandidates && !ColumnFlag.Candidate.equals(xColumnConfig.getColumnFlag()))) {
        continue;
      }
      CorrelationWritable xCw=corrMap.get(entry.getKey());
      double[] corrArray=new double[this.columnConfigList.size()];
      for (int i=0; i < corrArray.length; i++) {
        ColumnConfig yColumnConfig=this.columnConfigList.get(i);
        if (yColumnConfig.getColumnFlag() == ColumnFlag.Meta) {
          continue;
        }
        if (entry.getKey() > i) {
          double[] reverseDoubleArray=finalCorrMap.get(i);
          if (reverseDoubleArray != null) {
            corrArray[i]=reverseDoubleArray[entry.getKey()];
          }
 else {
            corrArray[i]=0d;
          }
          continue;
        }
        double numerator=xCw.getAdjustCount()[i] * xCw.getXySum()[i] - xCw.getAdjustSumX()[i] * xCw.getAdjustSumY()[i];
        double denominator1=Math.sqrt(xCw.getAdjustCount()[i] * xCw.getXxSum()[i] - xCw.getAdjustSumX()[i] * xCw.getAdjustSumX()[i]);
        double denominator2=Math.sqrt(xCw.getAdjustCount()[i] * xCw.getYySum()[i] - xCw.getAdjustSumY()[i] * xCw.getAdjustSumY()[i]);
        if (Double.compare(denominator1,Double.valueOf(0d)) == 0 || Double.compare(denominator2,Double.valueOf(0d)) == 0) {
          corrArray[i]=0d;
        }
 else {
          corrArray[i]=numerator / (denominator1 * denominator2);
        }
        if (corrArray[i] > 1.05d) {
          log.warn("String_Node_Str" + numerator + "String_Node_Str"+ denominator1+ "String_Node_Str"+ denominator2+ "String_Node_Str",numerator / (denominator1 * denominator2),entry.getKey(),i);
          log.warn("String_Node_Str",xCw.getAdjustCount()[i],xCw.getXySum()[i],xCw.getAdjustSumX()[i],xCw.getAdjustSumY()[i]);
          log.warn("String_Node_Str",xCw.getAdjustCount()[i],xCw.getXxSum()[i],xCw.getAdjustSumX()[i],xCw.getAdjustSumX()[i]);
          log.warn("String_Node_Str",xCw.getAdjustCount()[i],xCw.getYySum()[i],xCw.getAdjustSumY()[i],xCw.getAdjustSumY()[i]);
        }
      }
      finalCorrMap.put(entry.getKey(),corrArray);
      String corrStr=Arrays.toString(corrArray);
      String adjustCorrStr=corrStr.substring(1,corrStr.length() - 1);
      writer.write(entry.getKey() + "String_Node_Str" + this.columnConfigList.get(entry.getKey()).getColumnName()+ "String_Node_Str"+ adjustCorrStr);
      writer.newLine();
    }
  }
  finally {
    IOUtils.closeQuietly(writer);
  }
}