Program: 10905
Project: 10905
Buggy source:
private CloudApplication doDeployApplication(CloudFoundryOperations client,final ApplicationModule appModule,final DeploymentDescriptor descriptor,IProgressMonitor monitor) throws CoreException {
  Assert.isNotNull(descriptor.applicationInfo);
  ApplicationInfo applicationInfo=descriptor.applicationInfo;
  String applicationId=applicationInfo.getAppName();
  appModule.setLastApplicationInfo(applicationInfo);
  appModule.setLastDeploymentInfo(descriptor.deploymentInfo);
  try {
    List<CloudApplication> existingApps=client.getApplications();
    boolean found=false;
    for (    CloudApplication existingApp : existingApps) {
      if (existingApp.getName().equals(applicationId)) {
        found=true;
        break;
      }
    }
    if (!found) {
      Staging staging=descriptor.staging;
      if (staging != null) {
        List<String> uris=descriptor.deploymentInfo.getUris() != null ? descriptor.deploymentInfo.getUris() : new ArrayList<String>();
        List<String> services=descriptor.deploymentInfo.getServices() != null ? descriptor.deploymentInfo.getServices() : new ArrayList<String>();
        client.createApplication(applicationId,staging,descriptor.deploymentInfo.getMemory(),uris,services);
      }
 else {
        client.createApplication(applicationId,applicationInfo.getFramework(),descriptor.deploymentInfo.getMemory(),descriptor.deploymentInfo.getUris(),descriptor.deploymentInfo.getServices());
      }
    }
    File warFile=applicationInfo.getWarFile();
    if (warFile != null) {
      client.uploadApplication(applicationId,warFile);
    }
 else {
      ApplicationArchive archive=descriptor.applicationArchive;
      if (archive instanceof ModuleResourceApplicationArchive) {
        final ModuleResourceApplicationArchive moduleArchive=(ModuleResourceApplicationArchive)archive;
        client.uploadApplication(applicationId,archive,new UploadStatusCallback(){
          public void onProcessMatchedResources(          int length){
          }
          public void onMatchedFileNames(          Set<String> matchedFileNames){
            moduleArchive.generatePartialWarFile(matchedFileNames);
          }
          public void onCheckResources(){
          }
        }
);
      }
 else {
        client.uploadApplication(applicationId,archive);
      }
    }
  }
 catch (  IOException e) {
    throw new CoreException(new Status(IStatus.ERROR,CloudFoundryPlugin.PLUGIN_ID,NLS.bind("String_Node_Str",applicationInfo.getWarFile()),e));
  }
  try {
    CloudApplication application=waitForUpload(client,applicationId,monitor);
    appModule.setCloudApplication(application);
    return application;
  }
 catch (  InterruptedException e) {
    throw new OperationCanceledException();
  }
}

Fixed version (ground truth):
private CloudApplication doDeployApplication(CloudFoundryOperations client,final ApplicationModule appModule,final DeploymentDescriptor descriptor,IProgressMonitor monitor) throws CoreException {
  Assert.isNotNull(descriptor.applicationInfo);
  ApplicationInfo applicationInfo=descriptor.applicationInfo;
  String applicationId=applicationInfo.getAppName();
  appModule.setLastApplicationInfo(applicationInfo);
  appModule.setLastDeploymentInfo(descriptor.deploymentInfo);
  try {
    List<CloudApplication> existingApps=client.getApplications();
    boolean found=false;
    for (    CloudApplication existingApp : existingApps) {
      if (existingApp.getName().equals(applicationId)) {
        found=true;
        break;
      }
    }
    if (!found) {
      Staging staging=descriptor.staging;
      if (staging != null) {
        List<String> uris=descriptor.deploymentInfo.getUris() != null ? descriptor.deploymentInfo.getUris() : new ArrayList<String>();
        List<String> services=descriptor.deploymentInfo.getServices() != null ? descriptor.deploymentInfo.getServices() : new ArrayList<String>();
        client.createApplication(applicationId,staging,descriptor.deploymentInfo.getMemory(),uris,services,null);
      }
 else {
        client.createApplication(applicationId,applicationInfo.getFramework(),descriptor.deploymentInfo.getMemory(),descriptor.deploymentInfo.getUris(),descriptor.deploymentInfo.getServices());
      }
    }
    File warFile=applicationInfo.getWarFile();
    if (warFile != null) {
      client.uploadApplication(applicationId,warFile);
    }
 else {
      ApplicationArchive archive=descriptor.applicationArchive;
      if (archive instanceof ModuleResourceApplicationArchive) {
        final ModuleResourceApplicationArchive moduleArchive=(ModuleResourceApplicationArchive)archive;
        client.uploadApplication(applicationId,archive,new UploadStatusCallback(){
          public void onProcessMatchedResources(          int length){
          }
          public void onMatchedFileNames(          Set<String> matchedFileNames){
            moduleArchive.generatePartialWarFile(matchedFileNames);
          }
          public void onCheckResources(){
          }
        }
);
      }
 else {
        client.uploadApplication(applicationId,archive);
      }
    }
  }
 catch (  IOException e) {
    throw new CoreException(new Status(IStatus.ERROR,CloudFoundryPlugin.PLUGIN_ID,NLS.bind("String_Node_Str",applicationInfo.getWarFile()),e));
  }
  try {
    CloudApplication application=waitForUpload(client,applicationId,monitor);
    appModule.setCloudApplication(application);
    return application;
  }
 catch (  InterruptedException e) {
    throw new OperationCanceledException();
  }
}