Program: 160391
Project: 160391
Buggy source:
private void initDatabaseDependantItems() throws BimserverDatabaseException {
  serverSettingsCache.init();
  notificationsManager.init();
  getSerializerFactory().init(pluginManager,bimDatabase,this);
  try {
    DatabaseSession session=bimDatabase.createSession();
    try {
      updatePlugins(session);
      session.commit();
    }
 catch (    ServiceException e) {
      LOGGER.error("String_Node_Str",e);
    }
 finally {
      session.close();
    }
    session=bimDatabase.createSession();
    createDatabaseObjects(session);
    ServerSettings serverSettings=serverSettingsCache.getServerSettings();
    for (    Entry<PluginContext,WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
      WebModulePluginConfiguration webPluginConfiguration=find(serverSettings.getWebModules(),entry.getKey().getIdentifier());
      if (webPluginConfiguration == null) {
        webPluginConfiguration=session.create(WebModulePluginConfiguration.class);
        serverSettings.getWebModules().add(webPluginConfiguration);
        PluginDescriptor pluginDescriptor=getPluginDescriptor(session,entry.getKey().getIdentifier());
        if (pluginDescriptor == null) {
          throw new BimserverDatabaseException("String_Node_Str" + entry.getKey().getIdentifier());
        }
        genericPluginConversion(entry.getKey(),session,webPluginConfiguration,pluginDescriptor);
      }
 else {
        if (webPluginConfiguration == serverSettings.getWebModule()) {
          setDefaultWebModule(entry.getValue());
        }
      }
    }
    session.store(serverSettings);
    Condition condition=new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(),new StringLiteral("String_Node_Str"));
    User systemUser=session.querySingle(condition,User.class,OldQuery.getDefault());
    ServerStarted serverStarted=session.create(ServerStarted.class);
    serverStarted.setDate(new Date());
    serverStarted.setAccessMethod(AccessMethod.INTERNAL);
    serverStarted.setExecutor(systemUser);
    try {
      session.store(serverStarted);
      session.commit();
    }
 catch (    BimserverLockConflictException e) {
      throw new BimserverDatabaseException(e);
    }
catch (    ServiceException e) {
      throw new BimserverDatabaseException(e);
    }
 finally {
      session.close();
    }
    webModules=new HashMap<String,WebModulePlugin>();
    DatabaseSession ses=bimDatabase.createSession();
    try {
      List<WebModulePluginConfiguration> webModuleConfigurations=serverSettingsCache.getServerSettings().getWebModules();
      for (      WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
        String contextPath="String_Node_Str";
        for (        Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
          if (parameter.getName().equals("String_Node_Str")) {
            contextPath=((StringType)parameter.getValue()).getValue();
          }
        }
        String identifier=webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
        webModules.put(contextPath,(WebModulePlugin)pluginManager.getPlugin(identifier,true));
      }
    }
  finally {
      ses.close();
    }
    Integer protocolBuffersPort=getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
    if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
      try {
        protocolBuffersServer=new ProtocolBuffersServer(protocolBuffersMetaData,serviceFactory,servicesMap,protocolBuffersPort);
        protocolBuffersServer.start();
      }
 catch (      Exception e) {
        LOGGER.error("String_Node_Str",e);
      }
    }
    bimServerClientFactory=new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(),serviceFactory,servicesMap,pluginManager,metaDataManager);
    pluginManager.setBimServerClientFactory(bimServerClientFactory);
  }
 catch (  BimserverLockConflictException e) {
    throw new BimserverDatabaseException(e);
  }
catch (  PluginException e) {
    throw new BimserverDatabaseException(e);
  }
}

Fixed version (ground truth):
private void initDatabaseDependantItems() throws BimserverDatabaseException {
  serverSettingsCache.init();
  notificationsManager.init();
  getSerializerFactory().init(pluginManager,bimDatabase,this);
  try {
    DatabaseSession session=bimDatabase.createSession();
    try {
      updatePlugins(session);
      session.commit();
    }
 catch (    ServiceException e) {
      LOGGER.error("String_Node_Str",e);
    }
 finally {
      session.close();
    }
    session=bimDatabase.createSession();
    ServerSettings serverSettings=serverSettingsCache.getServerSettings();
    for (    Entry<PluginContext,WebModulePlugin> entry : pluginManager.getAllWebPlugins(true).entrySet()) {
      WebModulePluginConfiguration webPluginConfiguration=find(serverSettings.getWebModules(),entry.getKey().getIdentifier());
      if (webPluginConfiguration == null) {
        webPluginConfiguration=session.create(WebModulePluginConfiguration.class);
        serverSettings.getWebModules().add(webPluginConfiguration);
        PluginDescriptor pluginDescriptor=getPluginDescriptor(session,entry.getKey().getIdentifier());
        if (pluginDescriptor == null) {
          throw new BimserverDatabaseException("String_Node_Str" + entry.getKey().getIdentifier());
        }
        genericPluginConversion(entry.getKey(),session,webPluginConfiguration,pluginDescriptor);
      }
 else {
        if (webPluginConfiguration == serverSettings.getWebModule()) {
          setDefaultWebModule(entry.getValue());
        }
      }
    }
    session.store(serverSettings);
    Condition condition=new AttributeCondition(StorePackage.eINSTANCE.getUser_Username(),new StringLiteral("String_Node_Str"));
    User systemUser=session.querySingle(condition,User.class,OldQuery.getDefault());
    ServerStarted serverStarted=session.create(ServerStarted.class);
    serverStarted.setDate(new Date());
    serverStarted.setAccessMethod(AccessMethod.INTERNAL);
    serverStarted.setExecutor(systemUser);
    try {
      session.store(serverStarted);
      session.commit();
    }
 catch (    BimserverLockConflictException e) {
      throw new BimserverDatabaseException(e);
    }
catch (    ServiceException e) {
      throw new BimserverDatabaseException(e);
    }
 finally {
      session.close();
    }
    webModules=new HashMap<String,WebModulePlugin>();
    DatabaseSession ses=bimDatabase.createSession();
    try {
      List<WebModulePluginConfiguration> webModuleConfigurations=serverSettingsCache.getServerSettings().getWebModules();
      for (      WebModulePluginConfiguration webModulePluginConfiguration : webModuleConfigurations) {
        String contextPath="String_Node_Str";
        for (        Parameter parameter : webModulePluginConfiguration.getSettings().getParameters()) {
          if (parameter.getName().equals("String_Node_Str")) {
            contextPath=((StringType)parameter.getValue()).getValue();
          }
        }
        String identifier=webModulePluginConfiguration.getPluginDescriptor().getIdentifier();
        webModules.put(contextPath,(WebModulePlugin)pluginManager.getPlugin(identifier,true));
      }
    }
  finally {
      ses.close();
    }
    Integer protocolBuffersPort=getServerSettingsCache().getServerSettings().getProtocolBuffersPort();
    if (protocolBuffersPort >= 1 && protocolBuffersPort <= 65535) {
      try {
        protocolBuffersServer=new ProtocolBuffersServer(protocolBuffersMetaData,serviceFactory,servicesMap,protocolBuffersPort);
        protocolBuffersServer.start();
      }
 catch (      Exception e) {
        LOGGER.error("String_Node_Str",e);
      }
    }
    bimServerClientFactory=new DirectBimServerClientFactory<ServiceInterface>(serverSettingsCache.getServerSettings().getSiteAddress(),serviceFactory,servicesMap,pluginManager,metaDataManager);
    pluginManager.setBimServerClientFactory(bimServerClientFactory);
  }
 catch (  BimserverLockConflictException e) {
    throw new BimserverDatabaseException(e);
  }
}