Program: 167091
Project: 167091
Buggy source:
/** 
 * Generate a query for the replaced steps. Each replaced step translates to a join statement and a section of the where clause.
 * @param replacedSteps
 * @return The results of the query
 */
private <S,E>Iterator<Pair<E,Multimap<String,Object>>> internalGetElements(List<ReplacedStep<S,E>> replacedSteps){
  Preconditions.checkState(SchemaTableTree.threadLocalAliasColumnNameMap.get().isEmpty(),"String_Node_Str");
  Preconditions.checkState(SchemaTableTree.threadLocalColumnNameAliasMap.get().isEmpty(),"String_Node_Str");
  SchemaTable schemaTable=getSchemaTablePrefixed();
  SchemaTableTree schemaTableTree=this.sqlgGraph.getGremlinParser().parse(schemaTable,replacedSteps);
  List<Pair<LinkedList<SchemaTableTree>,String>> sqlStatements=schemaTableTree.constructSql();
  try {
    SqlgCompiledResultIterator<Pair<E,Multimap<String,Object>>> resultIterator=new SqlgCompiledResultIterator<>();
    for (    Pair<LinkedList<SchemaTableTree>,String> sqlPair : sqlStatements) {
      Connection conn=this.sqlgGraph.tx().getConnection();
      if (logger.isDebugEnabled()) {
        logger.debug(sqlPair.getRight());
      }
      try (PreparedStatement preparedStatement=conn.prepareStatement(sqlPair.getRight())){
        preparedStatement.setLong(1,this.recordId.getId());
        SqlgUtil.setParametersOnStatement(this.sqlgGraph,sqlPair.getLeft(),conn,preparedStatement,2);
        ResultSet resultSet=preparedStatement.executeQuery();
        ResultSetMetaData resultSetMetaData=resultSet.getMetaData();
        while (resultSet.next()) {
          Pair<E,Multimap<String,Object>> result=SqlgUtil.loadElementsLabeledAndEndElements(this.sqlgGraph,resultSetMetaData,resultSet,sqlPair.getLeft());
          resultIterator.add(result);
        }
      }
 catch (      SQLException e) {
        throw new RuntimeException(e);
      }
    }
    return resultIterator;
  }
  finally {
    schemaTableTree.resetThreadVars();
  }
}

Fixed version (ground truth):
/** 
 * Generate a query for the replaced steps. Each replaced step translates to a join statement and a section of the where clause.
 * @param replacedSteps
 * @return The results of the query
 */
private <S,E>Iterator<Pair<E,Multimap<String,Object>>> internalGetElements(List<ReplacedStep<S,E>> replacedSteps){
  Preconditions.checkState(SchemaTableTree.threadLocalAliasColumnNameMap.get().isEmpty(),"String_Node_Str");
  Preconditions.checkState(SchemaTableTree.threadLocalColumnNameAliasMap.get().isEmpty(),"String_Node_Str");
  SchemaTable schemaTable=getSchemaTablePrefixed();
  SchemaTableTree schemaTableTree=null;
  try {
    schemaTableTree=this.sqlgGraph.getGremlinParser().parse(schemaTable,replacedSteps);
    List<Pair<LinkedList<SchemaTableTree>,String>> sqlStatements=schemaTableTree.constructSql();
    SqlgCompiledResultIterator<Pair<E,Multimap<String,Object>>> resultIterator=new SqlgCompiledResultIterator<>();
    for (    Pair<LinkedList<SchemaTableTree>,String> sqlPair : sqlStatements) {
      Connection conn=this.sqlgGraph.tx().getConnection();
      if (logger.isDebugEnabled()) {
        logger.debug(sqlPair.getRight());
      }
      try (PreparedStatement preparedStatement=conn.prepareStatement(sqlPair.getRight())){
        preparedStatement.setLong(1,this.recordId.getId());
        SqlgUtil.setParametersOnStatement(this.sqlgGraph,sqlPair.getLeft(),conn,preparedStatement,2);
        ResultSet resultSet=preparedStatement.executeQuery();
        ResultSetMetaData resultSetMetaData=resultSet.getMetaData();
        while (resultSet.next()) {
          Pair<E,Multimap<String,Object>> result=SqlgUtil.loadElementsLabeledAndEndElements(this.sqlgGraph,resultSetMetaData,resultSet,sqlPair.getLeft());
          resultIterator.add(result);
        }
      }
 catch (      SQLException e) {
        throw new RuntimeException(e);
      }
    }
    return resultIterator;
  }
  finally {
    if (schemaTableTree != null)     schemaTableTree.resetThreadVars();
  }
}