Program: 167032
Project: 167032
Buggy source:
private Iterator<Edge> internalEdges(Direction direction,String... labels){
  this.sqlgGraph.tx().readWrite();
  if (this.sqlgGraph.features().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode() && this.sqlgGraph.tx().getBatchManager().vertexIsCached(this)) {
    List<Edge> edges=this.sqlgGraph.tx().getBatchManager().getEdges(this,direction,labels);
    return edges.iterator();
  }
 else {
    List<Edge> edges=new ArrayList<>();
    List<Direction> directions=new ArrayList<>(2);
    Set<SchemaTable> inVertexLabels=new HashSet<>();
    Set<SchemaTable> outVertexLabels=new HashSet<>();
    if (direction == Direction.IN) {
      inVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getLeft());
      if (labels.length > 0) {
        retainLabels(inVertexLabels,labels);
      }
      directions.add(direction);
    }
 else     if (direction == Direction.OUT) {
      outVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getRight());
      if (labels.length > 0) {
        retainLabels(outVertexLabels,labels);
      }
      directions.add(direction);
    }
 else {
      inVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getLeft());
      outVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getRight());
      if (labels.length > 0) {
        retainLabels(inVertexLabels,labels);
        retainLabels(outVertexLabels,labels);
      }
      directions.add(Direction.IN);
      directions.add(Direction.OUT);
    }
    for (    Direction d : directions) {
      for (      SchemaTable schemaTable : (d == Direction.IN ? inVertexLabels : outVertexLabels)) {
        StringBuilder sql=new StringBuilder("String_Node_Str");
switch (d) {
case IN:
          sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getSchema()));
        sql.append("String_Node_Str");
      sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getTable()));
    sql.append(WHERE);
  sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema + "String_Node_Str" + this.table+ SchemaManager.IN_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
case OUT:
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getSchema()));
sql.append("String_Node_Str");
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getTable()));
sql.append(WHERE);
sql.append(this.sqlgGraph.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.schema + "String_Node_Str" + this.table+ SchemaManager.OUT_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
case BOTH:
throw new IllegalStateException(BUG_DIRECTION_BOTH_SHOULD_NEVER_FIRE_HERE);
}
if (this.sqlgGraph.getSqlDialect().needsSemicolon()) {
sql.append("String_Node_Str");
}
Connection conn=this.sqlgGraph.tx().getConnection();
if (logger.isDebugEnabled()) {
logger.debug(sql.toString());
}
try (PreparedStatement preparedStatement=conn.prepareStatement(sql.toString())){
switch (d) {
case IN:
preparedStatement.setLong(1,this.recordId.getId());
break;
case OUT:
preparedStatement.setLong(1,this.recordId.getId());
break;
case BOTH:
throw new IllegalStateException(BUG_DIRECTION_BOTH_SHOULD_NEVER_FIRE_HERE);
}
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.getColumnLabel(i);
if (columnName.endsWith(SchemaManager.IN_VERTEX_COLUMN_END)) {
inVertexColumnNames.add(columnName);
}
 else if (columnName.endsWith(SchemaManager.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) {
@SuppressWarnings("String_Node_Str") 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) {
@SuppressWarnings("String_Node_Str") 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");
}
SchemaTable inSchemaTable=SchemaTable.from(this.sqlgGraph,inVertexColumnName,this.sqlgGraph.getSqlDialect().getPublicSchema());
SchemaTable outSchemaTable=SchemaTable.from(this.sqlgGraph,outVertexColumnName,this.sqlgGraph.getSqlDialect().getPublicSchema());
List<Object> keyValues=new ArrayList<>();
for (int i=1; i <= resultSetMetaData.getColumnCount(); i++) {
String columnName=resultSetMetaData.getColumnLabel(i);
if (!((columnName.equals("String_Node_Str") || columnName.equals(inVertexColumnNames) || columnName.equals(outVertexColumnNames)))) {
keyValues.add(columnName);
keyValues.add(resultSet.getObject(columnName));
}
}
SqlgEdge sqlGEdge=null;
switch (d) {
case IN:
sqlGEdge=new SqlgEdge(this.sqlgGraph,edgeId,schemaTable.getSchema(),schemaTable.getTable().substring(SchemaManager.EDGE_PREFIX.length()),this,SqlgVertex.of(this.sqlgGraph,outId,outSchemaTable.getSchema(),SqlgUtil.removeTrailingOutId(outSchemaTable.getTable())),keyValues.toArray());
break;
case OUT:
sqlGEdge=new SqlgEdge(this.sqlgGraph,edgeId,schemaTable.getSchema(),schemaTable.getTable().substring(SchemaManager.EDGE_PREFIX.length()),SqlgVertex.of(this.sqlgGraph,inId,inSchemaTable.getSchema(),SqlgUtil.removeTrailingInId(inSchemaTable.getTable())),this,keyValues.toArray());
break;
case BOTH:
throw new IllegalStateException("String_Node_Str");
}
edges.add(sqlGEdge);
}
}
 catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
return edges.iterator();
}
}

