Program: 167038
Project: 167038
Buggy source:
public static List<Pair<SqlgElement,Map<String,Emit<SqlgElement>>>> loadResultSetIntoResultIterator(SqlgGraph sqlgGraph,ResultSetMetaData resultSetMetaData,ResultSet resultSet,SchemaTableTree rootSchemaTableTree,List<LinkedList<SchemaTableTree>> subQueryStacks,boolean first,Map<String,Integer> labeledColumnNameCountMap,Map<String,Integer> lastElementIdCountMap) throws SQLException {
  List<Pair<SqlgElement,Map<String,Emit<SqlgElement>>>> result=new ArrayList<>();
  if (resultSet.next()) {
    if (first) {
      for (      LinkedList<SchemaTableTree> subQueryStack : subQueryStacks) {
        subQueryStack.getFirst().clearColumnNamePropertNameMap();
      }
      populateMetaDataMaps(resultSetMetaData,rootSchemaTableTree,labeledColumnNameCountMap,lastElementIdCountMap);
    }
    int subQueryDepth=0;
    Map<String,Emit<SqlgElement>> previousLabeledElements=null;
    for (    LinkedList<SchemaTableTree> subQueryStack : subQueryStacks) {
      Map<String,Emit<SqlgElement>> labeledElements=SqlgUtil.loadLabeledElements(sqlgGraph,resultSet,subQueryStack,lastElementIdCountMap);
      if (previousLabeledElements == null) {
        previousLabeledElements=labeledElements;
      }
 else {
        previousLabeledElements.putAll(labeledElements);
      }
      if (subQueryDepth == subQueryStacks.size() - 1) {
        SchemaTableTree lastSchemaTableTree=subQueryStack.getLast();
        Optional<SqlgElement> e=SqlgUtil.loadElement(sqlgGraph,lastElementIdCountMap,resultSet,lastSchemaTableTree);
        if (e.isPresent()) {
          result.add(Pair.of(e.get(),previousLabeledElements));
          if (lastSchemaTableTree.getReplacedStepDepth() == lastSchemaTableTree.getStepDepth() && lastSchemaTableTree.isEmit() && lastSchemaTableTree.isUntilFirst()) {
            result.add(Pair.of(e.get(),previousLabeledElements));
          }
        }
 else {
          throw new IllegalStateException("String_Node_Str");
        }
      }
      subQueryDepth++;
    }
  }
  return result;
}

Fixed version (ground truth):
public static List<Pair<SqlgElement,Map<String,Emit<SqlgElement>>>> loadResultSetIntoResultIterator(SqlgGraph sqlgGraph,ResultSetMetaData resultSetMetaData,ResultSet resultSet,SchemaTableTree rootSchemaTableTree,List<LinkedList<SchemaTableTree>> subQueryStacks,boolean first,Map<String,Integer> lastElementIdCountMap) throws SQLException {
  List<Pair<SqlgElement,Map<String,Emit<SqlgElement>>>> result=new ArrayList<>();
  if (resultSet.next()) {
    if (first) {
      for (      LinkedList<SchemaTableTree> subQueryStack : subQueryStacks) {
        for (        SchemaTableTree schemaTableTree : subQueryStack) {
          schemaTableTree.clearColumnNamePropertNameMap();
        }
      }
      populateIdCountMap(resultSetMetaData,rootSchemaTableTree,lastElementIdCountMap);
    }
    int subQueryDepth=0;
    Map<String,Emit<SqlgElement>> previousLabeledElements=null;
    for (    LinkedList<SchemaTableTree> subQueryStack : subQueryStacks) {
      Map<String,Emit<SqlgElement>> labeledElements=SqlgUtil.loadLabeledElements(sqlgGraph,resultSet,subQueryStack,lastElementIdCountMap);
      if (previousLabeledElements == null) {
        previousLabeledElements=labeledElements;
      }
 else {
        previousLabeledElements.putAll(labeledElements);
      }
      if (subQueryDepth == subQueryStacks.size() - 1) {
        SchemaTableTree lastSchemaTableTree=subQueryStack.getLast();
        Optional<SqlgElement> e=SqlgUtil.loadElement(sqlgGraph,lastElementIdCountMap,resultSet,lastSchemaTableTree);
        if (e.isPresent()) {
          result.add(Pair.of(e.get(),previousLabeledElements));
          if (lastSchemaTableTree.getReplacedStepDepth() == lastSchemaTableTree.getStepDepth() && lastSchemaTableTree.isEmit() && lastSchemaTableTree.isUntilFirst()) {
            result.add(Pair.of(e.get(),previousLabeledElements));
          }
        }
 else {
          throw new IllegalStateException("String_Node_Str");
        }
      }
      subQueryDepth++;
    }
  }
  return result;
}