Program: 160405
Project: 160405
Buggy source:
public void init() throws DatabaseInitException, DatabaseRestartRequiredException, InconsistentModelsException {
  DatabaseSession databaseSession=createSession();
  try {
    if (getKeyValueStore().isNew()) {
      keyValueStore.createTable(CLASS_LOOKUP_TABLE,null,false);
      keyValueStore.createTable(Database.STORE_PROJECT_NAME,null,false);
      keyValueStore.createTable(Registry.REGISTRY_TABLE,null,false);
      setDatabaseVersion(-1,databaseSession);
      created=new Date();
      registry.save(DATE_CREATED,created,databaseSession);
    }
 else {
      keyValueStore.openTable(CLASS_LOOKUP_TABLE);
      keyValueStore.openTable(Database.STORE_PROJECT_NAME);
      keyValueStore.openTable(Registry.REGISTRY_TABLE);
      created=registry.readDate(DATE_CREATED,databaseSession);
      if (created == null) {
        created=new Date();
        registry.save(DATE_CREATED,created,databaseSession);
      }
    }
    databaseSchemaVersion=registry.readInt(SCHEMA_VERSION,databaseSession,-1);
    migrator=new Migrator(this);
    if (getKeyValueStore().isNew()) {
      try {
        migrator.migrate(databaseSession);
      }
 catch (      MigrationException e) {
        LOGGER.error("String_Node_Str",e);
      }
      registry.save("String_Node_Str",true,databaseSession);
      databaseSession.commit();
      databaseSession.close();
      throw new DatabaseRestartRequiredException();
    }
 else     if (registry.readBoolean("String_Node_Str",true,databaseSession)) {
      initInternalStructure(databaseSession);
      initCounters(databaseSession);
      ServerSettings settings=createDefaultSettings(databaseSession);
      databaseSession.store(settings);
      new CreateBaseProjectDatabaseAction(databaseSession,AccessMethod.INTERNAL).execute();
      AddUserDatabaseAction addUserDatabaseAction=new AddUserDatabaseAction(bimServer,databaseSession,AccessMethod.INTERNAL,"String_Node_Str","String_Node_Str","String_Node_Str",UserType.SYSTEM,new SystemAuthorization(1,TimeUnit.HOURS),false,null);
      addUserDatabaseAction.setCreateSystemUser();
      User systemUser=addUserDatabaseAction.execute();
      systemUser.setCreatedBy(systemUser);
      databaseSession.store(systemUser);
      DatabaseCreated databaseCreated=databaseSession.create(DatabaseCreated.class);
      databaseCreated.setAccessMethod(AccessMethod.INTERNAL);
      databaseCreated.setExecutor(systemUser);
      databaseCreated.setDate(new Date());
      databaseCreated.setPath(getKeyValueStore().getLocation());
      databaseCreated.setVersion(databaseSchemaVersion);
      databaseSession.store(databaseCreated);
      registry.save("String_Node_Str",false,databaseSession);
    }
 else {
      initInternalStructure(databaseSession);
      initCounters(databaseSession);
    }
    for (    EClass eClass : classifiers.keyBSet()) {
      if (eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE) {
        realClasses.add(eClass.getName());
      }
    }
    databaseSession.commit();
  }
 catch (  UserException e) {
    LOGGER.error("String_Node_Str",e);
    close();
    throw new DatabaseInitException(e.getMessage());
  }
catch (  BimserverDatabaseException e) {
    LOGGER.error("String_Node_Str",e);
    close();
    throw new DatabaseInitException(e.getMessage());
  }
catch (  DatabaseRestartRequiredException e) {
    throw e;
  }
catch (  Exception e) {
    throw new DatabaseInitException(e);
  }
 finally {
    databaseSession.close();
  }
}

Fixed version (ground truth):
public void init() throws DatabaseInitException, DatabaseRestartRequiredException, InconsistentModelsException {
  DatabaseSession databaseSession=createSession();
  try {
    if (getKeyValueStore().isNew()) {
      keyValueStore.createTable(CLASS_LOOKUP_TABLE,null,false);
      keyValueStore.createTable(Database.STORE_PROJECT_NAME,null,false);
      keyValueStore.createTable(Registry.REGISTRY_TABLE,null,false);
      setDatabaseVersion(-1,databaseSession);
      created=new Date();
      registry.save(DATE_CREATED,created,databaseSession);
    }
 else {
      keyValueStore.openTable(CLASS_LOOKUP_TABLE,false);
      keyValueStore.openTable(Database.STORE_PROJECT_NAME,false);
      keyValueStore.openTable(Registry.REGISTRY_TABLE,false);
      created=registry.readDate(DATE_CREATED,databaseSession);
      if (created == null) {
        created=new Date();
        registry.save(DATE_CREATED,created,databaseSession);
      }
    }
    databaseSchemaVersion=registry.readInt(SCHEMA_VERSION,databaseSession,-1);
    migrator=new Migrator(this);
    if (getKeyValueStore().isNew()) {
      try {
        migrator.migrate(databaseSession);
      }
 catch (      MigrationException e) {
        LOGGER.error("String_Node_Str",e);
      }
      registry.save("String_Node_Str",true,databaseSession);
      databaseSession.commit();
      databaseSession.close();
      throw new DatabaseRestartRequiredException();
    }
 else     if (registry.readBoolean("String_Node_Str",true,databaseSession)) {
      initInternalStructure(databaseSession);
      initCounters(databaseSession);
      ServerSettings settings=createDefaultSettings(databaseSession);
      databaseSession.store(settings);
      new CreateBaseProjectDatabaseAction(databaseSession,AccessMethod.INTERNAL).execute();
      AddUserDatabaseAction addUserDatabaseAction=new AddUserDatabaseAction(bimServer,databaseSession,AccessMethod.INTERNAL,"String_Node_Str","String_Node_Str","String_Node_Str",UserType.SYSTEM,new SystemAuthorization(1,TimeUnit.HOURS),false,null);
      addUserDatabaseAction.setCreateSystemUser();
      User systemUser=addUserDatabaseAction.execute();
      systemUser.setCreatedBy(systemUser);
      databaseSession.store(systemUser);
      DatabaseCreated databaseCreated=databaseSession.create(DatabaseCreated.class);
      databaseCreated.setAccessMethod(AccessMethod.INTERNAL);
      databaseCreated.setExecutor(systemUser);
      databaseCreated.setDate(new Date());
      databaseCreated.setPath(getKeyValueStore().getLocation());
      databaseCreated.setVersion(databaseSchemaVersion);
      databaseSession.store(databaseCreated);
      registry.save("String_Node_Str",false,databaseSession);
    }
 else {
      initInternalStructure(databaseSession);
      initCounters(databaseSession);
    }
    for (    EClass eClass : classifiers.keyBSet()) {
      if (eClass.getEPackage() == Ifc2x3tc1Package.eINSTANCE || eClass.getEPackage() == Ifc4Package.eINSTANCE) {
        realClasses.add(eClass.getName());
      }
    }
    databaseSession.commit();
  }
 catch (  UserException e) {
    LOGGER.error("String_Node_Str",e);
    close();
    throw new DatabaseInitException(e.getMessage());
  }
catch (  BimserverDatabaseException e) {
    LOGGER.error("String_Node_Str",e);
    close();
    throw new DatabaseInitException(e.getMessage());
  }
catch (  DatabaseRestartRequiredException e) {
    throw e;
  }
catch (  Exception e) {
    throw new DatabaseInitException(e);
  }
 finally {
    databaseSession.close();
  }
}