Program: 125229
Project: 125229
Buggy source:
public void generateTemplates(boolean overwrite) throws Exception {
  IProcessor processor=getJobProcessor();
  if (processor == null) {
    return;
  }
  ITalendProcessJavaProject codeProject=getJobProcessor().getTalendJavaProject();
  if (codeProject == null) {
    return;
  }
  Property property=codeProject.getPropery();
  if (property == null) {
    return;
  }
  String contextName=getOptionString(TalendProcessArgumentConstant.ARG_CONTEXT_NAME);
  if (contextName == null) {
    contextName=processor.getContext().getName();
  }
  String jobClass=JavaResourcesHelper.getJobClassPackageName(property.getItem()) + "String_Node_Str" + property.getLabel();
  StringBuffer windowsScriptAdditionValue=new StringBuffer(50);
  StringBuffer unixScriptAdditionValue=new StringBuffer(50);
  if (StringUtils.isNotEmpty(this.getWindowsScriptAddition())) {
    windowsScriptAdditionValue.append(this.getWindowsScriptAddition());
  }
  if (StringUtils.isNotEmpty(this.getWindowsScriptAddition())) {
    unixScriptAdditionValue.append(this.getUnixScriptAddition());
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_NEED_CONTEXT)) {
    final String contextPart=TalendProcessArgumentConstant.CMD_ARG_CONTEXT_NAME + contextName;
    addScriptAddition(windowsScriptAdditionValue,contextPart);
    addScriptAddition(unixScriptAdditionValue,contextPart);
  }
  List paramsList=ProcessUtils.getOptionValue(getArgumentsMap(),TalendProcessArgumentConstant.ARG_CONTEXT_PARAMS,(List)null);
  if (paramsList != null && !paramsList.isEmpty()) {
    StringBuffer contextParamPart=new StringBuffer(100);
    for (    Object param : paramsList) {
      if (param instanceof ContextParameterType) {
        ContextParameterType contextParamType=(ContextParameterType)param;
        contextParamPart.append(' ');
        contextParamPart.append(TalendProcessArgumentConstant.CMD_ARG_CONTEXT_PARAMETER);
        contextParamPart.append(' ');
        contextParamPart.append(contextParamType.getName());
        contextParamPart.append('=');
        String value=contextParamType.getRawValue();
        if (!contextParamType.getType().equals("String_Node_Str")) {
          value=StringEscapeUtils.escapeJava(value);
        }
        if (value == null) {
          contextParamPart.append((String)null);
        }
 else {
          value=TalendQuoteUtils.addPairQuotesIfNotExist(value);
          contextParamPart.append(value);
        }
      }
    }
    if (contextParamPart.length() > 0) {
      addScriptAddition(windowsScriptAdditionValue,contextParamPart.toString());
      addScriptAddition(unixScriptAdditionValue,contextParamPart.toString());
    }
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_ENABLE_LOG4J) && isOptionChecked(TalendProcessArgumentConstant.ARG_NEED_LOG4J_LEVEL)) {
    String log4jLevel=getOptionString(TalendProcessArgumentConstant.ARG_LOG4J_LEVEL);
    if (StringUtils.isNotEmpty(log4jLevel)) {
      String log4jLevelPart=log4jLevel;
      if (!log4jLevel.startsWith(TalendProcessArgumentConstant.CMD_ARG_LOG4J_LEVEL)) {
        log4jLevelPart=TalendProcessArgumentConstant.CMD_ARG_LOG4J_LEVEL + log4jLevel;
      }
      addScriptAddition(windowsScriptAdditionValue,log4jLevelPart);
      addScriptAddition(unixScriptAdditionValue,log4jLevelPart);
    }
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_ENABLE_STATS)) {
    String statsPort=getOptionString(TalendProcessArgumentConstant.ARG_PORT_STATS);
    if (StringUtils.isNotEmpty(statsPort)) {
      String statsPortPart=TalendProcessArgumentConstant.CMD_ARG_STATS_PORT + statsPort;
      addScriptAddition(windowsScriptAdditionValue,statsPortPart);
      addScriptAddition(unixScriptAdditionValue,statsPortPart);
    }
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_ENABLE_TRACS)) {
    String tracPort=getOptionString(TalendProcessArgumentConstant.ARG_PORT_TRACS);
    if (StringUtils.isNotEmpty(tracPort)) {
      String tracPortPart=TalendProcessArgumentConstant.CMD_ARG_TRACE_PORT + tracPort;
      addScriptAddition(windowsScriptAdditionValue,tracPortPart);
      addScriptAddition(unixScriptAdditionValue,tracPortPart);
    }
  }
  String watchParam=getOptionString(TalendProcessArgumentConstant.ARG_ENABLE_WATCH);
  if (StringUtils.isNotEmpty(watchParam)) {
    addScriptAddition(windowsScriptAdditionValue,TalendProcessArgumentConstant.CMD_ARG_WATCH);
    addScriptAddition(unixScriptAdditionValue,TalendProcessArgumentConstant.CMD_ARG_WATCH);
  }
  String[] jvmArgs=processor.getJVMArgs();
  StringBuilder jvmArgsStr=new StringBuilder();
  StringBuilder jvmArgsStrPs1=new StringBuilder();
  if (jvmArgs != null && jvmArgs.length > 0) {
    for (    String arg : jvmArgs) {
      jvmArgsStr.append(arg + "String_Node_Str");
      jvmArgsStrPs1.append("String_Node_Str" + arg + "String_Node_Str");
    }
  }
  final Map<String,Object> templateParameters=PomUtil.getTemplateParameters(property);
  String batContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_BAT,templateParameters);
  batContent=StringUtils.replaceEach(batContent,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},new String[]{jvmArgsStr.toString().trim(),getWindowsClasspath(),jobClass,windowsScriptAdditionValue.toString()});
  String shContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_SH,templateParameters);
  shContent=StringUtils.replaceEach(shContent,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},new String[]{jvmArgsStr.toString().trim(),getUnixClasspath(),jobClass,unixScriptAdditionValue.toString()});
  String psContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_PS,templateParameters);
  psContent=StringUtils.replaceEach(psContent,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},new String[]{jvmArgsStrPs1.toString().trim(),getWindowsClasspathForPs1(),jobClass,windowsScriptAdditionValue.toString()});
  String jobInfoContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_JOB_INFO,templateParameters);
  String projectTechName=ProjectManager.getInstance().getProject(property).getTechnicalLabel();
  org.talend.core.model.general.Project project=ProjectManager.getInstance().getProjectFromProjectTechLabel(projectTechName);
  if (project == null) {
    project=ProjectManager.getInstance().getCurrentProject();
  }
  String mainProjectBranch=ProjectManager.getInstance().getMainProjectBranch(project);
  if (mainProjectBranch == null) {
    ProjectPreferenceManager preferenceManager=new ProjectPreferenceManager(project,"String_Node_Str",false);
    mainProjectBranch=preferenceManager.getValue(RepositoryConstants.PROJECT_BRANCH_ID);
    if (mainProjectBranch == null) {
      mainProjectBranch="String_Node_Str";
    }
  }
  jobInfoContent=StringUtils.replace(jobInfoContent,"String_Node_Str",mainProjectBranch);
  IFolder templateFolder=codeProject.getTemplatesFolder();
  IFile shFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_RUN_SH_TEMPLATE_FILE_NAME);
  IFile batFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_RUN_BAT_TEMPLATE_FILE_NAME);
  IFile psFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_RUN_PS_TEMPLATE_FILE_NAME);
  IFile infoFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_INFO_TEMPLATE_FILE_NAME);
  MavenTemplateManager.saveContent(batFile,batContent,overwrite);
  MavenTemplateManager.saveContent(shFile,shContent,overwrite);
  MavenTemplateManager.saveContent(psFile,psContent,overwrite);
  MavenTemplateManager.saveContent(infoFile,jobInfoContent,overwrite);
}

