Program: 167057
Project: 167057
Buggy source:
private void upgradeSqlgToTopologySchema(){
  Connection conn=this.sqlgGraph.tx().getConnection();
  try {
    DatabaseMetaData metadata=conn.getMetaData();
    String catalog=null;
    String schemaPattern=null;
    String[] types=new String[]{"String_Node_Str"};
    ResultSet schemaRs=metadata.getSchemas();
    while (schemaRs.next()) {
      String schema=schemaRs.getString(1);
      if (schema.equals(SQLG_SCHEMA) || this.sqlDialect.getDefaultSchemas().contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      TopologyManager.addSchema(this.sqlgGraph,schema);
    }
    ResultSet vertexRs=metadata.getTables(catalog,schemaPattern,"String_Node_Str",types);
    while (vertexRs.next()) {
      String schema=vertexRs.getString(2);
      String table=vertexRs.getString(3);
      Set<String> schemasToIgnore=new HashSet<>(this.sqlDialect.getDefaultSchemas());
      schemasToIgnore.remove(this.sqlDialect.getPublicSchema());
      if (schema.equals(SQLG_SCHEMA) || schemasToIgnore.contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      if (this.sqlDialect.getSpacialRefTable().contains(table)) {
        continue;
      }
      Map<String,PropertyType> columns=new ConcurrentHashMap<>();
      ResultSet columnsRs=metadata.getColumns(catalog,schemaPattern,table,null);
      while (columnsRs.next()) {
        String column=columnsRs.getString(4);
        if (!column.equals(SchemaManager.ID)) {
          int columnType=columnsRs.getInt(5);
          String typeName=columnsRs.getString("String_Node_Str");
          PropertyType propertyType=this.sqlDialect.sqlTypeToPropertyType(columnType,typeName);
          columns.put(column,propertyType);
        }
      }
      TopologyManager.addVertexLabel(this.sqlgGraph,schema,table,columns);
    }
    ResultSet edgeRs=metadata.getTables(catalog,schemaPattern,"String_Node_Str",types);
    while (edgeRs.next()) {
      String schema=edgeRs.getString(2);
      String table=edgeRs.getString(3);
      Set<String> schemasToIgnore=new HashSet<>(this.sqlDialect.getDefaultSchemas());
      schemasToIgnore.remove(this.sqlDialect.getPublicSchema());
      if (schema.equals(SQLG_SCHEMA) || schemasToIgnore.contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      if (this.sqlDialect.getSpacialRefTable().contains(table)) {
        continue;
      }
      Map<SchemaTable,MutablePair<SchemaTable,SchemaTable>> inOutSchemaTable=new HashMap<>();
      Map<String,PropertyType> columns=Collections.emptyMap();
      ResultSet columnsRs=metadata.getColumns(catalog,schemaPattern,table,null);
      boolean edgeAdded=false;
      while (columnsRs.next()) {
        String column=columnsRs.getString(4);
        if (table.startsWith(EDGE_PREFIX) && (column.endsWith(SchemaManager.IN_VERTEX_COLUMN_END) || column.endsWith(SchemaManager.OUT_VERTEX_COLUMN_END))) {
          SchemaTable edgeSchemaTable=SchemaTable.of(schema,table);
          String[] split=column.split("String_Node_Str");
          SchemaTable foreignKey=SchemaTable.of(split[0],split[1]);
          if (column.endsWith(SchemaManager.IN_VERTEX_COLUMN_END)) {
            SchemaTable schemaTable=SchemaTable.of(split[0],split[1].substring(0,split[1].length() - SchemaManager.IN_VERTEX_COLUMN_END.length()));
            if (inOutSchemaTable.containsKey(edgeSchemaTable)) {
              MutablePair<SchemaTable,SchemaTable> inSchemaTable=inOutSchemaTable.get(edgeSchemaTable);
              if (inSchemaTable.getLeft() == null) {
                inSchemaTable.setLeft(schemaTable);
              }
 else {
                TopologyManager.addLabelToEdge(this.sqlgGraph,schema,table,true,foreignKey);
              }
            }
 else {
              inOutSchemaTable.put(edgeSchemaTable,MutablePair.of(schemaTable,null));
            }
          }
 else           if (column.endsWith(SchemaManager.OUT_VERTEX_COLUMN_END)) {
            SchemaTable schemaTable=SchemaTable.of(split[0],split[1].substring(0,split[1].length() - SchemaManager.OUT_VERTEX_COLUMN_END.length()));
            if (inOutSchemaTable.containsKey(edgeSchemaTable)) {
              MutablePair<SchemaTable,SchemaTable> outSchemaTable=inOutSchemaTable.get(edgeSchemaTable);
              if (outSchemaTable.getRight() == null) {
                outSchemaTable.setRight(schemaTable);
              }
 else {
                TopologyManager.addLabelToEdge(this.sqlgGraph,schema,table,false,foreignKey);
              }
            }
 else {
              inOutSchemaTable.put(edgeSchemaTable,MutablePair.of(null,schemaTable));
            }
          }
          MutablePair<SchemaTable,SchemaTable> inOutLabels=inOutSchemaTable.get(edgeSchemaTable);
          if (!edgeAdded && inOutLabels.getLeft() != null && inOutLabels.getRight() != null) {
            TopologyManager.addEdgeLabel(this.sqlgGraph,schema,table,inOutLabels.getLeft(),inOutLabels.getRight(),columns);
            edgeAdded=true;
          }
        }
      }
    }
    edgeRs=metadata.getTables(catalog,schemaPattern,"String_Node_Str",types);
    while (edgeRs.next()) {
      String schema=edgeRs.getString(2);
      String table=edgeRs.getString(3);
      Set<String> schemasToIgnore=new HashSet<>(this.sqlDialect.getDefaultSchemas());
      schemasToIgnore.remove(this.sqlDialect.getPublicSchema());
      if (schema.equals(SQLG_SCHEMA) || schemasToIgnore.contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      if (this.sqlDialect.getSpacialRefTable().contains(table)) {
        continue;
      }
      Map<String,PropertyType> columns=new HashMap<>();
      ResultSet columnsRs=metadata.getColumns(catalog,schemaPattern,table,null);
      while (columnsRs.next()) {
        String column=columnsRs.getString(4);
        if (!column.equals(SchemaManager.ID) && !column.endsWith(SchemaManager.IN_VERTEX_COLUMN_END) && !column.endsWith(SchemaManager.OUT_VERTEX_COLUMN_END)) {
          int columnType=columnsRs.getInt(5);
          String typeName=columnsRs.getString("String_Node_Str");
          PropertyType propertyType=this.sqlDialect.sqlTypeToPropertyType(columnType,typeName);
          columns.put(column,propertyType);
        }
      }
      TopologyManager.addEdgeColumn(this.sqlgGraph,schema,table,columns);
    }
    if (distributed) {
      this.schemas.putAll(this.localSchemas);
      this.labelSchemas.putAll(this.localLabelSchemas);
      this.tables.putAll(this.localTables);
      this.edgeForeignKeys.putAll(this.localEdgeForeignKeys);
    }
  }
 catch (  SQLException e) {
    throw new RuntimeException(e);
  }
}

Fixed version (ground truth):
private void upgradeSqlgToTopologySchema(){
  Connection conn=this.sqlgGraph.tx().getConnection();
  try {
    DatabaseMetaData metadata=conn.getMetaData();
    String catalog=null;
    String schemaPattern=null;
    String tableNamePattern=null;
    String[] types=new String[]{"String_Node_Str"};
    ResultSet schemaRs=metadata.getSchemas();
    while (schemaRs.next()) {
      String schema=schemaRs.getString(1);
      if (schema.equals(SQLG_SCHEMA) || this.sqlDialect.getDefaultSchemas().contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      TopologyManager.addSchema(this.sqlgGraph,schema);
    }
    ResultSet vertexRs=metadata.getTables(catalog,schemaPattern,"String_Node_Str",types);
    while (vertexRs.next()) {
      String schema=vertexRs.getString(2);
      String table=vertexRs.getString(3);
      Set<String> schemasToIgnore=new HashSet<>(this.sqlDialect.getDefaultSchemas());
      schemasToIgnore.remove(this.sqlDialect.getPublicSchema());
      if (schema.equals(SQLG_SCHEMA) || schemasToIgnore.contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      if (this.sqlDialect.getSpacialRefTable().contains(table)) {
        continue;
      }
      Map<SchemaTable,MutablePair<SchemaTable,SchemaTable>> inOutSchemaTable=new HashMap<>();
      Map<String,PropertyType> columns=new ConcurrentHashMap<>();
      String previousSchema="String_Node_Str";
      ResultSet columnsRs=metadata.getColumns(catalog,schemaPattern,table,null);
      while (columnsRs.next()) {
        String column=columnsRs.getString(4);
        if (!column.equals(SchemaManager.ID)) {
          int columnType=columnsRs.getInt(5);
          String typeName=columnsRs.getString("String_Node_Str");
          PropertyType propertyType=this.sqlDialect.sqlTypeToPropertyType(columnType,typeName);
          columns.put(column,propertyType);
        }
      }
      TopologyManager.addVertexLabel(this.sqlgGraph,schema,table,columns);
    }
    ResultSet edgeRs=metadata.getTables(catalog,schemaPattern,"String_Node_Str",types);
    while (edgeRs.next()) {
      String schema=edgeRs.getString(2);
      String table=edgeRs.getString(3);
      Set<String> schemasToIgnore=new HashSet<>(this.sqlDialect.getDefaultSchemas());
      schemasToIgnore.remove(this.sqlDialect.getPublicSchema());
      if (schema.equals(SQLG_SCHEMA) || schemasToIgnore.contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      if (this.sqlDialect.getSpacialRefTable().contains(table)) {
        continue;
      }
      Map<SchemaTable,MutablePair<SchemaTable,SchemaTable>> inOutSchemaTable=new HashMap<>();
      Map<String,PropertyType> columns=Collections.emptyMap();
      String previousSchema="String_Node_Str";
      ResultSet columnsRs=metadata.getColumns(catalog,schemaPattern,table,null);
      boolean edgeAdded=false;
      while (columnsRs.next()) {
        String column=columnsRs.getString(4);
        if (table.startsWith(EDGE_PREFIX) && (column.endsWith(SchemaManager.IN_VERTEX_COLUMN_END) || column.endsWith(SchemaManager.OUT_VERTEX_COLUMN_END))) {
          SchemaTable edgeSchemaTable=SchemaTable.of(schema,table);
          String[] split=column.split("String_Node_Str");
          SchemaTable foreignKey=SchemaTable.of(split[0],split[1]);
          if (column.endsWith(SchemaManager.IN_VERTEX_COLUMN_END)) {
            SchemaTable schemaTable=SchemaTable.of(split[0],split[1].substring(0,split[1].length() - SchemaManager.IN_VERTEX_COLUMN_END.length()));
            if (inOutSchemaTable.containsKey(edgeSchemaTable)) {
              MutablePair<SchemaTable,SchemaTable> inSchemaTable=inOutSchemaTable.get(edgeSchemaTable);
              if (inSchemaTable.getLeft() == null) {
                inSchemaTable.setLeft(schemaTable);
              }
 else {
                TopologyManager.addLabelToEdge(this.sqlgGraph,schema,table,true,foreignKey);
              }
            }
 else {
              inOutSchemaTable.put(edgeSchemaTable,MutablePair.of(schemaTable,null));
            }
          }
 else           if (column.endsWith(SchemaManager.OUT_VERTEX_COLUMN_END)) {
            SchemaTable schemaTable=SchemaTable.of(split[0],split[1].substring(0,split[1].length() - SchemaManager.OUT_VERTEX_COLUMN_END.length()));
            if (inOutSchemaTable.containsKey(edgeSchemaTable)) {
              MutablePair<SchemaTable,SchemaTable> outSchemaTable=inOutSchemaTable.get(edgeSchemaTable);
              if (outSchemaTable.getRight() == null) {
                outSchemaTable.setRight(schemaTable);
              }
 else {
                TopologyManager.addLabelToEdge(this.sqlgGraph,schema,table,false,foreignKey);
              }
            }
 else {
              inOutSchemaTable.put(edgeSchemaTable,MutablePair.of(null,schemaTable));
            }
          }
          MutablePair<SchemaTable,SchemaTable> inOutLabels=inOutSchemaTable.get(edgeSchemaTable);
          if (!edgeAdded && inOutLabels.getLeft() != null && inOutLabels.getRight() != null) {
            TopologyManager.addEdgeLabel(this.sqlgGraph,schema,table,inOutLabels.getLeft(),inOutLabels.getRight(),columns);
            edgeAdded=true;
          }
        }
      }
    }
    edgeRs=metadata.getTables(catalog,schemaPattern,"String_Node_Str",types);
    while (edgeRs.next()) {
      String schema=edgeRs.getString(2);
      String table=edgeRs.getString(3);
      Set<String> schemasToIgnore=new HashSet<>(this.sqlDialect.getDefaultSchemas());
      schemasToIgnore.remove(this.sqlDialect.getPublicSchema());
      if (schema.equals(SQLG_SCHEMA) || schemasToIgnore.contains(schema) || this.sqlDialect.getGisSchemas().contains(schema)) {
        continue;
      }
      if (this.sqlDialect.getSpacialRefTable().contains(table)) {
        continue;
      }
      Map<SchemaTable,MutablePair<SchemaTable,SchemaTable>> inOutSchemaTable=new HashMap<>();
      Map<String,PropertyType> columns=new HashMap<>();
      String previousSchema="String_Node_Str";
      ResultSet columnsRs=metadata.getColumns(catalog,schemaPattern,table,null);
      boolean edgeAdded=false;
      while (columnsRs.next()) {
        String column=columnsRs.getString(4);
        if (!column.equals(SchemaManager.ID) && !column.endsWith(SchemaManager.IN_VERTEX_COLUMN_END) && !column.endsWith(SchemaManager.OUT_VERTEX_COLUMN_END)) {
          int columnType=columnsRs.getInt(5);
          String typeName=columnsRs.getString("String_Node_Str");
          PropertyType propertyType=this.sqlDialect.sqlTypeToPropertyType(columnType,typeName);
          columns.put(column,propertyType);
        }
      }
      TopologyManager.addEdgeColumn(this.sqlgGraph,schema,table,columns);
    }
    if (distributed) {
      this.schemas.putAll(this.localSchemas);
      this.labelSchemas.putAll(this.localLabelSchemas);
      this.tables.putAll(this.localTables);
      this.edgeForeignKeys.putAll(this.localEdgeForeignKeys);
    }
  }
 catch (  SQLException e) {
    throw new RuntimeException(e);
  }
}