Program: 10761
Project: 10761
Buggy source:
/** 
 * Obtain a valid deployment info containing enough information to push an application, start it if necessary (starting an application is optional), and also optionally bind services to the application
 * @param server where application should be pushed to.
 * @param appModule pertaining to the application that needs to be pushed.
 * @param monitor
 * @throws CoreException if invalid deployment info.
 * @throws OperationCanceledException if user canceled deployment.
 */
public void prepareForDeployment(final CloudFoundryServer server,final CloudFoundryApplicationModule appModule,final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
  IModule module=appModule.getLocalModule();
  RepublishModule repModule=CloudFoundryPlugin.getModuleCache().getData(server.getServerOriginal()).untagForAutomaticRepublish(module);
  if (repModule != null) {
    ApplicationDeploymentInfo republishDeploymentInfo=repModule.getDeploymentInfo();
    if (republishDeploymentInfo != null) {
      DeploymentInfoWorkingCopy copy=appModule.getDeploymentInfoWorkingCopy();
      copy.setInfo(republishDeploymentInfo);
      copy.save();
    }
  }
  if (!appModule.validateDeploymentInfo().isOK()) {
    final ApplicationWizardDelegate providerDelegate=ApplicationWizardRegistry.getWizardProvider(appModule.getLocalModule());
    if (providerDelegate == null) {
      throw CloudErrorUtil.toCoreException("String_Node_Str" + appModule.getDeployedApplicationName() + "String_Node_Str"+ server.getServer().getName()+ "String_Node_Str"+ appModule.getLocalModule().getModuleType().getId());
    }
    DeploymentInfoWorkingCopy workingCopy=null;
    try {
      workingCopy=new ManifestParser(appModule,server).load();
    }
 catch (    CoreException ce) {
      CloudFoundryPlugin.log(ce);
    }
    final boolean[] cancelled={false};
    final boolean[] writeToManifest={false};
    final DeploymentInfoWorkingCopy finWorkingCopy=workingCopy;
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        CloudFoundryApplicationWizard wizard=new CloudFoundryApplicationWizard(server,appModule,finWorkingCopy,providerDelegate);
        WizardDialog dialog=new WizardDialog(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),wizard);
        int status=dialog.open();
        if (status == Dialog.OK) {
          final List<CloudService> addedServices=wizard.getCreatedCloudServices();
          writeToManifest[0]=wizard.persistManifestChanges();
          if (addedServices != null && !addedServices.isEmpty()) {
            IProgressMonitor subMonitor=new SubProgressMonitor(monitor,addedServices.size());
            try {
              server.getBehaviour().createService(addedServices.toArray(new CloudService[0]),subMonitor);
            }
 catch (            CoreException e) {
              CloudFoundryPlugin.log(e);
            }
 finally {
              subMonitor.done();
            }
          }
        }
 else {
          cancelled[0]=true;
        }
      }
    }
);
    if (cancelled[0]) {
      throw new OperationCanceledException();
    }
 else {
      IStatus status=appModule.validateDeploymentInfo();
      if (!status.isOK()) {
        throw new CoreException(status);
      }
 else       if (writeToManifest[0]) {
        IProgressMonitor subMonitor=new SubProgressMonitor(monitor,1);
        try {
          new ManifestParser(appModule,server).write(subMonitor);
        }
 catch (        CoreException ce) {
          CloudFoundryPlugin.logError(ce);
        }
 finally {
          subMonitor.done();
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Obtain a valid deployment info containing enough information to push an application, start it if necessary (starting an application is optional), and also optionally bind services to the application
 * @param server where application should be pushed to.
 * @param appModule pertaining to the application that needs to be pushed.
 * @param monitor
 * @throws CoreException if invalid deployment info.
 * @throws OperationCanceledException if user canceled deployment.
 */
public void prepareForDeployment(final CloudFoundryServer server,final CloudFoundryApplicationModule appModule,final IProgressMonitor monitor) throws CoreException, OperationCanceledException {
  IModule module=appModule.getLocalModule();
  RepublishModule repModule=CloudFoundryPlugin.getModuleCache().getData(server.getServerOriginal()).untagForAutomaticRepublish(module);
  if (repModule != null) {
    ApplicationDeploymentInfo republishDeploymentInfo=repModule.getDeploymentInfo();
    if (republishDeploymentInfo != null) {
      DeploymentInfoWorkingCopy copy=appModule.getDeploymentInfoWorkingCopy();
      copy.setInfo(republishDeploymentInfo);
      copy.save();
    }
  }
  if (!appModule.validateDeploymentInfo().isOK()) {
    final ApplicationWizardDelegate providerDelegate=ApplicationWizardRegistry.getWizardProvider(appModule.getLocalModule());
    if (providerDelegate == null) {
      throw CloudErrorUtil.toCoreException("String_Node_Str" + appModule.getDeployedApplicationName() + "String_Node_Str"+ server.getServer().getName()+ "String_Node_Str"+ appModule.getLocalModule().getModuleType().getId());
    }
    DeploymentInfoWorkingCopy workingCopy=null;
    try {
      workingCopy=new ManifestParser(appModule,server).load();
    }
 catch (    CoreException ce) {
      CloudFoundryPlugin.log(ce);
    }
    final boolean[] cancelled={false};
    final boolean[] writeToManifest={false};
    final IStatus status[]={Status.OK_STATUS};
    final DeploymentInfoWorkingCopy finWorkingCopy=workingCopy;
    Display.getDefault().syncExec(new Runnable(){
      public void run(){
        CloudFoundryApplicationWizard wizard=new CloudFoundryApplicationWizard(server,appModule,finWorkingCopy,providerDelegate);
        try {
          WizardDialog dialog=new WizardDialog(PlatformUI.getWorkbench().getModalDialogShellProvider().getShell(),wizard);
          int dialogueStatus=dialog.open();
          if (dialogueStatus == Dialog.OK) {
            final List<CloudService> addedServices=wizard.getCreatedCloudServices();
            writeToManifest[0]=wizard.persistManifestChanges();
            if (addedServices != null && !addedServices.isEmpty()) {
              IProgressMonitor subMonitor=new SubProgressMonitor(monitor,addedServices.size());
              try {
                server.getBehaviour().createService(addedServices.toArray(new CloudService[0]),subMonitor);
              }
 catch (              CoreException e) {
                CloudFoundryPlugin.log(e);
              }
 finally {
                subMonitor.done();
              }
            }
          }
 else {
            cancelled[0]=true;
          }
        }
 catch (        Throwable t) {
          cancelled[0]=true;
          status[0]=CloudFoundryPlugin.getErrorStatus(t);
        }
      }
    }
);
    if (cancelled[0]) {
      if (!status[0].isOK()) {
        CloudFoundryPlugin.logError("String_Node_Str" + status[0].getMessage(),status[0].getException());
      }
      throw new OperationCanceledException();
    }
 else {
      if (status[0].isOK()) {
        status[0]=appModule.validateDeploymentInfo();
      }
      if (!status[0].isOK()) {
        throw new CoreException(status[0]);
      }
 else       if (writeToManifest[0]) {
        IProgressMonitor subMonitor=new SubProgressMonitor(monitor,1);
        try {
          new ManifestParser(appModule,server).write(subMonitor);
        }
 catch (        CoreException ce) {
          CloudFoundryPlugin.logError(ce);
        }
 finally {
          subMonitor.done();
        }
      }
    }
  }
}