Fixed version (ground truth):
private Iterator<Edge> internalEdges(Direction direction,String... labels){
  this.sqlgGraph.tx().readWrite();
  if (this.sqlgGraph.features().supportsBatchMode() && this.sqlgGraph.tx().isInBatchMode() && this.sqlgGraph.tx().getBatchManager().vertexIsCached(this)) {
    this.sqlgGraph.tx().flush();
  }
  List<Edge> edges=new ArrayList<>();
  List<Direction> directions=new ArrayList<>(2);
  Set<SchemaTable> inVertexLabels=new HashSet<>();
  Set<SchemaTable> outVertexLabels=new HashSet<>();
  if (direction == Direction.IN) {
    inVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getLeft());
    if (labels.length > 0) {
      retainLabels(inVertexLabels,labels);
    }
    directions.add(direction);
  }
 else   if (direction == Direction.OUT) {
    outVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getRight());
    if (labels.length > 0) {
      retainLabels(outVertexLabels,labels);
    }
    directions.add(direction);
  }
 else {
    inVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getLeft());
    outVertexLabels.addAll(this.sqlgGraph.getSchemaManager().getTableLabels(this.getSchemaTablePrefixed()).getRight());
    if (labels.length > 0) {
      retainLabels(inVertexLabels,labels);
      retainLabels(outVertexLabels,labels);
    }
    directions.add(Direction.IN);
    directions.add(Direction.OUT);
  }
  for (  Direction d : directions) {
    for (    SchemaTable schemaTable : (d == Direction.IN ? inVertexLabels : outVertexLabels)) {
      StringBuilder sql=new StringBuilder("String_Node_Str");
switch (d) {
case IN:
        sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getSchema()));
      sql.append("String_Node_Str");
    sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getTable()));
  sql.append(WHERE);
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(this.schema + "String_Node_Str" + this.table+ SchemaManager.IN_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
case OUT:
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getSchema()));
sql.append("String_Node_Str");
sql.append(this.sqlgGraph.getSqlDialect().maybeWrapInQoutes(schemaTable.getTable()));
sql.append(WHERE);
sql.append(this.sqlgGraph.getSchemaManager().getSqlDialect().maybeWrapInQoutes(this.schema + "String_Node_Str" + this.table+ SchemaManager.OUT_VERTEX_COLUMN_END));
sql.append("String_Node_Str");
break;
case BOTH:
throw new IllegalStateException(BUG_DIRECTION_BOTH_SHOULD_NEVER_FIRE_HERE);
}
if (this.sqlgGraph.getSqlDialect().needsSemicolon()) {
sql.append("String_Node_Str");
}
Connection conn=this.sqlgGraph.tx().getConnection();
if (logger.isDebugEnabled()) {
logger.debug(sql.toString());
}
try (PreparedStatement preparedStatement=conn.prepareStatement(sql.toString())){
switch (d) {
case IN:
preparedStatement.setLong(1,this.recordId.getId());
break;
case OUT:
preparedStatement.setLong(1,this.recordId.getId());
break;
case BOTH:
throw new IllegalStateException(BUG_DIRECTION_BOTH_SHOULD_NEVER_FIRE_HERE);
}
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.getColumnLabel(i);
if (columnName.endsWith(SchemaManager.IN_VERTEX_COLUMN_END)) {
inVertexColumnNames.add(columnName);
}
 else if (columnName.endsWith(SchemaManager.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) {
@SuppressWarnings("String_Node_Str") 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) {
@SuppressWarnings("String_Node_Str") 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");
}
SchemaTable inSchemaTable=SchemaTable.from(this.sqlgGraph,inVertexColumnName,this.sqlgGraph.getSqlDialect().getPublicSchema());
SchemaTable outSchemaTable=SchemaTable.from(this.sqlgGraph,outVertexColumnName,this.sqlgGraph.getSqlDialect().getPublicSchema());
List<Object> keyValues=new ArrayList<>();
for (int i=1; i <= resultSetMetaData.getColumnCount(); i++) {
String columnName=resultSetMetaData.getColumnLabel(i);
if (!((columnName.equals("String_Node_Str") || columnName.equals(inVertexColumnNames) || columnName.equals(outVertexColumnNames)))) {
keyValues.add(columnName);
keyValues.add(resultSet.getObject(columnName));
}
}
SqlgEdge sqlGEdge=null;
switch (d) {
case IN:
sqlGEdge=new SqlgEdge(this.sqlgGraph,edgeId,schemaTable.getSchema(),schemaTable.getTable().substring(SchemaManager.EDGE_PREFIX.length()),this,SqlgVertex.of(this.sqlgGraph,outId,outSchemaTable.getSchema(),SqlgUtil.removeTrailingOutId(outSchemaTable.getTable())),keyValues.toArray());
break;
case OUT:
sqlGEdge=new SqlgEdge(this.sqlgGraph,edgeId,schemaTable.getSchema(),schemaTable.getTable().substring(SchemaManager.EDGE_PREFIX.length()),SqlgVertex.of(this.sqlgGraph,inId,inSchemaTable.getSchema(),SqlgUtil.removeTrailingInId(inSchemaTable.getTable())),this,keyValues.toArray());
break;
case BOTH:
throw new IllegalStateException("String_Node_Str");
}
edges.add(sqlGEdge);
}
}
 catch (SQLException e) {
throw new RuntimeException(e);
}
}
}
return edges.iterator();
}