Program: 31767
Project: 31767
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 {
  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) {
        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();
      corrMap.remove(entry.getKey());
    }
    log.info("String_Node_Str",localCorrelationCsv);
  }
  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 {
  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) {
        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();
    }
    log.info("String_Node_Str",localCorrelationCsv);
  }
  finally {
    IOUtils.closeQuietly(writer);
  }
}