Program: 10766
Project: 10766
Buggy source:
/** 
 * Writes the app's current deployment info into a manifest file in the app's related workspace project. If the workspace project is not accessible, false is returned. If the manifest file does not exist in the app's workspace project, one will be created. If manifest file failed to create, exception is thrown. Returns true if the manifest file was successfully written. If so, the project is also refreshed.
 * @return true if deployment info for the cloud module was written tomanifest file. False if there was no content to write to the manifest file.
 * @throws CoreException if error occurred while writing to a Manifest file.
 */
public boolean write(IProgressMonitor monitor) throws CoreException {
  ApplicationDeploymentInfo deploymentInfo=appModule.getDeploymentInfo();
  if (deploymentInfo == null) {
    return false;
  }
  String appName=deploymentInfo.getDeploymentName();
  Map<Object,Object> deploymentInfoYaml=parseManifestFromFile();
  if (deploymentInfoYaml == null) {
    deploymentInfoYaml=new LinkedHashMap<Object,Object>();
  }
  Object applicationsObj=deploymentInfoYaml.get(APPLICATIONS_PROP);
  List<Map<Object,Object>> applicationsList=null;
  if (applicationsObj == null) {
    applicationsList=new ArrayList<Map<Object,Object>>();
    deploymentInfoYaml.put(APPLICATIONS_PROP,applicationsList);
  }
 else   if (applicationsObj instanceof List<?>) {
    applicationsList=(List<Map<Object,Object>>)applicationsObj;
  }
 else {
    throw CloudErrorUtil.toCoreException("String_Node_Str" + relativePath + "String_Node_Str");
  }
  Map<Object,Object> applicationProperties=null;
  for (  Object appMap : applicationsList) {
    if (appMap instanceof Map<?,?>) {
      applicationProperties=(Map<Object,Object>)appMap;
      if (!appName.equals(applicationProperties.get(NAME_PROP))) {
        applicationProperties=null;
      }
 else {
        break;
      }
    }
  }
  if (applicationProperties == null) {
    applicationProperties=new LinkedHashMap<Object,Object>();
    applicationsList.add(applicationProperties);
  }
  applicationProperties.put(NAME_PROP,appName);
  String memory=getMemoryAsString(deploymentInfo.getMemory());
  if (memory != null) {
    applicationProperties.put(MEMORY_PROP,memory);
  }
  int instances=deploymentInfo.getInstances();
  if (instances > 0) {
    applicationProperties.put(INSTANCES_PROP,instances);
  }
  List<String> urls=deploymentInfo.getUris();
  if (urls != null && !urls.isEmpty()) {
    String url=urls.get(0);
    CloudApplicationUrlLookup lookup=CloudApplicationUrlLookup.getCurrentLookup(cloudServer);
    CloudApplicationURL cloudUrl=lookup.getCloudApplicationURL(url);
    String subdomain=cloudUrl.getSubdomain();
    String domain=cloudUrl.getDomain();
    if (subdomain != null) {
      applicationProperties.put(SUB_DOMAIN_PROP,subdomain);
    }
    if (domain != null) {
      applicationProperties.put(DOMAIN_PROP,domain);
    }
  }
  Staging staging=deploymentInfo.getStaging();
  if (staging != null && staging.getBuildpackUrl() != null) {
    applicationProperties.put(BUILDPACK_PROP,staging.getBuildpackUrl());
  }
  Map<Object,Object> services=new LinkedHashMap<Object,Object>();
  applicationProperties.put(SERVICES_PROP,services);
  List<CloudService> servicesToBind=deploymentInfo.getServices();
  if (servicesToBind != null) {
    for (    CloudService service : servicesToBind) {
      String serviceName=service.getName();
      if (!services.containsKey(serviceName)) {
        if (containsServiceCreationDescription(service)) {
          Map<String,String> serviceDescription=new LinkedHashMap<String,String>();
          String label=service.getLabel();
          if (label != null) {
            serviceDescription.put(LABEL_PROP,label);
          }
          String version=service.getVersion();
          if (version != null) {
            serviceDescription.put(VERSION_PROP,version);
          }
          String plan=service.getPlan();
          if (plan != null) {
            serviceDescription.put(PLAN_PROP,plan);
          }
          String provider=service.getProvider();
          if (provider != null) {
            serviceDescription.put(PROVIDER_PROP,provider);
          }
          services.put(serviceName,serviceDescription);
        }
      }
    }
  }
  if (deploymentInfoYaml.isEmpty()) {
    return false;
  }
  DumperOptions options=new DumperOptions();
  options.setCanonical(false);
  options.setPrettyFlow(true);
  options.setDefaultFlowStyle(FlowStyle.BLOCK);
  Yaml yaml=new Yaml(options);
  String manifestValue=yaml.dump(deploymentInfoYaml);
  if (manifestValue == null) {
    throw CloudErrorUtil.toCoreException("String_Node_Str" + appModule.getDeployedApplicationName() + "String_Node_Str"+ deploymentInfoYaml);
  }
  OutputStream outStream=null;
  try {
    outStream=getOutStream();
    if (outStream == null) {
      throw CloudErrorUtil.toCoreException("String_Node_Str" + relativePath + "String_Node_Str"+ appModule.getDeployedApplicationName());
    }
    outStream.write(manifestValue.getBytes());
    outStream.flush();
    IProject project=CloudUtil.getProject(appModule);
    if (project != null) {
      project.refreshLocal(IResource.DEPTH_INFINITE,monitor);
    }
    return true;
  }
 catch (  IOException io) {
    throw CloudErrorUtil.toCoreException(io);
  }
 finally {
    if (outStream != null) {
      try {
        outStream.close();
      }
 catch (      IOException io) {
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * Writes the app's current deployment info into a manifest file in the app's related workspace project. If the workspace project is not accessible, false is returned. If the manifest file does not exist in the app's workspace project, one will be created. If manifest file failed to create, exception is thrown. Returns true if the manifest file was successfully written. If so, the project is also refreshed.
 * @return true if deployment info for the cloud module was written tomanifest file. False if there was no content to write to the manifest file. <p/> WHne writing content to manifest, if the application has a previous deployment information, and the app name changed, meaning the current name of the application does not match the one in the old deployment information, the old entry in the manifest will be updated to the new name, rather than creating a new entry with the new name. <p/> If both an existing entry with the current application name, as well as an old entry with the old application name, exist, the old entry has higher priority, as the old entry truly represents the application that is being edited.
 * @param monitor progress monitor
 * @param previousInfo Previous deployment information pertaining to thegive application module. May be null if there is no previous information available.
 * @throws CoreException if error occurred while writing to a Manifest file.
 */
public boolean write(IProgressMonitor monitor,ApplicationDeploymentInfo previousInfo) throws CoreException {
  ApplicationDeploymentInfo deploymentInfo=appModule.getDeploymentInfo();
  if (deploymentInfo == null) {
    return false;
  }
  String previousName=previousInfo != null ? previousInfo.getDeploymentName() : null;
  String appName=deploymentInfo.getDeploymentName();
  Map<Object,Object> deploymentInfoYaml=parseManifestFromFile();
  if (deploymentInfoYaml == null) {
    deploymentInfoYaml=new LinkedHashMap<Object,Object>();
  }
  Object applicationsObj=deploymentInfoYaml.get(APPLICATIONS_PROP);
  List<Map<Object,Object>> applicationsList=null;
  if (applicationsObj == null) {
    applicationsList=new ArrayList<Map<Object,Object>>();
    deploymentInfoYaml.put(APPLICATIONS_PROP,applicationsList);
  }
 else   if (applicationsObj instanceof List<?>) {
    applicationsList=(List<Map<Object,Object>>)applicationsObj;
  }
 else {
    throw CloudErrorUtil.toCoreException("String_Node_Str" + relativePath + "String_Node_Str");
  }
  Map<Object,Object> applicationWithSameName=null;
  Map<Object,Object> oldApplication=null;
  for (  Object appMap : applicationsList) {
    if (appMap instanceof Map<?,?>) {
      Map<Object,Object> properties=(Map<Object,Object>)appMap;
      String name=getStringValue(properties,NAME_PROP);
      if (appName.equals(name)) {
        applicationWithSameName=properties;
      }
 else       if (previousName != null && previousName.equals(name)) {
        oldApplication=properties;
      }
    }
  }
  Map<Object,Object> application=oldApplication != null ? oldApplication : applicationWithSameName;
  if (application == null) {
    application=new LinkedHashMap<Object,Object>();
    applicationsList.add(application);
  }
  application.put(NAME_PROP,appName);
  String memory=getMemoryAsString(deploymentInfo.getMemory());
  if (memory != null) {
    application.put(MEMORY_PROP,memory);
  }
  int instances=deploymentInfo.getInstances();
  if (instances > 0) {
    application.put(INSTANCES_PROP,instances);
  }
  List<String> urls=deploymentInfo.getUris();
  if (urls != null && !urls.isEmpty()) {
    String url=urls.get(0);
    CloudApplicationUrlLookup lookup=CloudApplicationUrlLookup.getCurrentLookup(cloudServer);
    CloudApplicationURL cloudUrl=lookup.getCloudApplicationURL(url);
    String subdomain=cloudUrl.getSubdomain();
    String domain=cloudUrl.getDomain();
    if (subdomain != null) {
      application.put(SUB_DOMAIN_PROP,subdomain);
    }
    if (domain != null) {
      application.put(DOMAIN_PROP,domain);
    }
  }
  Staging staging=deploymentInfo.getStaging();
  if (staging != null && staging.getBuildpackUrl() != null) {
    application.put(BUILDPACK_PROP,staging.getBuildpackUrl());
  }
  Map<Object,Object> services=new LinkedHashMap<Object,Object>();
  application.put(SERVICES_PROP,services);
  List<CloudService> servicesToBind=deploymentInfo.getServices();
  if (servicesToBind != null) {
    for (    CloudService service : servicesToBind) {
      String serviceName=service.getName();
      if (!services.containsKey(serviceName)) {
        if (containsServiceCreationDescription(service)) {
          Map<String,String> serviceDescription=new LinkedHashMap<String,String>();
          String label=service.getLabel();
          if (label != null) {
            serviceDescription.put(LABEL_PROP,label);
          }
          String version=service.getVersion();
          if (version != null) {
            serviceDescription.put(VERSION_PROP,version);
          }
          String plan=service.getPlan();
          if (plan != null) {
            serviceDescription.put(PLAN_PROP,plan);
          }
          String provider=service.getProvider();
          if (provider != null) {
            serviceDescription.put(PROVIDER_PROP,provider);
          }
          services.put(serviceName,serviceDescription);
        }
      }
    }
  }
  if (deploymentInfoYaml.isEmpty()) {
    return false;
  }
  DumperOptions options=new DumperOptions();
  options.setCanonical(false);
  options.setPrettyFlow(true);
  options.setDefaultFlowStyle(FlowStyle.BLOCK);
  Yaml yaml=new Yaml(options);
  String manifestValue=yaml.dump(deploymentInfoYaml);
  if (manifestValue == null) {
    throw CloudErrorUtil.toCoreException("String_Node_Str" + appModule.getDeployedApplicationName() + "String_Node_Str"+ deploymentInfoYaml);
  }
  OutputStream outStream=null;
  try {
    outStream=getOutStream();
    if (outStream == null) {
      throw CloudErrorUtil.toCoreException("String_Node_Str" + relativePath + "String_Node_Str"+ appModule.getDeployedApplicationName());
    }
    outStream.write(manifestValue.getBytes());
    outStream.flush();
    IProject project=CloudUtil.getProject(appModule);
    if (project != null) {
      project.refreshLocal(IResource.DEPTH_INFINITE,monitor);
    }
    return true;
  }
 catch (  IOException io) {
    throw CloudErrorUtil.toCoreException(io);
  }
 finally {
    if (outStream != null) {
      try {
        outStream.close();
      }
 catch (      IOException io) {
      }
    }
  }
}