Fixed version (ground truth):
public void generateTemplates(boolean overwrite) throws Exception {
  IProcessor processor=getJobProcessor();
  if (processor == null) {
    return;
  }
  ITalendProcessJavaProject codeProject=getJobProcessor().getTalendJavaProject();
  if (codeProject == null) {
    return;
  }
  Property property=codeProject.getPropery();
  if (property == null) {
    return;
  }
  String contextName=getOptionString(TalendProcessArgumentConstant.ARG_CONTEXT_NAME);
  if (contextName == null) {
    contextName=processor.getContext().getName();
  }
  String jobClass=JavaResourcesHelper.getJobClassPackageName(property.getItem()) + "String_Node_Str" + property.getLabel();
  StringBuffer windowsScriptAdditionValue=new StringBuffer(50);
  StringBuffer unixScriptAdditionValue=new StringBuffer(50);
  if (StringUtils.isNotEmpty(this.getWindowsScriptAddition())) {
    windowsScriptAdditionValue.append(this.getWindowsScriptAddition());
  }
  if (StringUtils.isNotEmpty(this.getUnixScriptAddition())) {
    unixScriptAdditionValue.append(this.getUnixScriptAddition());
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_NEED_CONTEXT)) {
    final String contextPart=TalendProcessArgumentConstant.CMD_ARG_CONTEXT_NAME + contextName;
    addScriptAddition(windowsScriptAdditionValue,contextPart);
    addScriptAddition(unixScriptAdditionValue,contextPart);
  }
  List paramsList=ProcessUtils.getOptionValue(getArgumentsMap(),TalendProcessArgumentConstant.ARG_CONTEXT_PARAMS,(List)null);
  if (paramsList != null && !paramsList.isEmpty()) {
    StringBuffer contextParamPart=new StringBuffer(100);
    for (    Object param : paramsList) {
      if (param instanceof ContextParameterType) {
        ContextParameterType contextParamType=(ContextParameterType)param;
        contextParamPart.append(' ');
        contextParamPart.append(TalendProcessArgumentConstant.CMD_ARG_CONTEXT_PARAMETER);
        contextParamPart.append(' ');
        contextParamPart.append(contextParamType.getName());
        contextParamPart.append('=');
        String value=contextParamType.getRawValue();
        if (!contextParamType.getType().equals("String_Node_Str")) {
          value=StringEscapeUtils.escapeJava(value);
        }
        if (value == null) {
          contextParamPart.append((String)null);
        }
 else {
          value=TalendQuoteUtils.addPairQuotesIfNotExist(value);
          contextParamPart.append(value);
        }
      }
    }
    if (contextParamPart.length() > 0) {
      addScriptAddition(windowsScriptAdditionValue,contextParamPart.toString());
      addScriptAddition(unixScriptAdditionValue,contextParamPart.toString());
    }
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_ENABLE_LOG4J) && isOptionChecked(TalendProcessArgumentConstant.ARG_NEED_LOG4J_LEVEL)) {
    String log4jLevel=getOptionString(TalendProcessArgumentConstant.ARG_LOG4J_LEVEL);
    if (StringUtils.isNotEmpty(log4jLevel)) {
      String log4jLevelPart=log4jLevel;
      if (!log4jLevel.startsWith(TalendProcessArgumentConstant.CMD_ARG_LOG4J_LEVEL)) {
        log4jLevelPart=TalendProcessArgumentConstant.CMD_ARG_LOG4J_LEVEL + log4jLevel;
      }
      addScriptAddition(windowsScriptAdditionValue,log4jLevelPart);
      addScriptAddition(unixScriptAdditionValue,log4jLevelPart);
    }
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_ENABLE_STATS)) {
    String statsPort=getOptionString(TalendProcessArgumentConstant.ARG_PORT_STATS);
    if (StringUtils.isNotEmpty(statsPort)) {
      String statsPortPart=TalendProcessArgumentConstant.CMD_ARG_STATS_PORT + statsPort;
      addScriptAddition(windowsScriptAdditionValue,statsPortPart);
      addScriptAddition(unixScriptAdditionValue,statsPortPart);
    }
  }
  if (isOptionChecked(TalendProcessArgumentConstant.ARG_ENABLE_TRACS)) {
    String tracPort=getOptionString(TalendProcessArgumentConstant.ARG_PORT_TRACS);
    if (StringUtils.isNotEmpty(tracPort)) {
      String tracPortPart=TalendProcessArgumentConstant.CMD_ARG_TRACE_PORT + tracPort;
      addScriptAddition(windowsScriptAdditionValue,tracPortPart);
      addScriptAddition(unixScriptAdditionValue,tracPortPart);
    }
  }
  String watchParam=getOptionString(TalendProcessArgumentConstant.ARG_ENABLE_WATCH);
  if (StringUtils.isNotEmpty(watchParam)) {
    addScriptAddition(windowsScriptAdditionValue,TalendProcessArgumentConstant.CMD_ARG_WATCH);
    addScriptAddition(unixScriptAdditionValue,TalendProcessArgumentConstant.CMD_ARG_WATCH);
  }
  String[] jvmArgs=processor.getJVMArgs();
  StringBuilder jvmArgsStr=new StringBuilder();
  StringBuilder jvmArgsStrPs1=new StringBuilder();
  if (jvmArgs != null && jvmArgs.length > 0) {
    for (    String arg : jvmArgs) {
      jvmArgsStr.append(arg + "String_Node_Str");
      jvmArgsStrPs1.append("String_Node_Str" + arg + "String_Node_Str");
    }
  }
  final Map<String,Object> templateParameters=PomUtil.getTemplateParameters(property);
  String batContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_BAT,templateParameters);
  batContent=StringUtils.replaceEach(batContent,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},new String[]{jvmArgsStr.toString().trim(),getWindowsClasspath(),jobClass,windowsScriptAdditionValue.toString()});
  String shContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_SH,templateParameters);
  shContent=StringUtils.replaceEach(shContent,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},new String[]{jvmArgsStr.toString().trim(),getUnixClasspath(),jobClass,unixScriptAdditionValue.toString()});
  String psContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_PS,templateParameters);
  psContent=StringUtils.replaceEach(psContent,new String[]{"String_Node_Str","String_Node_Str","String_Node_Str","String_Node_Str"},new String[]{jvmArgsStrPs1.toString().trim(),getWindowsClasspathForPs1(),jobClass,windowsScriptAdditionValue.toString()});
  String jobInfoContent=MavenTemplateManager.getProjectSettingValue(IProjectSettingPreferenceConstants.TEMPLATE_JOB_INFO,templateParameters);
  String projectTechName=ProjectManager.getInstance().getProject(property).getTechnicalLabel();
  org.talend.core.model.general.Project project=ProjectManager.getInstance().getProjectFromProjectTechLabel(projectTechName);
  if (project == null) {
    project=ProjectManager.getInstance().getCurrentProject();
  }
  String mainProjectBranch=ProjectManager.getInstance().getMainProjectBranch(project);
  if (mainProjectBranch == null) {
    ProjectPreferenceManager preferenceManager=new ProjectPreferenceManager(project,"String_Node_Str",false);
    mainProjectBranch=preferenceManager.getValue(RepositoryConstants.PROJECT_BRANCH_ID);
    if (mainProjectBranch == null) {
      mainProjectBranch="String_Node_Str";
    }
  }
  jobInfoContent=StringUtils.replace(jobInfoContent,"String_Node_Str",mainProjectBranch);
  IFolder templateFolder=codeProject.getTemplatesFolder();
  IFile shFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_RUN_SH_TEMPLATE_FILE_NAME);
  IFile batFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_RUN_BAT_TEMPLATE_FILE_NAME);
  IFile psFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_RUN_PS_TEMPLATE_FILE_NAME);
  IFile infoFile=templateFolder.getFile(IProjectSettingTemplateConstants.JOB_INFO_TEMPLATE_FILE_NAME);
  MavenTemplateManager.saveContent(batFile,batContent,overwrite);
  MavenTemplateManager.saveContent(shFile,shContent,overwrite);
  MavenTemplateManager.saveContent(psFile,psContent,overwrite);
  MavenTemplateManager.saveContent(infoFile,jobInfoContent,overwrite);
}