Program: 10947
Project: 10947
Buggy source:
@Override public DeploymentDescriptor prepareForDeployment(final CloudFoundryServer server,final ApplicationModule appModule,final IProgressMonitor monitor){
  final DeploymentDescriptor descriptor=new DeploymentDescriptor();
  CloudApplication existingApp=appModule.getApplication();
  if (existingApp != null) {
    descriptor.applicationInfo=new ApplicationInfo(existingApp.getName());
    descriptor.deploymentInfo=new DeploymentInfo();
    descriptor.deploymentInfo.setUris(existingApp.getUris());
    descriptor.deploymentMode=ApplicationAction.START;
    DeploymentInfo lastDeploymentInfo=appModule.getLastDeploymentInfo();
    if (lastDeploymentInfo != null) {
      descriptor.deploymentInfo.setServices(lastDeploymentInfo.getServices());
    }
  }
 else {
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        CloudFoundryApplicationWizard wizard=new CloudFoundryApplicationWizard(server,appModule);
        WizardDialog dialog=new WizardDialog(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),wizard);
        int status=dialog.open();
        if (status == Dialog.OK) {
          descriptor.applicationInfo=wizard.getApplicationInfo();
          descriptor.deploymentInfo=wizard.getDeploymentInfo();
          descriptor.deploymentMode=wizard.getDeploymentMode();
          descriptor.staging=wizard.getStaging();
          final List<CloudService> addedServices=wizard.getAddedCloudServices();
          if (!addedServices.isEmpty()) {
            IProgressMonitor subMonitor=new SubProgressMonitor(monitor,addedServices.size());
            try {
              server.getBehaviour().createService(addedServices.toArray(new CloudService[0]),subMonitor);
            }
 catch (            CoreException e) {
              CloudFoundryPlugin.logError(e);
            }
 finally {
              subMonitor.done();
            }
          }
          List<String> selectedServices=wizard.getSelectedCloudServicesID();
          descriptor.deploymentInfo.setServices(selectedServices);
        }
      }
    }
);
  }
  if (descriptor.deploymentInfo == null) {
    throw new OperationCanceledException();
  }
  return descriptor;
}

Fixed version (ground truth):
@Override public DeploymentDescriptor prepareForDeployment(final CloudFoundryServer server,final ApplicationModule appModule,final IProgressMonitor monitor){
  final DeploymentDescriptor descriptor=new DeploymentDescriptor();
  CloudApplication existingApp=appModule.getApplication();
  if (existingApp != null) {
    descriptor.applicationInfo=new ApplicationInfo(existingApp.getName());
    descriptor.deploymentInfo=new DeploymentInfo();
    descriptor.deploymentInfo.setUris(existingApp.getUris());
    descriptor.deploymentMode=ApplicationAction.START;
    descriptor.staging=getStaging(appModule);
    DeploymentInfo lastDeploymentInfo=appModule.getLastDeploymentInfo();
    if (lastDeploymentInfo != null) {
      descriptor.deploymentInfo.setServices(lastDeploymentInfo.getServices());
    }
  }
 else {
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        CloudFoundryApplicationWizard wizard=new CloudFoundryApplicationWizard(server,appModule);
        WizardDialog dialog=new WizardDialog(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),wizard);
        int status=dialog.open();
        if (status == Dialog.OK) {
          descriptor.applicationInfo=wizard.getApplicationInfo();
          descriptor.deploymentInfo=wizard.getDeploymentInfo();
          descriptor.deploymentMode=wizard.getDeploymentMode();
          descriptor.staging=wizard.getStaging();
          final List<CloudService> addedServices=wizard.getAddedCloudServices();
          if (!addedServices.isEmpty()) {
            IProgressMonitor subMonitor=new SubProgressMonitor(monitor,addedServices.size());
            try {
              server.getBehaviour().createService(addedServices.toArray(new CloudService[0]),subMonitor);
            }
 catch (            CoreException e) {
              CloudFoundryPlugin.logError(e);
            }
 finally {
              subMonitor.done();
            }
          }
          List<String> selectedServices=wizard.getSelectedCloudServicesID();
          descriptor.deploymentInfo.setServices(selectedServices);
        }
      }
    }
);
  }
  if (descriptor.deploymentInfo == null) {
    throw new OperationCanceledException();
  }
  return descriptor;
}