Program: 167136
Project: 167136
Buggy source:
public Iterator<SqlEdge> getEdges(Direction direction,String... labels){
  long sequenceFirstValueLessOne=this.sqlG.getSqlDialect().sequenceInitialValue() - 1l;
  List<Direction> directions=new ArrayList<>(2);
  Set<SqlEdge> edges=new HashSet<>();
  Set<String> inVertexLabels=new HashSet<>();
  Set<String> outVertexLabels=new HashSet<>();
  if (direction == Direction.IN) {
    inVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),true));
    if (labels.length > 0)     inVertexLabels.retainAll(Arrays.asList(labels));
    directions.add(direction);
  }
 else   if (direction == Direction.OUT) {
    outVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),false));
    if (labels.length > 0)     outVertexLabels.retainAll(Arrays.asList(labels));
    directions.add(direction);
  }
 else {
    inVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),true));
    outVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),false));
    if (labels.length > 0) {
      inVertexLabels.retainAll(Arrays.asList(labels));
      outVertexLabels.retainAll(Arrays.asList(labels));
    }
    directions.add(Direction.IN);
    directions.add(Direction.OUT);
  }
  for (  Direction d : directions) {
    for (    String label : (d == Direction.IN ? inVertexLabels : outVertexLabels)) {
      if (this.sqlG.getSchemaManager().tableExist(SchemaManager.EDGE_PREFIX + label)) {
        StringBuilder sql=new StringBuilder("String_Node_Str");
        sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(SchemaManager.EDGE_PREFIX + label));
        sql.append("String_Node_Str");
switch (d) {
case IN:
          sql.append("String_Node_Str");
        sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.IN_VERTEX_COLUMN_END));
      sql.append("String_Node_Str");
    break;
case OUT:
  sql.append("String_Node_Str");
sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.OUT_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
case BOTH:
sql.append("String_Node_Str");
sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.OUT_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.IN_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
}
if (this.sqlG.getSqlDialect().needsSemicolon()) {
sql.append("String_Node_Str");
}
Connection conn=this.sqlG.tx().getConnection();
try (PreparedStatement preparedStatement=conn.prepareStatement(sql.toString())){
switch (d) {
case IN:
preparedStatement.setLong(1,this.primaryKey);
break;
case OUT:
preparedStatement.setLong(1,this.primaryKey);
break;
case BOTH:
preparedStatement.setLong(1,this.primaryKey);
preparedStatement.setLong(2,this.primaryKey);
break;
}
ResultSet resultSet=preparedStatement.executeQuery();
while (resultSet.next()) {
Set<String> inVertexColumnNames=new HashSet<>();
Set<String> outVertexColumnNames=new HashSet<>();
String inVertexColumnName="String_Node_Str";
String outVertexColumnName="String_Node_Str";
ResultSetMetaData resultSetMetaData=resultSet.getMetaData();
for (int i=1; i <= resultSetMetaData.getColumnCount(); i++) {
String columnName=resultSetMetaData.getColumnName(i);
if (columnName.endsWith(SqlElement.IN_VERTEX_COLUMN_END)) {
inVertexColumnNames.add(columnName);
}
 else if (columnName.endsWith(SqlElement.OUT_VERTEX_COLUMN_END)) {
outVertexColumnNames.add(columnName);
}
}
if (inVertexColumnNames.isEmpty() || outVertexColumnNames.isEmpty()) {
throw new IllegalStateException("String_Node_Str");
}
Long edgeId=resultSet.getLong("String_Node_Str");
Long inId=null;
Long outId=null;
for (String inColumnName : inVertexColumnNames) {
if (inId != null) {
Long tempInId=resultSet.getLong(inColumnName);
if (tempInId.longValue() != sequenceFirstValueLessOne) {
throw new IllegalStateException("String_Node_Str");
}
}
 else {
Long tempInId=resultSet.getLong(inColumnName);
if (tempInId.longValue() != sequenceFirstValueLessOne) {
inId=tempInId;
inVertexColumnName=inColumnName;
}
}
}
for (String outColumnName : outVertexColumnNames) {
if (outId != null) {
Long tempOutId=resultSet.getLong(outColumnName);
if (tempOutId.longValue() != sequenceFirstValueLessOne) {
throw new IllegalStateException("String_Node_Str");
}
}
 else {
Long tempOutId=resultSet.getLong(outColumnName);
if (tempOutId.longValue() != sequenceFirstValueLessOne) {
outId=tempOutId;
outVertexColumnName=outColumnName;
}
}
}
if (inVertexColumnName.isEmpty() || outVertexColumnName.isEmpty()) {
throw new IllegalStateException("String_Node_Str");
}
List<Object> keyValues=new ArrayList<>();
for (int i=1; i <= resultSetMetaData.getColumnCount(); i++) {
String columnName=resultSetMetaData.getColumnName(i);
if (!((columnName.equals("String_Node_Str") || columnName.equals(inVertexColumnNames) || columnName.equals(outVertexColumnNames)))) {
keyValues.add(columnName);
keyValues.add(resultSet.getObject(columnName));
}
}
SqlEdge sqlEdge=null;
switch (d) {
case IN:
sqlEdge=new SqlEdge(this.sqlG,edgeId,label,this,new SqlVertex(this.sqlG,outId,outVertexColumnName.replace(SqlElement.OUT_VERTEX_COLUMN_END,"String_Node_Str")),keyValues.toArray());
break;
case OUT:
sqlEdge=new SqlEdge(this.sqlG,edgeId,label,new SqlVertex(this.sqlG,inId,inVertexColumnName.replace(SqlElement.IN_VERTEX_COLUMN_END,"String_Node_Str")),this,keyValues.toArray());
break;
case BOTH:
throw new IllegalStateException("String_Node_Str");
}
edges.add(sqlEdge);
}
}
 catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
