Program: 126342
Project: 126342
Buggy source:
public static void addTableForTemCatalogOrSchema(String dbsid,String schema,DatabaseConnection connection,MetadataTable dbtable,IMetadataConnection iMetadataConnection) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  boolean hasSchemaInCatalog=false;
  boolean isAccess=EDatabaseTypeName.ACCESS.getDisplayName().equals(iMetadataConnection.getDbType());
  Catalog c=(Catalog)ConnectionHelper.getPackage(dbsid,connection,Catalog.class);
  Schema s=(Schema)ConnectionHelper.getPackage(schema,connection,Schema.class);
  List<Schema> subschemas=new ArrayList<Schema>();
  if (c != null) {
    subschemas=CatalogHelper.getSchemas(c);
    hasSchemaInCatalog=subschemas.size() > 0;
  }
  if (c != null && s == null && !hasSchemaInCatalog) {
    PackageHelper.addMetadataTable(dbtable,c);
  }
 else   if (s != null && !hasSchemaInCatalog && c == null) {
    PackageHelper.addMetadataTable(dbtable,s);
  }
 else   if (c != null && hasSchemaInCatalog) {
    subschemas=CatalogHelper.getSchemas(c);
    hasSchemaInCatalog=subschemas.size() > 0;
    if (subschemas.size() > 0) {
      for (      Schema current : subschemas) {
        if (current.getName().equals(schema)) {
          s=current;
          break;
        }
      }
      if (s != null) {
        if (s instanceof SchemaImpl) {
          SchemaImpl schemaElement=(SchemaImpl)s;
          EList<ModelElement> ownedElement=schemaElement.getOwnedElement();
          ownedElement.add(dbtable);
        }
      }
 else       if (subschemas.size() > 0) {
        for (int i=0; i < subschemas.size(); i++) {
          SchemaImpl schemaElement=(SchemaImpl)subschemas.get(i);
          EList<ModelElement> ownedElement=schemaElement.getOwnedElement();
          ownedElement.add(dbtable);
        }
      }
    }
  }
 else   if (s == null && c == null && !isAccess) {
    fillCatalogAndSchemas(iMetadataConnection,connection);
    addTableForTemCatalogOrSchema(dbsid,schema,connection,dbtable,iMetadataConnection);
  }
 else {
    ProjectNodeHelper.addCatalogOrSchema(iMetadataConnection,connection);
    if (isAccess) {
      addTableForTemCatalogOrSchema(dbsid,connection.getName(),connection,dbtable,iMetadataConnection);
    }
 else {
      addTableForTemCatalogOrSchema(dbsid,schema,connection,dbtable,iMetadataConnection);
    }
  }
}

Fixed version (ground truth):
private static void addTableForTemCatalogOrSchema(String dbsid,String schema,DatabaseConnection connection,MetadataTable dbtable,IMetadataConnection iMetadataConnection,int stackCount) throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
  if (3 < stackCount) {
    return;
  }
  boolean hasSchemaInCatalog=false;
  boolean isAccess=EDatabaseTypeName.ACCESS.getDisplayName().equals(iMetadataConnection.getDbType());
  Catalog c=(Catalog)ConnectionHelper.getPackage(dbsid,connection,Catalog.class);
  Schema s=(Schema)ConnectionHelper.getPackage(schema,connection,Schema.class);
  List<Schema> subschemas=new ArrayList<Schema>();
  if (c != null) {
    subschemas=CatalogHelper.getSchemas(c);
    hasSchemaInCatalog=subschemas.size() > 0;
  }
  if (c != null && s == null && !hasSchemaInCatalog) {
    PackageHelper.addMetadataTable(dbtable,c);
  }
 else   if (s != null && !hasSchemaInCatalog && c == null) {
    PackageHelper.addMetadataTable(dbtable,s);
  }
 else   if (c != null && hasSchemaInCatalog) {
    subschemas=CatalogHelper.getSchemas(c);
    hasSchemaInCatalog=subschemas.size() > 0;
    if (subschemas.size() > 0) {
      for (      Schema current : subschemas) {
        if (current.getName().equals(schema)) {
          s=current;
          break;
        }
      }
      if (s != null) {
        if (s instanceof SchemaImpl) {
          SchemaImpl schemaElement=(SchemaImpl)s;
          EList<ModelElement> ownedElement=schemaElement.getOwnedElement();
          ownedElement.add(dbtable);
        }
      }
 else       if (subschemas.size() > 0) {
        for (int i=0; i < subschemas.size(); i++) {
          SchemaImpl schemaElement=(SchemaImpl)subschemas.get(i);
          EList<ModelElement> ownedElement=schemaElement.getOwnedElement();
          ownedElement.add(dbtable);
        }
      }
    }
  }
 else   if (s == null && c == null && !isAccess && stackCount == 1) {
    fillCatalogAndSchemas(iMetadataConnection,connection);
    addTableForTemCatalogOrSchema(dbsid,schema,connection,dbtable,iMetadataConnection,stackCount + 1);
  }
 else {
    ProjectNodeHelper.addCatalogOrSchema(iMetadataConnection,connection);
    if (isAccess) {
      addTableForTemCatalogOrSchema(dbsid,connection.getName(),connection,dbtable,iMetadataConnection,stackCount + 1);
    }
 else {
      addTableForTemCatalogOrSchema(dbsid,schema,connection,dbtable,iMetadataConnection,stackCount + 1);
    }
  }
}