Program: 10757
Project: 10757
Buggy source:
/** 
 * Update the local (WST) (   {@link IModule} ) and corresponding cloud module(  {@link CloudFoundryApplicationModule} ) such that they are in synchwith the actual deployed applications (represented by {@link CloudApplication} ). Local WST modules ( {@link IModule} ) that donot have a corresponding deployed application (  {@link CloudApplication}) will be removed.
 * @param deployedApplications
 * @throws CoreException
 */
public void updateModules(Map<String,CloudApplication> deployedApplications) 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 cloudModule=getCloudModule(module);
      if (cloudModule == null) {
        CloudFoundryPlugin.logError("String_Node_Str" + module.getName() + "String_Node_Str");
        continue;
      }
      CloudApplication actualApplication=deployedApplications.remove(cloudModule.getDeployedApplicationName());
      cloudModule.setCloudApplication(actualApplication);
      if (actualApplication != null) {
        if (cloudModule.isExternal()) {
          externalModules.add(cloudModule);
        }
        allModules.add(cloudModule);
      }
 else       if (getData() != null && getData().isUndeployed(module)) {
        allModules.add(cloudModule);
      }
 else {
        deletedModules.add(module);
      }
    }
    if (getData() != null) {
      for (      CloudApplication application : deployedApplications.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=getExistingCloudModule(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);
    }
  }
}

Fixed version (ground truth):
/** 
 * Update the local (WST) (   {@link IModule} ) and corresponding cloud module(  {@link CloudFoundryApplicationModule} ) such that they are in synchwith the actual deployed applications (represented by {@link CloudApplication} ). Local WST modules ( {@link IModule} ) that donot have a corresponding deployed application (  {@link CloudApplication}) will be removed.
 * @param deployedApplications
 * @throws CoreException
 */
public void updateModules(Map<String,CloudApplication> deployedApplications) 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 cloudModule=getCloudModule(module);
      if (cloudModule == null) {
        CloudFoundryPlugin.logError("String_Node_Str" + module.getName() + "String_Node_Str");
        continue;
      }
      CloudApplication actualApplication=deployedApplications.remove(cloudModule.getDeployedApplicationName());
      cloudModule.setCloudApplication(actualApplication);
      if (actualApplication != null) {
        if (cloudModule.isExternal()) {
          externalModules.add(cloudModule);
        }
        allModules.add(cloudModule);
      }
 else       if (getData() != null && getData().isUndeployed(module)) {
        allModules.add(cloudModule);
      }
 else {
        deletedModules.add(module);
      }
    }
    if (getData() != null) {
      for (      CloudApplication application : deployedApplications.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=getExistingCloudModule(module);
      if (appModule != null) {
        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);
    }
  }
}