Program: 12174
Project: 12174
Buggy source:
/** 
 * Returns a temporally unique integer representing a symbol constant. <p> episodic_memory.cpp:1928:epmem_hash_id epmem_temporal_hash( agent *my_agent, Symbol *sym, bool add_on_fail = true )
 * @param sym
 * @param add_on_fail
 * @return
 * @throws SQLException 
 */
private long epmem_temporal_hash(SymbolImpl sym,boolean add_on_fail) throws SQLException {
  long return_val=0;
  if (sym.asString() != null || sym.asDouble() != null || sym.asInteger() != null) {
    if (!(sym.epmem_hash_id == 0) || (sym.epmem_valid != epmem_validation)) {
      sym.epmem_hash_id=0;
      sym.epmem_valid=epmem_validation;
      final PreparedStatement hash_get=db.hash_get;
      hash_get.setLong(1,Symbols.getSymbolType(sym));
switch (Symbols.getSymbolType(sym)) {
case Symbols.SYM_CONSTANT_SYMBOL_TYPE:
        hash_get.setString(2,sym.asString().getValue());
      break;
case Symbols.INT_CONSTANT_SYMBOL_TYPE:
    hash_get.setLong(2,sym.asInteger().getValue());
  break;
case Symbols.FLOAT_CONSTANT_SYMBOL_TYPE:
hash_get.setDouble(2,sym.asDouble().getValue());
break;
}
final ResultSet hash_get_rs=hash_get.executeQuery();
try {
if (hash_get_rs.next()) {
return_val=hash_get_rs.getLong(0 + 1);
}
}
  finally {
hash_get_rs.close();
}
if (return_val == 0 && add_on_fail) {
final PreparedStatement hash_add=db.hash_add;
hash_add.setLong(1,Symbols.getSymbolType(sym));
switch (Symbols.getSymbolType(sym)) {
case Symbols.SYM_CONSTANT_SYMBOL_TYPE:
hash_add.setString(2,sym.asString().getValue());
break;
case Symbols.INT_CONSTANT_SYMBOL_TYPE:
hash_add.setLong(2,sym.asInteger().getValue());
break;
case Symbols.FLOAT_CONSTANT_SYMBOL_TYPE:
hash_add.setDouble(2,sym.asDouble().getValue());
break;
}
hash_add.execute();
final ResultSet hash_add_rs=hash_add.getGeneratedKeys();
try {
if (hash_add_rs.next()) {
return_val=hash_add_rs.getLong(1);
}
 else {
throw new SQLException("String_Node_Str");
}
}
  finally {
hash_add_rs.close();
}
}
sym.epmem_hash_id=return_val;
sym.epmem_valid=epmem_validation;
}
return_val=sym.epmem_hash_id;
}
return return_val;
}

Fixed version (ground truth):
/** 
 * Returns a temporally unique integer representing a symbol constant. <p> episodic_memory.cpp:1928: epmem_hash_id epmem_temporal_hash(  agent *my_agent,  Symbol *sym,  bool add_on_fail = true  )
 * @param sym
 * @param add_on_fail
 * @return
 * @throws SQLException 
 */
private long epmem_temporal_hash(SymbolImpl sym,boolean add_on_fail) throws SQLException {
  long return_val=0;
  if (sym.asString() != null || sym.asDouble() != null || sym.asInteger() != null) {
    if (!(sym.epmem_hash_id == 0) || (sym.epmem_valid != epmem_validation)) {
      sym.epmem_hash_id=0;
      sym.epmem_valid=epmem_validation;
      final PreparedStatement hash_get=db.hash_get;
      hash_get.setLong(1,Symbols.getSymbolType(sym));
switch (Symbols.getSymbolType(sym)) {
case Symbols.SYM_CONSTANT_SYMBOL_TYPE:
        hash_get.setString(2,sym.asString().getValue());
      break;
case Symbols.INT_CONSTANT_SYMBOL_TYPE:
    hash_get.setLong(2,sym.asInteger().getValue());
  break;
case Symbols.FLOAT_CONSTANT_SYMBOL_TYPE:
hash_get.setDouble(2,sym.asDouble().getValue());
break;
}
final ResultSet hash_get_rs=hash_get.executeQuery();
try {
if (hash_get_rs.next()) {
return_val=hash_get_rs.getLong(0 + 1);
}
}
  finally {
hash_get_rs.close();
}
if (return_val == 0 && add_on_fail) {
final PreparedStatement hash_add=db.hash_add;
hash_add.setLong(1,Symbols.getSymbolType(sym));
switch (Symbols.getSymbolType(sym)) {
case Symbols.SYM_CONSTANT_SYMBOL_TYPE:
hash_add.setString(2,sym.asString().getValue());
break;
case Symbols.INT_CONSTANT_SYMBOL_TYPE:
hash_add.setLong(2,sym.asInteger().getValue());
break;
case Symbols.FLOAT_CONSTANT_SYMBOL_TYPE:
hash_add.setDouble(2,sym.asDouble().getValue());
break;
}
hash_add.execute();
final ResultSet hash_add_rs=hash_add.getGeneratedKeys();
try {
if (hash_add_rs.next()) {
return_val=hash_add_rs.getLong(1);
}
 else {
throw new SQLException("String_Node_Str");
}
}
  finally {
hash_add_rs.close();
}
}
sym.epmem_hash_id=return_val;
sym.epmem_valid=epmem_validation;
}
return_val=sym.epmem_hash_id;
}
return return_val;
}