Program: 163239
Project: 163239
Buggy source:
/** 
 * Dumps the content of a   {@link java.sql.ResultSet}.
 * @param rs     the {@link java.sql.ResultSet} whose contents should be read and written to a given output
 * @param output the output that will store the data in the given {@link java.sql.ResultSet}in the format specified by concrete implementations of this class.
 */
public final void write(ResultSet rs,Writer output){
  validateWriterSettings();
  boolean hasWriterProcessor=writerSettings.getRowWriterProcessor() != null;
  AbstractWriter<W> writer=null;
  long rowCount=0L;
  Object[] row=null;
  try {
    try {
      ResultSetMetaData md=rs.getMetaData();
      int columns=md.getColumnCount();
      String[] headers=new String[columns];
      int[] lengths=new int[columns];
      for (int i=1; i <= columns; i++) {
        headers[i - 1]=md.getColumnLabel(i);
        int precision=md.getPrecision(i);
        int scale=md.getScale(i);
        int length;
        if (precision != 0 && scale != 0) {
          length=precision + scale + 2;
        }
 else {
          length=precision + scale;
        }
        lengths[i - 1]=length;
      }
      String[] userProvidedHeaders=writerSettings.getHeaders();
      if (userProvidedHeaders == null) {
        writerSettings.setHeaders(headers);
      }
 else {
        headers=userProvidedHeaders;
      }
      adjustColumnLengths(headers,lengths);
      writer=createWriter(output,writerSettings);
      if (writerSettings.isHeaderWritingEnabled()) {
        writer.writeHeaders();
      }
      row=new Object[columns];
      while (rs.next()) {
        for (int i=1; i <= columns; i++) {
          row[i - 1]=rs.getObject(i);
        }
        if (hasWriterProcessor) {
          writer.processRecord(row);
        }
 else {
          writer.writeRow(row);
        }
        rowCount++;
      }
    }
  finally {
      if (!keepResourcesOpen) {
        rs.close();
      }
    }
  }
 catch (  Exception e) {
    throw new TextWritingException("String_Node_Str",rowCount,row,e);
  }
 finally {
    if (writer != null) {
      if (!keepResourcesOpen) {
        writer.close();
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Dumps the content of a   {@link java.sql.ResultSet}.
 * @param rs     the {@link java.sql.ResultSet} whose contents should be read and written to a given output
 * @param output the output that will store the data in the given {@link java.sql.ResultSet}in the format specified by concrete implementations of this class.
 */
public final void write(ResultSet rs,Writer output){
  validateWriterSettings();
  boolean hasWriterProcessor=writerSettings.getRowWriterProcessor() != null;
  AbstractWriter<W> writer=null;
  long rowCount=0L;
  Object[] row=null;
  try {
    try {
      ResultSetMetaData md=rs.getMetaData();
      int columns=md.getColumnCount();
      String[] headers=new String[columns];
      int[] lengths=new int[columns];
      for (int i=1; i <= columns; i++) {
        headers[i - 1]=md.getColumnLabel(i);
        int precision=md.getPrecision(i);
        int scale=md.getScale(i);
        int length;
        if (precision != 0 && scale != 0) {
          length=precision + scale + 2;
        }
 else {
          length=precision + scale;
        }
        lengths[i - 1]=length;
      }
      String[] userProvidedHeaders=writerSettings.getHeaders();
      if (userProvidedHeaders == null) {
        writerSettings.setHeaders(headers);
      }
 else {
        headers=userProvidedHeaders;
      }
      adjustColumnLengths(headers,lengths);
      writer=createWriter(output,writerSettings);
      if (writerSettings.isHeaderWritingEnabled()) {
        writer.writeHeaders();
      }
      row=new Object[columns];
      while (rs.next()) {
        for (int i=1; i <= columns; i++) {
          row[i - 1]=rs.getObject(i);
        }
        if (hasWriterProcessor) {
          writer.processRecord(row);
        }
 else {
          writer.writeRow(row);
        }
        rowCount++;
      }
    }
  finally {
      if (!keepResourcesOpen) {
        rs.close();
      }
    }
  }
 catch (  Exception e) {
    throw new TextWritingException("String_Node_Str",rowCount,row,e);
  }
 finally {
    close(writer);
  }
}