Program: 15881
Project: 15881
Buggy source:
/** 
 * Analyze this table.
 * @param session the session
 * @param table the table
 * @param sample the number of sample rows
 * @param manual whether the command was called by the user
 */
public static void analyzeTable(Session session,Table table,int sample,boolean manual){
  if (!(table.getTableType().equals(Table.TABLE)) || table.isHidden() || session == null) {
    return;
  }
  if (!manual) {
    if (session.getDatabase().isSysTableLocked()) {
      return;
    }
    if (table.hasSelectTrigger()) {
      return;
    }
  }
  if (table.isTemporary() && !table.isGlobalTemporary() && session.findLocalTempTable(table.getName()) == null) {
    return;
  }
  if (table.isLockedExclusively() && !table.isLockedExclusivelyBy(session)) {
    return;
  }
  if (!session.getUser().hasRight(table,Right.SELECT)) {
    return;
  }
  if (session.getCancel() != 0) {
    return;
  }
  Database db=session.getDatabase();
  StatementBuilder buff=new StatementBuilder("String_Node_Str");
  ArrayList<Parameter> parameters=New.arrayList();
  int parameterIndex=0;
  Column[] columns=table.getColumns();
  for (  Column col : columns) {
    buff.appendExceptFirst("String_Node_Str");
    int type=col.getType();
    if (type == Value.BLOB || type == Value.CLOB) {
      buff.append("String_Node_Str");
    }
 else {
      buff.append("String_Node_Str").append(col.getSQL()).append(')');
    }
  }
  buff.append("String_Node_Str").append(table.getSQL());
  if (sample > 0) {
    buff.append("String_Node_Str");
    Parameter p=new Parameter(parameterIndex++);
    p.setValue(ValueInt.get(1));
    parameters.add(p);
    p=new Parameter(parameterIndex++);
    p.setValue(ValueInt.get(sample));
    parameters.add(p);
  }
  String sql=buff.toString();
  Prepared command=session.prepare(sql);
  command.setParameterList(parameters);
  ResultInterface result=command.query(0);
  result.next();
  for (int j=0; j < columns.length; j++) {
    int selectivity=result.currentRow()[j].getInt();
    columns[j].setSelectivity(selectivity);
  }
  if (manual) {
    db.update(session,table);
  }
 else {
    Session sysSession=db.getSystemSession();
    if (sysSession != session) {
      db.update(sysSession,table);
      sysSession.commit(true);
    }
  }
}

Fixed version (ground truth):
/** 
 * Analyze this table.
 * @param session the session
 * @param table the table
 * @param sample the number of sample rows
 * @param manual whether the command was called by the user
 */
public static void analyzeTable(Session session,Table table,int sample,boolean manual){
  if (!(table.getTableType().equals(Table.TABLE)) || table.isHidden() || session == null) {
    return;
  }
  if (!manual) {
    if (session.getDatabase().isSysTableLocked()) {
      return;
    }
    if (table.hasSelectTrigger()) {
      return;
    }
  }
  if (table.isTemporary() && !table.isGlobalTemporary() && session.findLocalTempTable(table.getName()) == null) {
    return;
  }
  if (table.isLockedExclusively() && !table.isLockedExclusivelyBy(session)) {
    return;
  }
  if (!session.getUser().hasRight(table,Right.SELECT)) {
    return;
  }
  if (session.getCancel() != 0) {
    return;
  }
  Database db=session.getDatabase();
  StatementBuilder buff=new StatementBuilder("String_Node_Str");
  Column[] columns=table.getColumns();
  for (  Column col : columns) {
    buff.appendExceptFirst("String_Node_Str");
    int type=col.getType();
    if (type == Value.BLOB || type == Value.CLOB) {
      buff.append("String_Node_Str");
    }
 else {
      buff.append("String_Node_Str").append(col.getSQL()).append(')');
    }
  }
  buff.append("String_Node_Str").append(table.getSQL());
  if (sample > 0) {
    buff.append("String_Node_Str");
  }
  String sql=buff.toString();
  Prepared command=session.prepare(sql);
  if (sample > 0) {
    ArrayList<Parameter> params=command.getParameters();
    params.get(0).setValue(ValueInt.get(1));
    params.get(1).setValue(ValueInt.get(sample));
  }
  ResultInterface result=command.query(0);
  result.next();
  for (int j=0; j < columns.length; j++) {
    int selectivity=result.currentRow()[j].getInt();
    columns[j].setSelectivity(selectivity);
  }
  if (manual) {
    db.update(session,table);
  }
 else {
    Session sysSession=db.getSystemSession();
    if (sysSession != session) {
      db.update(sysSession,table);
      sysSession.commit(true);
    }
  }
}