Program: 41008
Project: 41008
Buggy source:
/** 
 * Exports the given BuildPlans repackaged with the CSAR denoted by the given CSARID
 * @param buildPlans the BuildPlans to export
 * @param csarId the CSARID of a CSAR
 * @return a File denoting the absolute Path to the exported CSAR
 */
public File export(List<BuildPlan> buildPlans,CSARID csarId){
  CSARContent csarContent=null;
  try {
    csarContent=this.handler.getCSARContentForID(csarId);
  }
 catch (  UserException e1) {
    Exporter.LOG.error("String_Node_Str",e1);
  }
  if (csarContent == null) {
    return null;
  }
  String csarName=csarId.getFileName();
  IFileAccessService service=this.getFileAccessService();
  File tempDir=service.getTemp();
  File pathToRepackagedCsar=service.getTemp();
  File repackagedCsar=new File(pathToRepackagedCsar,csarName);
  try {
    Set<AbstractFile> files=csarContent.getFilesRecursively();
    AbstractFile mainDefFile=csarContent.getRootTOSCA();
    File rootDefFile=mainDefFile.getFile().toFile();
    Definitions defs=this.parseDefinitionsFile(rootDefFile);
    List<TServiceTemplate> servTemps=this.getServiceTemplates(defs);
    List<BuildPlan> plansToExport=new ArrayList<BuildPlan>();
    for (    BuildPlan buildPlan : buildPlans) {
      for (      TServiceTemplate serviceTemplate : servTemps) {
        if (buildPlan.getServiceTemplate().toString().equals(this.buildQName(defs,serviceTemplate).toString())) {
          TPlans plans=serviceTemplate.getPlans();
          if (plans == null) {
            plans=this.toscaFactory.createTPlans();
            serviceTemplate.setPlans(plans);
          }
          List<TPlan> planList=plans.getPlan();
          planList.add(this.generateTPlanElement(buildPlan));
          plansToExport.add(buildPlan);
        }
      }
    }
    for (    AbstractFile file : files) {
      if (file.getFile().toFile().toString().equals(rootDefFile.toString())) {
        continue;
      }
      File newLocation=new File(tempDir,file.getPath());
      Exporter.LOG.debug(newLocation.getAbsolutePath());
      Exporter.LOG.debug(file.getFile().toString());
      if (newLocation.isDirectory()) {
        FileUtils.copyDirectory(file.getFile().toFile(),newLocation);
      }
 else {
        FileUtils.copyFile(file.getFile().toFile(),newLocation);
      }
    }
    File newDefsFile=new File(tempDir,mainDefFile.getPath());
    newDefsFile.createNewFile();
    JAXBContext jaxbContext=JAXBContext.newInstance(Definitions.class);
    Marshaller m=jaxbContext.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
    m.marshal(defs,newDefsFile);
    for (    BuildPlan plan : plansToExport) {
      File planPath=new File(tempDir,this.generateRelativePlanPath(plan));
      Exporter.LOG.debug(planPath.toString());
      planPath.getParentFile().mkdirs();
      planPath.createNewFile();
      this.simpleExporter.export(planPath.toURI(),plan);
    }
    File selfServiceDir=new File(tempDir,"String_Node_Str");
    File selfServiceDataXml=new File(selfServiceDir,"String_Node_Str");
    JAXBContext jaxbContextWineryApplication=JAXBContext.newInstance(Application.class);
    if (selfServiceDir.exists() && selfServiceDataXml.exists()) {
      Unmarshaller u=jaxbContextWineryApplication.createUnmarshaller();
      Application appDesc=(Application)u.unmarshal(selfServiceDataXml);
      if (appDesc.getOptions() != null) {
        for (        ApplicationOption option : appDesc.getOptions().getOption()) {
          for (          BuildPlan plan : plansToExport) {
            if (option.getPlanServiceName().equals(this.getBuildPlanServiceName(plan.getDeploymentDeskriptor()).getLocalPart())) {
              if (!new File(selfServiceDir,option.getPlanInputMessageUrl()).exists()) {
                File planInputFile=new File(selfServiceDir,option.getPlanInputMessageUrl());
                this.writePlanInputMessageInstance(plan,planInputFile);
              }
            }
          }
        }
      }
 else {
        int optionCounter=1;
        Application.Options options=new Application.Options();
        for (        BuildPlan plan : plansToExport) {
          ApplicationOption option=new ApplicationOption();
          option.setName("String_Node_Str" + optionCounter);
          option.setId(String.valueOf(optionCounter));
          option.setIconUrl("String_Node_Str");
          option.setDescription("String_Node_Str");
          option.setPlanServiceName(this.getBuildPlanServiceName(plan.getDeploymentDeskriptor()).getLocalPart());
          option.setPlanInputMessageUrl("String_Node_Str" + optionCounter + "String_Node_Str");
          this.writePlanInputMessageInstance(plan,new File(selfServiceDir,"String_Node_Str" + optionCounter + "String_Node_Str"));
          optionCounter++;
          options.getOption().add(option);
        }
        appDesc.setOptions(options);
        Marshaller wineryAppMarshaller=jaxbContextWineryApplication.createMarshaller();
        wineryAppMarshaller.marshal(appDesc,selfServiceDataXml);
      }
    }
 else {
      if (selfServiceDir.mkdirs() && selfServiceDataXml.createNewFile()) {
        Application appDesc=new Application();
        appDesc.setDisplayName(csarName);
        appDesc.setDescription("String_Node_Str");
        appDesc.setIconUrl("String_Node_Str");
        appDesc.setImageUrl("String_Node_Str");
        int optionCounter=1;
        Application.Options options=new Application.Options();
        for (        BuildPlan plan : plansToExport) {
          ApplicationOption option=new ApplicationOption();
          option.setName("String_Node_Str" + optionCounter);
          option.setId(String.valueOf(optionCounter));
          option.setIconUrl("String_Node_Str");
          option.setDescription("String_Node_Str");
          option.setPlanServiceName(this.getBuildPlanServiceName(plan.getDeploymentDeskriptor()).getLocalPart());
          option.setPlanInputMessageUrl("String_Node_Str" + optionCounter + "String_Node_Str");
          this.writePlanInputMessageInstance(plan,new File(selfServiceDir,"String_Node_Str" + optionCounter + "String_Node_Str"));
          optionCounter++;
          options.getOption().add(option);
        }
        appDesc.setOptions(options);
        Marshaller wineryAppMarshaller=jaxbContextWineryApplication.createMarshaller();
        wineryAppMarshaller.marshal(appDesc,selfServiceDataXml);
      }
    }
  }
 catch (  IOException e) {
    Exporter.LOG.error("String_Node_Str",e);
  }
catch (  JAXBException e) {
    Exporter.LOG.error("String_Node_Str",e);
  }
catch (  SystemException e) {
    Exporter.LOG.error("String_Node_Str",e);
  }
  service.zip(tempDir,repackagedCsar);
  Exporter.LOG.debug(repackagedCsar.toString());
  return repackagedCsar;
}

