Program: 12121
Project: 12121
Buggy source:
/** 
 * Private method for epmem_init_db that throws SQLException, IOException so it can wrap in SoarException and throw. <p> episodic_memory.cpp:1458:epmem_init_db
 * @param readonly
 * @throws SoarException
 */
private void epmem_init_db_ex(boolean readonly) throws SQLException, IOException, SoarException {
  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());
  db=new EpisodicMemoryDatabase(params.driver.get(),connection);
  applyDatabasePerformanceOptions();
  epmem_validation++;
  db.structure();
  db.prepare();
  if (!EpisodicMemoryDatabase.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 (!EpisodicMemoryDatabase.EPMEM_SCHEMA_VERSION.equals(schemaVersion)) {
          logger.error("String_Node_Str" + schemaVersion);
          params.path.set(EpisodicMemoryDatabase.IN_MEMORY_PATH);
          connection.close();
          db=null;
          epmem_init_db_ex(readonly);
        }
      }
 else {
        if (params.append_database.get() == AppendDatabaseChoices.on) {
          logger.info("String_Node_Str");
        }
      }
    }
  finally {
      result.close();
    }
  }
  db.set_schema_version.setString(1,EpisodicMemoryDatabase.EPMEM_SCHEMA_VERSION);
  db.set_schema_version.execute();
  if (params.append_database.get() == AppendDatabaseChoices.off) {
    db.dropEpmemTables();
    db.structure();
    db.prepare();
  }
  epmem_node_mins.clear();
  epmem_node_maxes.clear();
  epmem_node_removals.clear();
  epmem_edge_mins.clear();
  epmem_edge_maxes.clear();
  epmem_edge_removals.clear();
  epmem_id_repository.put(EPMEM_NODEID_ROOT,new LinkedHashMap<Long,LinkedList<EpisodicMemoryIdPair>>());
{
    Set<WmeImpl> wms_temp=Sets.newLinkedHashSet();
    wms_temp.add(null);
    epmem_id_ref_counts.put(EPMEM_NODEID_ROOT,wms_temp);
  }
  stats.time.set(1L);
  stats.next_id.set(1L);
{
    final ByRef<Long> stored_id=ByRef.create(0L);
    if (epmem_get_variable(epmem_variable_key.var_next_id,stored_id)) {
      stats.next_id.set(stored_id.value);
    }
 else {
      epmem_set_variable(epmem_variable_key.var_next_id,stats.next_id.get());
    }
  }
  for (int i=EPMEM_RIT_STATE_NODE; i <= EPMEM_RIT_STATE_EDGE; i++) {
    epmem_rit_state_graph[i].offset.stat=EPMEM_RIT_OFFSET_INIT;
    epmem_rit_state_graph[i].leftroot.stat=0;
    epmem_rit_state_graph[i].rightroot.stat=1;
    epmem_rit_state_graph[i].minstep.stat=Long.MAX_VALUE;
  }
  epmem_rit_state_graph[EPMEM_RIT_STATE_NODE].add_query=db.add_epmem_wmes_constant_range;
  epmem_rit_state_graph[EPMEM_RIT_STATE_EDGE].add_query=db.add_epmem_wmes_identifier_range;
{
    final ByRef<Long> var_val=ByRef.create(0L);
    for (int i=EPMEM_RIT_STATE_NODE; i <= EPMEM_RIT_STATE_EDGE; i++) {
      if (epmem_get_variable(epmem_rit_state_graph[i].offset.var_key,var_val)) {
        epmem_rit_state_graph[i].offset.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].offset.var_key,epmem_rit_state_graph[i].offset.stat);
      }
      if (epmem_get_variable(epmem_rit_state_graph[i].leftroot.var_key,var_val)) {
        epmem_rit_state_graph[i].leftroot.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].leftroot.var_key,epmem_rit_state_graph[i].leftroot.stat);
      }
      if (epmem_get_variable(epmem_rit_state_graph[i].rightroot.var_key,var_val)) {
        epmem_rit_state_graph[i].rightroot.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].rightroot.var_key,epmem_rit_state_graph[i].rightroot.stat);
      }
      if (epmem_get_variable(epmem_rit_state_graph[i].minstep.var_key,var_val)) {
        epmem_rit_state_graph[i].minstep.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].minstep.var_key,epmem_rit_state_graph[i].minstep.stat);
      }
    }
  }
{
    final PreparedStatement temp_q=db.get_max_time;
    final ResultSet rs=temp_q.executeQuery();
    try {
      if (rs.next()) {
        stats.time.set(rs.getLong(0 + 1) + 1);
      }
    }
  finally {
      rs.close();
    }
  }
  long time_max=stats.time.get();
  if (!readonly) {
    long time_last=(time_max - 1);
    final PreparedStatement[] now_select=new PreparedStatement[]{db.now_select_node,db.now_select_edge};
    final PreparedStatement[] now_add=new PreparedStatement[]{db.add_epmem_wmes_constant_point,db.add_epmem_wmes_identifier_point};
    final PreparedStatement[] now_delete=new PreparedStatement[]{db.now_delete_node,db.now_delete_edge};
    for (int i=EPMEM_RIT_STATE_NODE; i <= EPMEM_RIT_STATE_EDGE; i++) {
      final PreparedStatement temp_q=now_add[i];
      temp_q.setLong(2,time_last);
      final PreparedStatement temp_q2=now_select[i];
      final ResultSet rs=temp_q2.executeQuery();
      try {
        while (rs.next()) {
          long range_start=rs.getLong(1 + 1);
          if (range_start == time_last) {
            temp_q.setLong(1,rs.getLong(0 + 1));
            temp_q.executeUpdate();
          }
 else {
            epmem_rit_insert_interval(range_start,time_last,rs.getLong(0 + 1),epmem_rit_state_graph[i]);
          }
        }
      }
  finally {
        rs.close();
      }
      now_delete[i].execute();
    }
  }
{
    initMinMax(time_max,db.minmax_select_node,epmem_node_maxes,epmem_node_mins);
    initMinMax(time_max,db.minmax_select_edge,epmem_edge_maxes,epmem_edge_mins);
  }
{
    long parent_n_id;
    long attributes_s_id;
    long child_n_id;
    long wi_id;
    Map<Long,LinkedList<EpisodicMemoryIdPair>> hp;
    LinkedList<EpisodicMemoryIdPair> ip;
    PreparedStatement temp_q=db.edge_unique_select;
    final ResultSet rs=temp_q.executeQuery();
    try {
      while (rs.next()) {
        parent_n_id=rs.getLong(0 + 1);
        attributes_s_id=rs.getLong(1 + 1);
        child_n_id=rs.getLong(2 + 1);
        wi_id=rs.getLong(3 + 1);
        hp=epmem_id_repository.get(parent_n_id);
        if (hp == null) {
          hp=Maps.newLinkedHashMap();
          epmem_id_repository.put(parent_n_id,hp);
        }
        ip=hp.get(attributes_s_id);
        if (ip == null) {
          ip=Lists.newLinkedList();
          hp.put(attributes_s_id,ip);
        }
        ip.addFirst(new EpisodicMemoryIdPair(child_n_id,wi_id));
        hp=epmem_id_repository.get(child_n_id);
        if (hp == null) {
          hp=Maps.newLinkedHashMap();
          epmem_id_repository.put(child_n_id,hp);
        }
      }
    }
  finally {
      rs.close();
    }
  }
{
    epmem_wme_adds.add(decider.top_state);
  }
  decider.top_goal.epmem_id=EPMEM_NODEID_ROOT;
  decider.top_goal.epmem_valid=epmem_validation;
  ResultSet r=db.database_version.executeQuery();
  r.next();
  try {
    stats.db_version.set(r.getString(1));
  }
  finally {
    r.close();
  }
  if (params.lazy_commit.get() == LazyCommitChoices.on) {
    db.begin.executeUpdate();
  }
}