return edges.iterator();
}

Fixed version (ground truth):
public Iterator<SqlEdge> getEdges(Direction direction,String... labels){
  List<Direction> directions=new ArrayList<>(2);
  Set<SqlEdge> edges=new HashSet<>();
  Set<String> inVertexLabels=new HashSet<>();
  Set<String> outVertexLabels=new HashSet<>();
  if (direction == Direction.IN) {
    inVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),true));
    if (labels.length > 0)     inVertexLabels.retainAll(Arrays.asList(labels));
    directions.add(direction);
  }
 else   if (direction == Direction.OUT) {
    outVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),false));
    if (labels.length > 0)     outVertexLabels.retainAll(Arrays.asList(labels));
    directions.add(direction);
  }
 else {
    inVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),true));
    outVertexLabels.addAll(this.sqlG.getSchemaManager().getLabelsForVertex((Long)this.id(),false));
    if (labels.length > 0) {
      inVertexLabels.retainAll(Arrays.asList(labels));
      outVertexLabels.retainAll(Arrays.asList(labels));
    }
    directions.add(Direction.IN);
    directions.add(Direction.OUT);
  }
  for (  Direction d : directions) {
    for (    String label : (d == Direction.IN ? inVertexLabels : outVertexLabels)) {
      if (this.sqlG.getSchemaManager().tableExist(SchemaManager.EDGE_PREFIX + label)) {
        StringBuilder sql=new StringBuilder("String_Node_Str");
        sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(SchemaManager.EDGE_PREFIX + label));
        sql.append("String_Node_Str");
switch (d) {
case IN:
          sql.append("String_Node_Str");
        sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.IN_VERTEX_COLUMN_END));
      sql.append("String_Node_Str");
    break;
case OUT:
  sql.append("String_Node_Str");
sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.OUT_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
case BOTH:
sql.append("String_Node_Str");
sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.OUT_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
sql.append(this.sqlG.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.label + SqlElement.IN_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
}
if (this.sqlG.getSqlDialect().needsSemicolon()) {
sql.append("String_Node_Str");
}
Connection conn=this.sqlG.tx().getConnection();
try (PreparedStatement preparedStatement=conn.prepareStatement(sql.toString())){
switch (d) {
case IN:
preparedStatement.setLong(1,this.primaryKey);
break;
case OUT:
preparedStatement.setLong(1,this.primaryKey);
break;
case BOTH:
preparedStatement.setLong(1,this.primaryKey);
preparedStatement.setLong(2,this.primaryKey);
break;
}
ResultSet resultSet=preparedStatement.executeQuery();
while (resultSet.next()) {
Set<String> inVertexColumnNames=new HashSet<>();
Set<String> outVertexColumnNames=new HashSet<>();
String inVertexColumnName="String_Node_Str";
String outVertexColumnName="String_Node_Str";
ResultSetMetaData resultSetMetaData=resultSet.getMetaData();
for (int i=1; i <= resultSetMetaData.getColumnCount(); i++) {
String columnName=resultSetMetaData.getColumnName(i);
if (columnName.endsWith(SqlElement.IN_VERTEX_COLUMN_END)) {
inVertexColumnNames.add(columnName);
}
 else if (columnName.endsWith(SqlElement.OUT_VERTEX_COLUMN_END)) {
outVertexColumnNames.add(columnName);
}
}
if (inVertexColumnNames.isEmpty() || outVertexColumnNames.isEmpty()) {
throw new IllegalStateException("String_Node_Str");
}
Long edgeId=resultSet.getLong("String_Node_Str");
Long inId=null;
Long outId=null;
for (String inColumnName : inVertexColumnNames) {
if (inId != null) {
Long tempInId=resultSet.getLong(inColumnName);
if (!resultSet.wasNull()) {
throw new IllegalStateException("String_Node_Str");
}
}
 else {
Long tempInId=resultSet.getLong(inColumnName);
if (!resultSet.wasNull()) {
inId=tempInId;
inVertexColumnName=inColumnName;
}
}
}
for (String outColumnName : outVertexColumnNames) {
if (outId != null) {
Long tempOutId=resultSet.getLong(outColumnName);
if (!resultSet.wasNull()) {
throw new IllegalStateException("String_Node_Str");
}
}
 else {
Long tempOutId=resultSet.getLong(outColumnName);
if (!resultSet.wasNull()) {
outId=tempOutId;
outVertexColumnName=outColumnName;
}
}
}
if (inVertexColumnName.isEmpty() || outVertexColumnName.isEmpty()) {
throw new IllegalStateException("String_Node_Str");
}
List<Object> keyValues=new ArrayList<>();
for (int i=1; i <= resultSetMetaData.getColumnCount(); i++) {
String columnName=resultSetMetaData.getColumnName(i);
if (!((columnName.equals("String_Node_Str") || columnName.equals(inVertexColumnNames) || columnName.equals(outVertexColumnNames)))) {
keyValues.add(columnName);
keyValues.add(resultSet.getObject(columnName));
}
}
SqlEdge sqlEdge=null;
switch (d) {
case IN:
sqlEdge=new SqlEdge(this.sqlG,edgeId,label,this,new SqlVertex(this.sqlG,outId,outVertexColumnName.replace(SqlElement.OUT_VERTEX_COLUMN_END,"String_Node_Str")),keyValues.toArray());
break;
case OUT:
sqlEdge=new SqlEdge(this.sqlG,edgeId,label,new SqlVertex(this.sqlG,inId,inVertexColumnName.replace(SqlElement.IN_VERTEX_COLUMN_END,"String_Node_Str")),this,keyValues.toArray());
break;
case BOTH:
throw new IllegalStateException("String_Node_Str");
}
edges.add(sqlEdge);
}
}
 catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
}
return edges.iterator();
}