Program: 12141
Project: 12141
Buggy source:
/** 
 * Opens the SQLite database and performs all initialization required for the current mode The readonly param should only be used in experimentation where you don't want to alter previous database state. <p> semantic_memory.cpp:1952:smem_init_db
 * @param readonly
 * @throws SoarException
 * @throws SQLException
 * @throws IOException
 */
void smem_init_db(boolean readonly) throws SoarException, SQLException, IOException {
  if (db != null) {
    return;
  }
  final String jdbcUrl=params.protocol.get() + "String_Node_Str" + params.path.get();
  final Connection connection=JdbcTools.connect(params.driver.get(),jdbcUrl);
  final DatabaseMetaData meta=connection.getMetaData();
  params.protocol.set(meta.getDriverName() + "String_Node_Str" + meta.getDriverVersion());
  logger.info("String_Node_Str" + jdbcUrl + "String_Node_Str"+ meta.getDriverName()+ "String_Node_Str"+ meta.getDriverVersion());
  if (params.path.get().equals(SemanticMemoryDatabase.IN_MEMORY_PATH)) {
    trace.print(Category.SMEM,"String_Node_Str");
  }
 else {
    trace.print(Category.SMEM,"String_Node_Str",params.path.get());
  }
  db=new SemanticMemoryDatabase(params.driver.get(),connection);
  applyDatabasePerformanceOptions();
  smem_validation++;
  final boolean tabula_rasa=db.structure();
  db.prepare();
  if (!SemanticMemoryDatabase.IN_MEMORY_PATH.equals(params.path.get())) {
    final ResultSet result=db.get_schema_version.executeQuery();
    try {
      if (result.next()) {
        String schemaVersion=result.getString(1);
        if (!SemanticMemoryDatabase.SMEM_SCHEMA_VERSION.equals(schemaVersion)) {
          logger.error("String_Node_Str" + schemaVersion);
          params.path.set(SemanticMemoryDatabase.IN_MEMORY_PATH);
          connection.close();
          db=null;
          smem_init_db(readonly);
        }
      }
 else {
        if (params.append_db.get() == AppendDatabaseChoices.on) {
          logger.info("String_Node_Str");
        }
      }
    }
  finally {
      result.close();
    }
  }
  db.set_schema_version.setString(1,SemanticMemoryDatabase.SMEM_SCHEMA_VERSION);
  db.set_schema_version.execute();
  if (params.append_db.get() == AppendDatabaseChoices.off) {
    db.dropSmemTables();
    db.structure();
    db.prepare();
  }
  if (tabula_rasa) {
    db.begin.executeUpdate();
{
      smem_max_cycle=1;
      smem_variable_create(smem_variable_key.var_max_cycle,smem_max_cycle);
      stats.nodes.set(0L);
      smem_variable_create(smem_variable_key.var_num_nodes,stats.nodes.get());
      stats.edges.set(0L);
      smem_variable_create(smem_variable_key.var_num_edges,stats.edges.get());
      smem_variable_create(smem_variable_key.var_act_thresh,params.thresh.get());
      smem_variable_create(smem_variable_key.var_act_mode,params.activation_mode.get().ordinal());
    }
    db.commit.executeUpdate();
  }
 else {
    final ByRef<Long> tempMaxCycle=ByRef.create(smem_max_cycle);
    smem_variable_get(smem_variable_key.var_max_cycle,tempMaxCycle);
    smem_max_cycle=tempMaxCycle.value;
    final ByRef<Long> temp=ByRef.create(0L);
    smem_variable_get(smem_variable_key.var_act_thresh,temp);
    params.thresh.set(temp.value);
    smem_variable_get(smem_variable_key.var_num_nodes,temp);
    stats.nodes.set(temp.value);
    smem_variable_get(smem_variable_key.var_num_edges,temp);
    stats.edges.set(temp.value);
    smem_variable_get(smem_variable_key.var_act_mode,temp);
    params.activation_mode.set(ActivationChoices.values()[Integer.parseInt(temp.value.toString())]);
  }
  smem_reset_id_counters();
  if (params.lazy_commit.get() == LazyCommitChoices.on) {
    db.begin.executeUpdate();
  }
}