Fixed version (ground truth):
/** 
 * Exports the given BuildPlans repackaged with the CSAR denoted by the given CSARID
 * @param buildPlans the BuildPlans to export
 * @param csarId the CSARID of a CSAR
 * @return a File denoting the absolute Path to the exported CSAR
 */
public File export(List<BuildPlan> buildPlans,CSARID csarId){
  CSARContent csarContent=null;
  try {
    csarContent=this.handler.getCSARContentForID(csarId);
  }
 catch (  UserException e1) {
    Exporter.LOG.error("String_Node_Str",e1);
  }
  if (csarContent == null) {
    return null;
  }
  String csarName=csarId.getFileName();
  IFileAccessService service=this.getFileAccessService();
  File tempDir=service.getTemp();
  File pathToRepackagedCsar=service.getTemp();
  File repackagedCsar=new File(pathToRepackagedCsar,csarName);
  try {
    Set<AbstractFile> files=csarContent.getFilesRecursively();
    AbstractFile mainDefFile=csarContent.getRootTOSCA();
    File rootDefFile=mainDefFile.getFile().toFile();
    Definitions defs=this.parseDefinitionsFile(rootDefFile);
    List<TServiceTemplate> servTemps=this.getServiceTemplates(defs);
    List<BuildPlan> plansToExport=new ArrayList<BuildPlan>();
    for (    BuildPlan buildPlan : buildPlans) {
      for (      TServiceTemplate serviceTemplate : servTemps) {
        if (buildPlan.getServiceTemplate().equals(this.buildQName(defs,serviceTemplate))) {
          TPlans plans=serviceTemplate.getPlans();
          if (plans == null) {
            plans=this.toscaFactory.createTPlans();
            serviceTemplate.setPlans(plans);
          }
          List<TPlan> planList=plans.getPlan();
          planList.add(this.generateTPlanElement(buildPlan));
          plansToExport.add(buildPlan);
        }
      }
    }
    for (    AbstractFile file : files) {
      if (file.getFile().toFile().toString().equals(rootDefFile.toString())) {
        continue;
      }
      File newLocation=new File(tempDir,file.getPath());
      Exporter.LOG.debug(newLocation.getAbsolutePath());
      Exporter.LOG.debug(file.getFile().toString());
      if (newLocation.isDirectory()) {
        FileUtils.copyDirectory(file.getFile().toFile(),newLocation);
      }
 else {
        FileUtils.copyFile(file.getFile().toFile(),newLocation);
      }
    }
    File newDefsFile=new File(tempDir,mainDefFile.getPath());
    newDefsFile.createNewFile();
    JAXBContext jaxbContext=JAXBContext.newInstance(Definitions.class);
    Marshaller m=jaxbContext.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
    m.marshal(defs,newDefsFile);
    for (    BuildPlan plan : plansToExport) {
      File planPath=new File(tempDir,this.generateRelativePlanPath(plan));
      Exporter.LOG.debug(planPath.toString());
      planPath.getParentFile().mkdirs();
      planPath.createNewFile();
      this.simpleExporter.export(planPath.toURI(),plan);
    }
    File selfServiceDir=new File(tempDir,"String_Node_Str");
    File selfServiceDataXml=new File(selfServiceDir,"String_Node_Str");
    JAXBContext jaxbContextWineryApplication=JAXBContext.newInstance(Application.class);
    if (selfServiceDir.exists() && selfServiceDataXml.exists()) {
      Unmarshaller u=jaxbContextWineryApplication.createUnmarshaller();
      Application appDesc=(Application)u.unmarshal(selfServiceDataXml);
      if (appDesc.getOptions() != null) {
        for (        ApplicationOption option : appDesc.getOptions().getOption()) {
          for (          BuildPlan plan : plansToExport) {
            if (option.getPlanServiceName().equals(this.getBuildPlanServiceName(plan.getDeploymentDeskriptor()).getLocalPart())) {
              if (!new File(selfServiceDir,option.getPlanInputMessageUrl()).exists()) {
                File planInputFile=new File(selfServiceDir,option.getPlanInputMessageUrl());
                this.writePlanInputMessageInstance(plan,planInputFile);
              }
            }
          }
        }
      }
 else {
        int optionCounter=1;
        Application.Options options=new Application.Options();
        for (        BuildPlan plan : plansToExport) {
          ApplicationOption option=new ApplicationOption();
          option.setName("String_Node_Str" + optionCounter);
          option.setId(String.valueOf(optionCounter));
          option.setIconUrl("String_Node_Str");
          option.setDescription("String_Node_Str");
          option.setPlanServiceName(this.getBuildPlanServiceName(plan.getDeploymentDeskriptor()).getLocalPart());
          option.setPlanInputMessageUrl("String_Node_Str" + optionCounter + "String_Node_Str");
          this.writePlanInputMessageInstance(plan,new File(selfServiceDir,"String_Node_Str" + optionCounter + "String_Node_Str"));
          optionCounter++;
          options.getOption().add(option);
        }
        appDesc.setOptions(options);
        Marshaller wineryAppMarshaller=jaxbContextWineryApplication.createMarshaller();
        wineryAppMarshaller.marshal(appDesc,selfServiceDataXml);
      }
    }
 else {
      if (selfServiceDir.mkdirs() && selfServiceDataXml.createNewFile()) {
        Application appDesc=new Application();
        appDesc.setDisplayName(csarName);
        appDesc.setDescription("String_Node_Str");
        appDesc.setIconUrl("String_Node_Str");
        appDesc.setImageUrl("String_Node_Str");
        int optionCounter=1;
        Application.Options options=new Application.Options();
        for (        BuildPlan plan : plansToExport) {
          ApplicationOption option=new ApplicationOption();
          option.setName("String_Node_Str" + optionCounter);
          option.setId(String.valueOf(optionCounter));
          option.setIconUrl("String_Node_Str");
          option.setDescription("String_Node_Str");
          option.setPlanServiceName(this.getBuildPlanServiceName(plan.getDeploymentDeskriptor()).getLocalPart());
          option.setPlanInputMessageUrl("String_Node_Str" + optionCounter + "String_Node_Str");
          this.writePlanInputMessageInstance(plan,new File(selfServiceDir,"String_Node_Str" + optionCounter + "String_Node_Str"));
          optionCounter++;
          options.getOption().add(option);
        }
        appDesc.setOptions(options);
        Marshaller wineryAppMarshaller=jaxbContextWineryApplication.createMarshaller();
        wineryAppMarshaller.marshal(appDesc,selfServiceDataXml);
      }
    }
  }
 catch (  IOException e) {
    Exporter.LOG.error("String_Node_Str",e);
  }
catch (  JAXBException e) {
    Exporter.LOG.error("String_Node_Str",e);
  }
catch (  SystemException e) {
    Exporter.LOG.error("String_Node_Str",e);
  }
  service.zip(tempDir,repackagedCsar);
  Exporter.LOG.debug(repackagedCsar.toString());
  return repackagedCsar;
}