Program: 166878
Project: 166878
Buggy source:
@Override public void flushEdgeCache(SqlgGraph sqlgGraph,Map<MetaEdge,Pair<SortedSet<String>,Map<SqlgEdge,Triple<SqlgVertex,SqlgVertex,Map<String,Object>>>>> edgeCache){
  Connection con=sqlgGraph.tx().getConnection();
  try {
    for (    MetaEdge metaEdge : edgeCache.keySet()) {
      Pair<SortedSet<String>,Map<SqlgEdge,Triple<SqlgVertex,SqlgVertex,Map<String,Object>>>> triples=edgeCache.get(metaEdge);
      Map<String,PropertyType> propertyTypeMap=sqlgGraph.getTopology().getTableFor(metaEdge.getSchemaTable().withPrefix(EDGE_PREFIX));
      StringBuilder sql=new StringBuilder();
      sql.append("String_Node_Str");
      sql.append(maybeWrapInQoutes(metaEdge.getSchemaTable().getSchema()));
      sql.append("String_Node_Str");
      sql.append(maybeWrapInQoutes(EDGE_PREFIX + metaEdge.getSchemaTable().getTable()));
      sql.append("String_Node_Str");
      for (      Triple<SqlgVertex,SqlgVertex,Map<String,Object>> triple : triples.getRight().values()) {
        int count=1;
        sql.append(maybeWrapInQoutes(triple.getLeft().getSchema() + "String_Node_Str" + triple.getLeft().getTable()+ Topology.OUT_VERTEX_COLUMN_END));
        sql.append("String_Node_Str");
        sql.append(maybeWrapInQoutes(triple.getMiddle().getSchema() + "String_Node_Str" + triple.getMiddle().getTable()+ Topology.IN_VERTEX_COLUMN_END));
        for (        String key : triples.getLeft()) {
          if (count <= triples.getLeft().size()) {
            sql.append("String_Node_Str");
          }
          count++;
          appendKeyForStream(propertyTypeMap.get(key),sql,key);
        }
        break;
      }
      sql.append("String_Node_Str");
      sql.append("String_Node_Str");
      sql.append(COPY_COMMAND_DELIMITER);
      sql.append("String_Node_Str");
      sql.append("String_Node_Str");
      sql.append(COPY_COMMAND_QUOTE);
      sql.append("String_Node_Str");
      sql.append(ESCAPE);
      sql.append("String_Node_Str");
      if (logger.isDebugEnabled()) {
        logger.debug(sql.toString());
      }
      long numberInserted=0;
      try (Writer writer=streamSql(sqlgGraph,sql.toString())){
        for (        Map.Entry<SqlgEdge,Triple<SqlgVertex,SqlgVertex,Map<String,Object>>> sqlgEdgeTripleEntry : triples.getRight().entrySet()) {
          SqlgEdge sqlgEdge=sqlgEdgeTripleEntry.getKey();
          Triple<SqlgVertex,SqlgVertex,Map<String,Object>> outInVertexKeyValueMap=sqlgEdgeTripleEntry.getValue();
          LinkedHashMap<String,Object> values=new LinkedHashMap<>();
          for (          String key : triples.getLeft()) {
            values.put(key,outInVertexKeyValueMap.getRight().get(key));
          }
          writeStreamingEdge(writer,sqlgEdge,outInVertexKeyValueMap.getLeft(),outInVertexKeyValueMap.getMiddle(),values);
          numberInserted++;
        }
      }
       long endHigh;
      sql.setLength(0);
      sql.append("String_Node_Str" + maybeWrapInQoutes(metaEdge.getSchemaTable().getSchema()) + "String_Node_Str"+ maybeWrapInQoutes(EDGE_PREFIX + metaEdge.getSchemaTable().getTable() + "String_Node_Str")+ "String_Node_Str");
      if (logger.isDebugEnabled()) {
        logger.debug(sql.toString());
      }
      try (PreparedStatement preparedStatement=con.prepareStatement(sql.toString())){
        ResultSet resultSet=preparedStatement.executeQuery();
        resultSet.next();
        endHigh=resultSet.getLong(1);
        resultSet.close();
      }
       long id=endHigh - numberInserted + 1;
      for (      SqlgEdge sqlgEdge : triples.getRight().keySet()) {
        sqlgEdge.setInternalPrimaryKey(RecordId.from(metaEdge.getSchemaTable(),id++));
      }
    }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
@Override public void flushEdgeCache(SqlgGraph sqlgGraph,Map<MetaEdge,Pair<SortedSet<String>,Map<SqlgEdge,Triple<SqlgVertex,SqlgVertex,Map<String,Object>>>>> edgeCache){
  Connection con=sqlgGraph.tx().getConnection();
  try {
    for (    MetaEdge metaEdge : edgeCache.keySet()) {
      Pair<SortedSet<String>,Map<SqlgEdge,Triple<SqlgVertex,SqlgVertex,Map<String,Object>>>> triples=edgeCache.get(metaEdge);
      List<Long> ids=new LinkedList<>();
      String seqsql="String_Node_Str" + maybeWrapInQoutes(metaEdge.getSchemaTable().getSchema()) + "String_Node_Str"+ maybeWrapInQoutes(EDGE_PREFIX + metaEdge.getSchemaTable().getTable() + "String_Node_Str")+ "String_Node_Str"+ triples.getRight().values().size()+ "String_Node_Str";
      if (logger.isDebugEnabled()) {
        logger.debug(seqsql);
      }
      try (PreparedStatement preparedStatement=con.prepareStatement(seqsql)){
        ResultSet resultSet=preparedStatement.executeQuery();
        while (resultSet.next()) {
          ids.add(resultSet.getLong(1));
        }
        resultSet.close();
      }
 catch (      SQLException e) {
        throw new RuntimeException(e);
      }
      Iterator<Long> it=ids.iterator();
      Map<String,PropertyType> propertyTypeMap=sqlgGraph.getTopology().getTableFor(metaEdge.getSchemaTable().withPrefix(EDGE_PREFIX));
      StringBuilder sql=new StringBuilder();
      sql.append("String_Node_Str");
      sql.append(maybeWrapInQoutes(metaEdge.getSchemaTable().getSchema()));
      sql.append("String_Node_Str");
      sql.append(maybeWrapInQoutes(EDGE_PREFIX + metaEdge.getSchemaTable().getTable()));
      sql.append("String_Node_Str");
      for (      Triple<SqlgVertex,SqlgVertex,Map<String,Object>> triple : triples.getRight().values()) {
        int count=1;
        sql.append(maybeWrapInQoutes(triple.getLeft().getSchema() + "String_Node_Str" + triple.getLeft().getTable()+ Topology.OUT_VERTEX_COLUMN_END));
        sql.append("String_Node_Str");
        sql.append(maybeWrapInQoutes(triple.getMiddle().getSchema() + "String_Node_Str" + triple.getMiddle().getTable()+ Topology.IN_VERTEX_COLUMN_END));
        sql.append("String_Node_Str");
        sql.append("String_Node_Str");
        for (        String key : triples.getLeft()) {
          if (count <= triples.getLeft().size()) {
            sql.append("String_Node_Str");
          }
          count++;
          appendKeyForStream(propertyTypeMap.get(key),sql,key);
        }
        break;
      }
      sql.append("String_Node_Str");
      sql.append("String_Node_Str");
      sql.append(COPY_COMMAND_DELIMITER);
      sql.append("String_Node_Str");
      sql.append("String_Node_Str");
      sql.append(COPY_COMMAND_QUOTE);
      sql.append("String_Node_Str");
      sql.append(ESCAPE);
      sql.append("String_Node_Str");
      if (logger.isDebugEnabled()) {
        logger.debug(sql.toString());
      }
      long numberInserted=0;
      try (Writer writer=streamSql(sqlgGraph,sql.toString())){
        for (        Map.Entry<SqlgEdge,Triple<SqlgVertex,SqlgVertex,Map<String,Object>>> sqlgEdgeTripleEntry : triples.getRight().entrySet()) {
          SqlgEdge sqlgEdge=sqlgEdgeTripleEntry.getKey();
          long id=it.next();
          sqlgEdge.setInternalPrimaryKey(RecordId.from(metaEdge.getSchemaTable(),id));
          Triple<SqlgVertex,SqlgVertex,Map<String,Object>> outInVertexKeyValueMap=sqlgEdgeTripleEntry.getValue();
          LinkedHashMap<String,Object> values=new LinkedHashMap<>();
          values.put("String_Node_Str",id);
          for (          String key : triples.getLeft()) {
            values.put(key,outInVertexKeyValueMap.getRight().get(key));
          }
          writeStreamingEdge(writer,sqlgEdge,outInVertexKeyValueMap.getLeft(),outInVertexKeyValueMap.getMiddle(),values);
          numberInserted++;
        }
      }
     }
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}