Program: 10792
Project: 10792
Buggy source:
public void updateModules(Map<String,CloudApplication> applicationByName) throws CoreException {
  Server server=(Server)getServer();
  final Set<CloudFoundryApplicationModule> allModules=new HashSet<CloudFoundryApplicationModule>();
  List<CloudFoundryApplicationModule> externalModules=new ArrayList<CloudFoundryApplicationModule>();
  final Set<IModule> deletedModules=new HashSet<IModule>();
synchronized (this) {
    for (    IModule module : server.getModules()) {
      CloudFoundryApplicationModule appModule=getApplication(module);
      CloudApplication application=applicationByName.remove(appModule.getApplicationId());
      appModule.setCloudApplication(application);
      if (application != null) {
        if (appModule.isExternal()) {
          externalModules.add(appModule);
        }
        allModules.add(appModule);
      }
 else       if (getData().isUndeployed(module)) {
        allModules.add(appModule);
      }
 else {
        deletedModules.add(module);
      }
    }
    for (    CloudApplication application : applicationByName.values()) {
      CloudFoundryApplicationModule appModule=getData().createModule(application);
      externalModules.add(appModule);
      allModules.add(appModule);
    }
    server.setExternalModules(externalModules.toArray(new IModule[0]));
    for (    IModule module : server.getModules()) {
      CloudFoundryApplicationModule appModule=getApplication(module);
      updateState(server,appModule);
    }
    if (deletedModules.size() > 0) {
      for (      IModule module : deletedModules) {
        server.setModuleState(new IModule[]{module},IServer.STATE_UNKNOWN);
      }
      deleteModules(deletedModules);
    }
    getData().removeObsoleteModules(allModules);
  }
}

Fixed version (ground truth):
public void updateModules(Map<String,CloudApplication> applicationByName) throws CoreException {
  Server server=(Server)getServer();
  final Set<CloudFoundryApplicationModule> allModules=new HashSet<CloudFoundryApplicationModule>();
  List<CloudFoundryApplicationModule> externalModules=new ArrayList<CloudFoundryApplicationModule>();
  final Set<IModule> deletedModules=new HashSet<IModule>();
synchronized (this) {
    for (    IModule module : server.getModules()) {
      CloudFoundryApplicationModule appModule=getApplication(module);
      CloudApplication application=applicationByName.remove(appModule.getApplicationId());
      appModule.setCloudApplication(application);
      if (application != null) {
        if (appModule.isExternal()) {
          externalModules.add(appModule);
        }
        allModules.add(appModule);
      }
 else       if (getData() != null && getData().isUndeployed(module)) {
        allModules.add(appModule);
      }
 else {
        deletedModules.add(module);
      }
    }
    if (getData() != null) {
      for (      CloudApplication application : applicationByName.values()) {
        CloudFoundryApplicationModule appModule=getData().createModule(application);
        externalModules.add(appModule);
        allModules.add(appModule);
      }
    }
    server.setExternalModules(externalModules.toArray(new IModule[0]));
    for (    IModule module : server.getModules()) {
      CloudFoundryApplicationModule appModule=getApplication(module);
      updateState(server,appModule);
    }
    if (deletedModules.size() > 0) {
      for (      IModule module : deletedModules) {
        server.setModuleState(new IModule[]{module},IServer.STATE_UNKNOWN);
      }
      deleteModules(deletedModules);
    }
    if (getData() != null) {
      getData().removeObsoleteModules(allModules);
    }
  }
}