Fixed version (ground truth):
/** 
 * Private method for epmem_init_db that throws SQLException, IOException so it can wrap in SoarException and throw. <p> episodic_memory.cpp:1458:epmem_init_db
 * @param readonly
 * @throws SoarException
 * @throws URISyntaxException 
 */
private void epmem_init_db_ex(boolean readonly) throws SQLException, IOException, SoarException {
  if (db != null) {
    return;
  }
  final String jdbcUrl=URLDecoder.decode(params.protocol.get() + "String_Node_Str" + params.path.get(),"String_Node_Str");
  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());
  db=new EpisodicMemoryDatabase(params.driver.get(),connection);
  applyDatabasePerformanceOptions();
  epmem_validation++;
  db.structure();
  db.prepare();
  if (!EpisodicMemoryDatabase.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 (!EpisodicMemoryDatabase.EPMEM_SCHEMA_VERSION.equals(schemaVersion)) {
          logger.error("String_Node_Str" + schemaVersion);
          params.path.set(EpisodicMemoryDatabase.IN_MEMORY_PATH);
          connection.close();
          db=null;
          epmem_init_db_ex(readonly);
        }
      }
 else {
        if (params.append_database.get() == AppendDatabaseChoices.on) {
          logger.info("String_Node_Str");
        }
      }
    }
  finally {
      result.close();
    }
  }
  db.set_schema_version.setString(1,EpisodicMemoryDatabase.EPMEM_SCHEMA_VERSION);
  db.set_schema_version.execute();
  if (params.append_database.get() == AppendDatabaseChoices.off) {
    db.dropEpmemTables();
    db.structure();
    db.prepare();
  }
  epmem_node_mins.clear();
  epmem_node_maxes.clear();
  epmem_node_removals.clear();
  epmem_edge_mins.clear();
  epmem_edge_maxes.clear();
  epmem_edge_removals.clear();
  epmem_id_repository.put(EPMEM_NODEID_ROOT,new LinkedHashMap<Long,LinkedList<EpisodicMemoryIdPair>>());
{
    Set<WmeImpl> wms_temp=Sets.newLinkedHashSet();
    wms_temp.add(null);
    epmem_id_ref_counts.put(EPMEM_NODEID_ROOT,wms_temp);
  }
  stats.time.set(1L);
  stats.next_id.set(1L);
{
    final ByRef<Long> stored_id=ByRef.create(0L);
    if (epmem_get_variable(epmem_variable_key.var_next_id,stored_id)) {
      stats.next_id.set(stored_id.value);
    }
 else {
      epmem_set_variable(epmem_variable_key.var_next_id,stats.next_id.get());
    }
  }
  for (int i=EPMEM_RIT_STATE_NODE; i <= EPMEM_RIT_STATE_EDGE; i++) {
    epmem_rit_state_graph[i].offset.stat=EPMEM_RIT_OFFSET_INIT;
    epmem_rit_state_graph[i].leftroot.stat=0;
    epmem_rit_state_graph[i].rightroot.stat=1;
    epmem_rit_state_graph[i].minstep.stat=Long.MAX_VALUE;
  }
  epmem_rit_state_graph[EPMEM_RIT_STATE_NODE].add_query=db.add_epmem_wmes_constant_range;
  epmem_rit_state_graph[EPMEM_RIT_STATE_EDGE].add_query=db.add_epmem_wmes_identifier_range;
{
    final ByRef<Long> var_val=ByRef.create(0L);
    for (int i=EPMEM_RIT_STATE_NODE; i <= EPMEM_RIT_STATE_EDGE; i++) {
      if (epmem_get_variable(epmem_rit_state_graph[i].offset.var_key,var_val)) {
        epmem_rit_state_graph[i].offset.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].offset.var_key,epmem_rit_state_graph[i].offset.stat);
      }
      if (epmem_get_variable(epmem_rit_state_graph[i].leftroot.var_key,var_val)) {
        epmem_rit_state_graph[i].leftroot.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].leftroot.var_key,epmem_rit_state_graph[i].leftroot.stat);
      }
      if (epmem_get_variable(epmem_rit_state_graph[i].rightroot.var_key,var_val)) {
        epmem_rit_state_graph[i].rightroot.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].rightroot.var_key,epmem_rit_state_graph[i].rightroot.stat);
      }
      if (epmem_get_variable(epmem_rit_state_graph[i].minstep.var_key,var_val)) {
        epmem_rit_state_graph[i].minstep.stat=var_val.value;
      }
 else {
        epmem_set_variable(epmem_rit_state_graph[i].minstep.var_key,epmem_rit_state_graph[i].minstep.stat);
      }
    }
  }
{
    final PreparedStatement temp_q=db.get_max_time;
    final ResultSet rs=temp_q.executeQuery();
    try {
      if (rs.next()) {
        stats.time.set(rs.getLong(0 + 1) + 1);
      }
    }
  finally {
      rs.close();
    }
  }
  long time_max=stats.time.get();
  if (!readonly) {
    long time_last=(time_max - 1);
    final PreparedStatement[] now_select=new PreparedStatement[]{db.now_select_node,db.now_select_edge};
    final PreparedStatement[] now_add=new PreparedStatement[]{db.add_epmem_wmes_constant_point,db.add_epmem_wmes_identifier_point};
    final PreparedStatement[] now_delete=new PreparedStatement[]{db.now_delete_node,db.now_delete_edge};
    for (int i=EPMEM_RIT_STATE_NODE; i <= EPMEM_RIT_STATE_EDGE; i++) {
      final PreparedStatement temp_q=now_add[i];
      temp_q.setLong(2,time_last);
      final PreparedStatement temp_q2=now_select[i];
      final ResultSet rs=temp_q2.executeQuery();
      try {
        while (rs.next()) {
          long range_start=rs.getLong(1 + 1);
          if (range_start == time_last) {
            temp_q.setLong(1,rs.getLong(0 + 1));
            temp_q.executeUpdate();
          }
 else {
            epmem_rit_insert_interval(range_start,time_last,rs.getLong(0 + 1),epmem_rit_state_graph[i]);
          }
        }
      }
  finally {
        rs.close();
      }
      now_delete[i].execute();
    }
  }
{
    initMinMax(time_max,db.minmax_select_node,epmem_node_maxes,epmem_node_mins);
    initMinMax(time_max,db.minmax_select_edge,epmem_edge_maxes,epmem_edge_mins);
  }
{
    long parent_n_id;
    long attributes_s_id;
    long child_n_id;
    long wi_id;
    Map<Long,LinkedList<EpisodicMemoryIdPair>> hp;
    LinkedList<EpisodicMemoryIdPair> ip;
    PreparedStatement temp_q=db.edge_unique_select;
    final ResultSet rs=temp_q.executeQuery();
    try {
      while (rs.next()) {
        parent_n_id=rs.getLong(0 + 1);
        attributes_s_id=rs.getLong(1 + 1);
        child_n_id=rs.getLong(2 + 1);
        wi_id=rs.getLong(3 + 1);
        hp=epmem_id_repository.get(parent_n_id);
        if (hp == null) {
          hp=Maps.newLinkedHashMap();
          epmem_id_repository.put(parent_n_id,hp);
        }
        ip=hp.get(attributes_s_id);
        if (ip == null) {
          ip=Lists.newLinkedList();
          hp.put(attributes_s_id,ip);
        }
        ip.addFirst(new EpisodicMemoryIdPair(child_n_id,wi_id));
        hp=epmem_id_repository.get(child_n_id);
        if (hp == null) {
          hp=Maps.newLinkedHashMap();
          epmem_id_repository.put(child_n_id,hp);
        }
      }
    }
  finally {
      rs.close();
    }
  }
{
    epmem_wme_adds.add(decider.top_state);
  }
  decider.top_goal.epmem_id=EPMEM_NODEID_ROOT;
  decider.top_goal.epmem_valid=epmem_validation;
  ResultSet r=db.database_version.executeQuery();
  r.next();
  try {
    stats.db_version.set(r.getString(1));
  }
  finally {
    r.close();
  }
  if (params.lazy_commit.get() == LazyCommitChoices.on) {
    db.begin.executeUpdate();
  }
}