Fixed version (ground truth):
/** 
 * Opens the SQLite database and performs all initialization required for the current mode The readonly param should only be used in experimentation where you don't want to alter previous database state. <p> semantic_memory.cpp:1952:smem_init_db
 * @param readonly
 * @throws SoarException
 * @throws SQLException
 * @throws IOException
 */
void smem_init_db(boolean readonly) throws SoarException, SQLException, IOException {
  if (db != null) {
    return;
  }
  final String jdbcUrl=params.protocol.get() + "String_Node_Str" + params.path.get();
  final Connection connection=JdbcTools.connect(params.driver.get(),jdbcUrl);
  final DatabaseMetaData meta=connection.getMetaData();
  logger.info("String_Node_Str" + jdbcUrl + "String_Node_Str"+ meta.getDriverName()+ "String_Node_Str"+ meta.getDriverVersion());
  if (params.path.get().equals(SemanticMemoryDatabase.IN_MEMORY_PATH)) {
    trace.print(Category.SMEM,"String_Node_Str");
  }
 else {
    trace.print(Category.SMEM,"String_Node_Str",params.path.get());
  }
  db=new SemanticMemoryDatabase(params.driver.get(),connection);
  applyDatabasePerformanceOptions();
  smem_validation++;
  final boolean tabula_rasa=db.structure();
  db.prepare();
  if (!SemanticMemoryDatabase.IN_MEMORY_PATH.equals(params.path.get())) {
    final ResultSet result=db.get_schema_version.executeQuery();
    try {
      if (result.next()) {
        String schemaVersion=result.getString(1);
        if (!SemanticMemoryDatabase.SMEM_SCHEMA_VERSION.equals(schemaVersion)) {
          logger.error("String_Node_Str" + schemaVersion);
          params.path.set(SemanticMemoryDatabase.IN_MEMORY_PATH);
          connection.close();
          db=null;
          smem_init_db(readonly);
        }
      }
 else {
        if (params.append_db.get() == AppendDatabaseChoices.on) {
          logger.info("String_Node_Str");
        }
      }
    }
  finally {
      result.close();
    }
  }
  db.set_schema_version.setString(1,SemanticMemoryDatabase.SMEM_SCHEMA_VERSION);
  db.set_schema_version.execute();
  if (params.append_db.get() == AppendDatabaseChoices.off) {
    db.dropSmemTables();
    db.structure();
    db.prepare();
  }
  if (tabula_rasa) {
    db.begin.executeUpdate();
{
      smem_max_cycle=1;
      smem_variable_create(smem_variable_key.var_max_cycle,smem_max_cycle);
      stats.nodes.set(0L);
      smem_variable_create(smem_variable_key.var_num_nodes,stats.nodes.get());
      stats.edges.set(0L);
      smem_variable_create(smem_variable_key.var_num_edges,stats.edges.get());
      smem_variable_create(smem_variable_key.var_act_thresh,params.thresh.get());
      smem_variable_create(smem_variable_key.var_act_mode,params.activation_mode.get().ordinal());
    }
    db.commit.executeUpdate();
  }
 else {
    final ByRef<Long> tempMaxCycle=ByRef.create(smem_max_cycle);
    smem_variable_get(smem_variable_key.var_max_cycle,tempMaxCycle);
    smem_max_cycle=tempMaxCycle.value;
    final ByRef<Long> temp=ByRef.create(0L);
    smem_variable_get(smem_variable_key.var_act_thresh,temp);
    params.thresh.set(temp.value);
    smem_variable_get(smem_variable_key.var_num_nodes,temp);
    stats.nodes.set(temp.value);
    smem_variable_get(smem_variable_key.var_num_edges,temp);
    stats.edges.set(temp.value);
    smem_variable_get(smem_variable_key.var_act_mode,temp);
    params.activation_mode.set(ActivationChoices.values()[Integer.parseInt(temp.value.toString())]);
  }
  smem_reset_id_counters();
  if (params.lazy_commit.get() == LazyCommitChoices.on) {
    db.begin.executeUpdate();
  }
}