Program: 39378
Project: 39378
Buggy source:
@PostConstruct public void init(){
  LOG.info("String_Node_Str");
  long time=System.currentTimeMillis();
  pluginStateResolver.setPluginAccessor(this);
  Set<InternalPlugin> pluginsFromDescriptor=pluginDescriptorParser.loadPlugins();
  Set<QcadooPluginPlugin> pluginsFromDatabase=pluginDao.list();
  for (  InternalPlugin plugin : pluginsFromDescriptor) {
    QcadooPluginPlugin existingPlugin=null;
    for (    QcadooPluginPlugin databasePlugin : pluginsFromDatabase) {
      if (plugin.getIdentifier().equals(databasePlugin.getIdentifier())) {
        existingPlugin=databasePlugin;
        break;
      }
    }
    if (existingPlugin != null) {
      plugin.changeStateTo(PluginState.valueOf(existingPlugin.getState()));
    }
 else {
      plugin.changeStateTo(PluginState.ENABLING);
    }
    if (existingPlugin == null || plugin.compareVersion(new Version(existingPlugin.getVersion())) > 0) {
      pluginDao.save(plugin);
    }
 else     if (plugin.compareVersion(new Version(existingPlugin.getVersion())) < 0) {
      throw new IllegalStateException("String_Node_Str" + plugin.getIdentifier());
    }
    LOG.info("String_Node_Str" + plugin);
    plugins.put(plugin.getIdentifier(),plugin);
  }
  for (  QcadooPluginPlugin databasePlugin : pluginsFromDatabase) {
    if (databasePlugin.getState().equals(PluginState.TEMPORARY.toString())) {
      continue;
    }
    Plugin existingPlugin=null;
    for (    Plugin plugin : pluginsFromDescriptor) {
      if (databasePlugin.getIdentifier().equals(plugin.getIdentifier())) {
        existingPlugin=plugin;
        break;
      }
    }
    if (existingPlugin == null) {
      pluginDao.delete(databasePlugin);
    }
  }
  List<Plugin> sortedPlugins=pluginDependencyManager.sortPluginsInDependencyOrder(plugins.values(),plugins);
  moduleFactoryAccessor.init(sortedPlugins);
  for (  Plugin plugin : sortedPlugins) {
    if (plugin.hasState(PluginState.ENABLING)) {
      ((InternalPlugin)plugin).changeStateTo(PluginState.ENABLED);
      pluginDao.save(plugin);
    }
  }
  LOG.info("String_Node_Str" + (System.currentTimeMillis() - time) + "String_Node_Str");
}

Fixed version (ground truth):
@PostConstruct public void init(){
  LOG.info("String_Node_Str");
  long time=System.currentTimeMillis();
  pluginStateResolver.setPluginAccessor(this);
  Set<InternalPlugin> pluginsFromDescriptor=pluginDescriptorParser.loadPlugins();
  Set<QcadooPluginPlugin> pluginsFromDatabase=pluginDao.list();
  for (  InternalPlugin plugin : pluginsFromDescriptor) {
    QcadooPluginPlugin existingPlugin=null;
    for (    QcadooPluginPlugin databasePlugin : pluginsFromDatabase) {
      if (plugin.getIdentifier().equals(databasePlugin.getIdentifier())) {
        existingPlugin=databasePlugin;
        break;
      }
    }
    if (existingPlugin != null) {
      plugin.changeStateTo(PluginState.valueOf(existingPlugin.getState()));
    }
 else {
      plugin.changeStateTo(PluginState.ENABLING);
    }
    if (existingPlugin == null || plugin.compareVersion(new Version(existingPlugin.getVersion())) > 0) {
      pluginDao.save(plugin);
    }
 else     if (plugin.compareVersion(new Version(existingPlugin.getVersion())) < 0) {
      throw new IllegalStateException("String_Node_Str" + plugin.getIdentifier());
    }
    LOG.info("String_Node_Str" + plugin);
    plugins.put(plugin.getIdentifier(),plugin);
  }
  for (  QcadooPluginPlugin databasePlugin : pluginsFromDatabase) {
    if (databasePlugin.getState().equals(PluginState.TEMPORARY.toString())) {
      continue;
    }
    Plugin existingPlugin=null;
    for (    Plugin plugin : pluginsFromDescriptor) {
      if (databasePlugin.getIdentifier().equals(plugin.getIdentifier())) {
        existingPlugin=plugin;
        break;
      }
    }
    if (existingPlugin == null) {
      pluginDao.delete(databasePlugin);
    }
  }
  LOG.info("String_Node_Str" + (System.currentTimeMillis() - time) + "String_Node_Str");
}