nus-yam/ex-repair huggingface dataset:
Program: 10837
Project: 10837
Buggy source:
public static List<String> getOptionVariables(ServiceCommand serviceCommand,String options){
  if (options == null || serviceCommand == null) {
    return Collections.emptyList();
  }
  options=options.trim();
  List<String> variableList=new ArrayList<String>();
  StringWriter variableBuffer=null;
  for (int i=0; i < options.length(); i++) {
    if (options.charAt(i) == '$') {
      variableBuffer=new StringWriter();
    }
 else     if ((options.charAt(i) == '}' || i == options.length() - 1) && variableBuffer != null) {
      if (variableBuffer.getBuffer().length() > 0) {
        variableList.add(variableBuffer.toString());
      }
      variableBuffer=null;
    }
 else     if (variableBuffer != null && options.charAt(i) != '{') {
      variableBuffer.append(options.charAt(i));
    }
  }
  return variableList;
}

Fixed version (ground truth):
public static List<String> getOptionVariables(ServiceCommand serviceCommand,String options){
  if (options == null || serviceCommand == null) {
    return Collections.emptyList();
  }
  options=options.trim();
  List<String> variableList=new ArrayList<String>();
  StringWriter variableBuffer=null;
  for (int i=0; i < options.length(); i++) {
    if ((options.charAt(i) == '$') && i + 1 < options.length() && (options.charAt(i + 1) == '{')) {
      variableBuffer=new StringWriter();
      i++;
    }
 else     if ((options.charAt(i) == '}') && variableBuffer != null) {
      if (variableBuffer.getBuffer().length() > 0) {
        variableList.add(variableBuffer.toString());
      }
      variableBuffer=null;
    }
 else     if (variableBuffer != null) {
      variableBuffer.append(options.charAt(i));
    }
  }
  return variableList;
}
Program: 10839
Project: 10839
Buggy source:
/** 
 * Will resolve an option variables for tunnel options like username and password, and prompt the user for non-user variables. Returns a service command with resolved variables, or null if the user cancelled entering values for non-user variables. If not service command is returned, it indicates that the application command should not be executed.
 * @return resolved service command, or null if variables are not resolved,most likely due to user canceling the prompt
 */
public ServiceCommand promptForValues(){
  Map<String,String> resolvedOptionVars=new HashMap<String,String>();
  Map<String,String> resolvedEnvVariables=new HashMap<String,String>();
  boolean shouldPromptForNonTunnel=resolveTunnelOptions(resolvedOptionVars);
  shouldPromptForNonTunnel|=resolveEnvironmentVariables(resolvedEnvVariables);
  if (shouldPromptForNonTunnel) {
    resolvedOptionVars=promptForUnsetValues(resolvedOptionVars,resolvedEnvVariables);
    if (resolvedOptionVars == null) {
      return null;
    }
  }
  ServiceCommand.setOptionVariableValues(serviceCommand,resolvedOptionVars);
  List<EnvironmentVariable> variables=serviceCommand.getEnvironmentVariables();
  if (variables != null) {
    for (    EnvironmentVariable var : variables) {
      String value=resolvedEnvVariables.get(var.getVariable());
      if (value != null) {
        var.setValue(value);
      }
    }
  }
  return serviceCommand;
}

Fixed version (ground truth):
/** 
 * Will resolve an option variables for tunnel options like user name and password, and prompt the user for non-user variables. Returns a service command with resolved variables, or null if the user cancelled entering values for non-user variables. If not service command is returned, it indicates that the application command should not be executed.
 * @return resolved service command, or null if variables are not resolved,most likely due to user canceling the prompt
 */
public ServiceCommand promptForValues(){
  Map<String,String> resolvedOptionVars=new HashMap<String,String>();
  Map<String,String> resolvedEnvVariables=new HashMap<String,String>();
  boolean shouldPromptOptions=resolveTunnelOptions(resolvedOptionVars);
  boolean shouldPromptEnvVariables=resolveEnvironmentVariables(resolvedEnvVariables);
  if (shouldPromptOptions || shouldPromptEnvVariables) {
    boolean executeCommand=promptForUnsetValues(resolvedOptionVars,resolvedEnvVariables);
    if (!executeCommand) {
      return null;
    }
  }
  ServiceCommand.setOptionVariableValues(serviceCommand,resolvedOptionVars);
  List<EnvironmentVariable> variables=serviceCommand.getEnvironmentVariables();
  if (variables != null) {
    for (    EnvironmentVariable var : variables) {
      String value=resolvedEnvVariables.get(var.getVariable());
      if (value != null) {
        var.setValue(value);
      }
    }
  }
  return serviceCommand;
}
Program: 10840
Project: 10840
Buggy source:
protected boolean resolveEnvironmentVariables(Map<String,String> envVariables){
  List<EnvironmentVariable> vars=serviceCommand.getEnvironmentVariables();
  boolean shouldPrompt=false;
  if (vars != null) {
    for (    EnvironmentVariable var : vars) {
      String varName=EnvironmentVariable.getValueVariable(var);
      String value=resolveTunnelVariable(varName);
      if (value == null) {
        shouldPrompt=true;
      }
      envVariables.put(var.getVariable(),value);
    }
  }
  return shouldPrompt;
}

Fixed version (ground truth):
protected boolean resolveEnvironmentVariables(Map<String,String> envVariables){
  List<EnvironmentVariable> vars=serviceCommand.getEnvironmentVariables();
  boolean shouldPrompt=false;
  if (vars != null) {
    for (    EnvironmentVariable var : vars) {
      String valueVar=EnvironmentVariable.getValueVariable(var);
      String value=var.getValue();
      if (valueVar != null) {
        value=resolveTunnelVariable(valueVar);
        if (value == null) {
          shouldPrompt=true;
        }
      }
      envVariables.put(var.getVariable(),value);
    }
  }
  return shouldPrompt;
}
Program: 10841
Project: 10841
Buggy source:
/** 
 * @param optionsVariables
 * @return resolved values or null if user cancelled entered values for thevariables
 */
protected Map<String,String> promptForUnsetValues(Map<String,String> optionsVariables,Map<String,String> envVariables){
  Map<String,String> resolvedVariables=optionsVariables;
  if ((optionsVariables != null && !optionsVariables.isEmpty()) || (envVariables != null && !envVariables.isEmpty())) {
    UnsetOptionsWizard wizard=new UnsetOptionsWizard(optionsVariables);
    WizardDialog dialog=new WizardDialog(shell,wizard);
    if (dialog.open() == Window.OK) {
      resolvedVariables=wizard.getVariables();
    }
 else {
      return null;
    }
  }
  return resolvedVariables;
}

Fixed version (ground truth):
/** 
 * Prompts user for missing environment or options Variables. The map arguments should be modifiable as they are modified by the UI
 * @return true if the user entered missing values. False if user cancelled or there were no values to enter
 */
protected boolean promptForUnsetValues(Map<String,String> optionsVariables,Map<String,String> envVariables){
  if ((optionsVariables != null && !optionsVariables.isEmpty()) || (envVariables != null && !envVariables.isEmpty())) {
    SetValueVariablesWizard wizard=new SetValueVariablesWizard(optionsVariables,envVariables);
    WizardDialog dialog=new WizardDialog(shell,wizard);
    if (dialog.open() == Window.OK) {
      return true;
    }
 else {
      return false;
    }
  }
  return false;
}
Program: 10842
Project: 10842
Buggy source:
@Override protected void createAreas(Composite parent){
  createURLArea(parent);
  createMemoryArea(parent);
  createCCNGPlanArea(parent);
  IProject project=module.getLocalModule().getProject();
  standalonePart=new StandaloneStartCommandPart(new JavaStartCommand(),this,project);
  standalonePart.createPart(parent);
  createStartOrDebugOptions(parent);
}

Fixed version (ground truth):
@Override protected void createAreas(Composite parent){
  Composite topComposite=new Composite(parent,SWT.NONE);
  GridLayout topLayout=new GridLayout(2,false);
  topComposite.setLayout(topLayout);
  topComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));
  createURLArea(topComposite);
  createMemoryArea(topComposite);
  createCCNGPlanArea(topComposite);
  IProject project=module.getLocalModule().getProject();
  standalonePart=new StandaloneStartCommandPart(new JavaStartCommand(),this,project);
  standalonePart.createPart(topComposite);
  createStartOrDebugOptions(topComposite);
}
Program: 10843
Project: 10843
Buggy source:
@Override protected void createStartOrDebugOptions(Composite parent){
  super.createStartOrDebugOptions(parent);
  if (isServerDebugModeAllowed()) {
    GridData buttonData=new GridData(SWT.FILL,SWT.FILL,false,false);
    regularStartOnDeploymentButton.setLayoutData(buttonData);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(runDebugOptions);
  }
}

Fixed version (ground truth):
@Override protected void createStartOrDebugOptions(Composite parent){
  super.createStartOrDebugOptions(parent);
  if (isServerDebugModeAllowed()) {
    regularStartOnDeploymentButton.setText("String_Node_Str");
    GridData buttonData=new GridData(SWT.FILL,SWT.FILL,false,false);
    regularStartOnDeploymentButton.setLayoutData(buttonData);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(runDebugOptions);
  }
}
Program: 10844
Project: 10844
Buggy source:
protected void createAreas(Composite parent){
  createURLArea(parent);
  createMemoryArea(parent);
  createCCNGPlanArea(parent);
  createStartOrDebugOptions(parent);
}

Fixed version (ground truth):
protected void createAreas(Composite parent){
  Composite topComposite=new Composite(parent,SWT.NONE);
  GridLayout topLayout=new GridLayout(2,false);
  topComposite.setLayout(topLayout);
  topComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));
  createURLArea(topComposite);
  createMemoryArea(topComposite);
  createCCNGPlanArea(topComposite);
  createStartOrDebugOptions(parent);
}
Program: 10845
Project: 10845
Buggy source:
public void createControl(Composite parent){
  setTitle("String_Node_Str");
  setDescription("String_Node_Str");
  ImageDescriptor banner=CloudFoundryImages.getWizardBanner(serverTypeId);
  if (banner != null) {
    setImageDescriptor(banner);
  }
  this.wizard=(CloudFoundryApplicationWizard)getWizard();
  Composite composite=new Composite(parent,SWT.NONE);
  composite.setLayout(new GridLayout());
  composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
  Composite topComposite=new Composite(composite,SWT.NONE);
  GridLayout topLayout=new GridLayout(2,false);
  topComposite.setLayout(topLayout);
  topComposite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));
  createAreas(topComposite);
  setControl(composite);
  update(false);
}

Fixed version (ground truth):
public void createControl(Composite parent){
  setTitle("String_Node_Str");
  setDescription("String_Node_Str");
  ImageDescriptor banner=CloudFoundryImages.getWizardBanner(serverTypeId);
  if (banner != null) {
    setImageDescriptor(banner);
  }
  this.wizard=(CloudFoundryApplicationWizard)getWizard();
  Composite composite=new Composite(parent,SWT.NONE);
  composite.setLayout(new GridLayout());
  composite.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,true));
  createAreas(composite);
  setControl(composite);
  update(false);
}
Program: 10846
Project: 10846
Buggy source:
public void run(){
  if (editorPage.isDisposed())   return;
  if (masterDetailsBlock.getMasterPart().getManagedForm().getForm().isDisposed())   return;
  masterDetailsBlock.refreshUI(area);
  IStatus status=event.getResult();
  Throwable exception=status.getException();
  if (!userAction) {
    return;
  }
  if (exception != null) {
    if (exception instanceof CoreException) {
      if (CloudUtil.isNotFoundException((CoreException)exception)) {
        display404Error(status);
        return;
      }
      if (userAction && CloudUtil.isWrongCredentialsException((CoreException)exception)) {
        CloudFoundryCredentialsWizard wizard=new CloudFoundryCredentialsWizard(editorPage.getCloudServer());
        WizardDialog dialog=new WizardDialog(Display.getDefault().getActiveShell(),wizard);
        if (dialog.open() == Dialog.OK) {
          CloudFoundryEditorAction.this.run();
          return;
        }
      }
    }
    editorPage.setMessage(status.getMessage(),IMessageProvider.ERROR);
  }
 else {
    IModule currentModule=editorPage.getMasterDetailsBlock().getCurrentModule();
    if (currentModule != null) {
      ApplicationModule appModule=editorPage.getCloudServer().getApplication(currentModule);
      if (appModule != null && appModule.getErrorMessage() != null) {
        editorPage.setMessage(appModule.getErrorMessage(),IMessageProvider.ERROR);
        return;
      }
    }
    editorPage.setMessage(null,IMessageProvider.NONE);
  }
}

Fixed version (ground truth):
public void run(){
  if (editorPage.isDisposed())   return;
  if (masterDetailsBlock.getMasterPart().getManagedForm().getForm().isDisposed())   return;
  masterDetailsBlock.refreshUI(area);
  IStatus status=event.getResult();
  Throwable exception=status.getException();
  if (!userAction) {
    return;
  }
  if (exception != null) {
    if (exception instanceof CoreException) {
      if (CloudUtil.isNotFoundException((CoreException)exception)) {
        display404Error(status);
        return;
      }
      if (userAction && CloudUtil.isWrongCredentialsException((CoreException)exception)) {
        CloudFoundryCredentialsWizard wizard=new CloudFoundryCredentialsWizard(editorPage.getCloudServer());
        WizardDialog dialog=new WizardDialog(Display.getDefault().getActiveShell(),wizard);
        if (dialog.open() == Dialog.OK) {
          CloudFoundryEditorAction.this.run();
          return;
        }
      }
    }
    setErrorInPage(status);
  }
 else {
    IModule currentModule=editorPage.getMasterDetailsBlock().getCurrentModule();
    if (currentModule != null) {
      ApplicationModule appModule=editorPage.getCloudServer().getApplication(currentModule);
      if (appModule != null && appModule.getErrorMessage() != null) {
        setErrorInPage(appModule.getErrorMessage());
        return;
      }
    }
    setErrorInPage((String)null);
  }
}
Program: 10848
Project: 10848
Buggy source:
protected void display404Error(IStatus status){
  editorPage.setMessage(status.getMessage(),IMessageProvider.ERROR);
}

Fixed version (ground truth):
/** 
 * Default behaviour is to display the error from the status. Subclasses can override to show other messages.
 */
protected void display404Error(IStatus status){
  setErrorInPage(status);
}
Program: 10850
Project: 10850
Buggy source:
public void setMessage(String message,int messageType){
  if (message == null) {
    sform.setMessage(null,IMessageProvider.NONE);
  }
 else {
    sform.setMessage(message,messageType);
  }
}

Fixed version (ground truth):
public void setMessage(String message,int messageType){
  String messageToDisplay=message;
  if (messageToDisplay == null) {
    sform.setMessage(null,IMessageProvider.NONE);
  }
 else {
    StringBuffer buffer=new StringBuffer(messageToDisplay);
    for (int i=0; i < buffer.length(); i++) {
      char ch=buffer.charAt(i);
      if (ch == '\r' || ch == '\n') {
        buffer.replace(i,i + 1,"String_Node_Str");
      }
    }
    if (buffer.length() > MAX_ERROR_MESSAGE) {
      String endingSegment="String_Node_Str";
      messageToDisplay=buffer.substring(0,MAX_ERROR_MESSAGE).trim() + endingSegment;
      CloudFoundryPlugin.logError(message);
    }
 else {
      messageToDisplay=buffer.toString();
    }
    sform.setMessage(messageToDisplay,messageType);
  }
}
Program: 10851
Project: 10851
Buggy source:
@Override public List<ApplicationFramework> getSupportedFrameworks(){
  List<ApplicationFramework> frameworks=new ArrayList<ApplicationFramework>();
  frameworks.add(new ApplicationFramework(STANDALONE_FRAMEWORK,STANDALONE_FRAMEWORK));
  return frameworks;
}

Fixed version (ground truth):
public List<ApplicationFramework> getSupportedFrameworks(){
  List<ApplicationFramework> frameworks=new ArrayList<ApplicationFramework>();
  frameworks.add(new ApplicationFramework(STANDALONE_FRAMEWORK,STANDALONE_FRAMEWORK));
  return frameworks;
}
Program: 10852
Project: 10852
Buggy source:
@Override public List<ApplicationRuntime> getRuntimes(CloudFoundryServer activeServer) throws CoreException {
  List<ApplicationRuntime> runtimes=new JavaRuntimeTypeHelper(activeServer).getRuntimeTypes();
  return runtimes;
}

Fixed version (ground truth):
public List<ApplicationRuntime> getRuntimes(CloudFoundryServer activeServer) throws CoreException {
  List<ApplicationRuntime> runtimes=new JavaRuntimeTypeHelper(activeServer).getRuntimeTypes();
  return runtimes;
}
Program: 10853
Project: 10853
Buggy source:
@Override public boolean providesApplicationArchive(IModule module){
  return true;
}

Fixed version (ground truth):
public boolean providesApplicationArchive(IModule module){
  return true;
}
Program: 10854
Project: 10854
Buggy source:
@Override public boolean requiresURL(){
  return false;
}

Fixed version (ground truth):
public boolean requiresURL(){
  return false;
}
Program: 10855
Project: 10855
Buggy source:
@Override public boolean isSupportedFramework(String frameworkName){
  return STANDALONE_FRAMEWORK.equals(frameworkName);
}

Fixed version (ground truth):
public boolean isSupportedFramework(String frameworkName){
  return STANDALONE_FRAMEWORK.equals(frameworkName);
}
Program: 10856
Project: 10856
Buggy source:
@Override public List<IWizardPage> getWizardPages(ApplicationWizardDescriptor descriptor,CloudFoundryServer cloudServer,ApplicationModule applicationModule){
  List<IWizardPage> defaultPages=new ArrayList<IWizardPage>();
  CloudFoundryDeploymentWizardPage deploymentPage=new CloudFoundryStandaloneDeploymentWizardPage(cloudServer,applicationModule,descriptor);
  CloudFoundryApplicationWizardPage runtimeFrameworkPage=new CloudFoundryApplicationWizardPage(cloudServer,deploymentPage,applicationModule,descriptor);
  defaultPages.add(runtimeFrameworkPage);
  defaultPages.add(deploymentPage);
  CloudFoundryApplicationServicesWizardPage servicesPage=new CloudFoundryApplicationServicesWizardPage(cloudServer,applicationModule,descriptor);
  defaultPages.add(servicesPage);
  return defaultPages;
}

Fixed version (ground truth):
public List<IWizardPage> getWizardPages(ApplicationWizardDescriptor descriptor,CloudFoundryServer cloudServer,ApplicationModule applicationModule){
  List<IWizardPage> defaultPages=new ArrayList<IWizardPage>();
  StandaloneDeploymentWizardPage deploymentPage=new StandaloneDeploymentWizardPage(cloudServer,applicationModule,descriptor);
  StandaloneApplicationWizardPage runtimeFrameworkPage=new StandaloneApplicationWizardPage(cloudServer,deploymentPage,applicationModule,descriptor);
  defaultPages.add(runtimeFrameworkPage);
  defaultPages.add(deploymentPage);
  CloudFoundryApplicationServicesWizardPage servicesPage=new CloudFoundryApplicationServicesWizardPage(cloudServer,applicationModule,descriptor);
  defaultPages.add(servicesPage);
  return defaultPages;
}
Program: 10857
Project: 10857
Buggy source:
public boolean isValid(ApplicationWizardDescriptor applicationDescriptor){
  return super.isValid(applicationDescriptor) && applicationDescriptor.getStaging() != null && applicationDescriptor.getStaging().getCommand() != null;
}

Fixed version (ground truth):
public boolean isValid(ApplicationWizardDescriptor applicationDescriptor){
  return super.isValid(applicationDescriptor) && applicationDescriptor.getStaging() != null && !ValueValidationUtil.isEmpty(applicationDescriptor.getStaging().getCommand());
}
Program: 10860
Project: 10860
Buggy source:
public ServiceCommand getServiceCommand(){
  if (terminalLocation != null) {
    CommandTerminal terminal=new CommandTerminal();
    terminal.setTerminal(terminalLocationVal);
    serviceCommand.setCommandTerminal(terminal);
  }
  ExternalApplication appInfo=new ExternalApplication();
  appInfo.setDisplayName(displayNameVal);
  appInfo.setExecutableNameAndPath(locationVal);
  serviceCommand.setExternalApplication(appInfo);
  if (optionsVal != null && optionsVal.trim().length() > 0) {
    CommandOptions options=new CommandOptions();
    options.setOptions(optionsVal);
    serviceCommand.setOptions(options);
  }
  return serviceCommand;
}

Fixed version (ground truth):
public ServiceCommand getServiceCommand(){
  if (terminalLocationVal != null) {
    CommandTerminal terminal=new CommandTerminal();
    terminal.setTerminal(terminalLocationVal);
    serviceCommand.setCommandTerminal(terminal);
  }
  ExternalApplication appInfo=new ExternalApplication();
  appInfo.setDisplayName(displayNameVal);
  appInfo.setExecutableNameAndPath(locationVal);
  serviceCommand.setExternalApplication(appInfo);
  if (optionsVal != null && optionsVal.trim().length() > 0) {
    CommandOptions options=new CommandOptions();
    options.setOptions(optionsVal);
    serviceCommand.setOptions(options);
  }
  return serviceCommand;
}
Program: 10862
Project: 10862
Buggy source:
protected void applyTerminalToAllCommands(CommandTerminal terminalToUpdate){
  if (terminalToUpdate != null) {
    List<ServerService> services=serviceCommands.getServices();
    if (services != null) {
      for (      ServerService service : services) {
        List<ServiceCommand> commands=service.getCommands();
        if (commands != null) {
          for (          ServiceCommand cmd : commands) {
            cmd.setCommandTerminal(terminalToUpdate);
          }
        }
      }
    }
    serviceCommands.setDefaultTerminal(terminalToUpdate);
  }
}

Fixed version (ground truth):
protected void applyTerminalToAllCommands(CommandTerminal terminalToUpdate){
  if (terminalToUpdate != null) {
    if (services != null) {
      for (      ServerService service : services) {
        List<ServiceCommand> commands=service.getCommands();
        if (commands != null) {
          for (          ServiceCommand cmd : commands) {
            cmd.setCommandTerminal(terminalToUpdate);
          }
        }
      }
    }
    serviceCommands.setDefaultTerminal(terminalToUpdate);
  }
}
Program: 10863
Project: 10863
Buggy source:
/** 
 * If add is true, it will ignore any currently selected command, and simply add a new command. Otherwise it will attempt to edit the currently selected command, if one exists. If add is false, and there are no selected command, it will add a new command
 * @param add true if adding a new command even if there is a currentlyselected command. False will ONLY edit an existing command, if one is currently selected. Otherwise it will add a new command.
 */
protected void addOrEditCommand(boolean add){
  ServiceCommand serviceCommandToEdit=null;
  if (add) {
    serviceCommandToEdit=new ServiceCommand();
    CommandTerminal defaultTerminal=serviceCommands.getDefaultTerminal();
    serviceCommandToEdit.setCommandTerminal(defaultTerminal);
  }
 else {
    serviceCommandToEdit=getSelectedCommand();
  }
  ServerService service=getSelectedService();
  if (service != null) {
    ServiceCommandWizard wizard=new ServiceCommandWizard(service,serviceCommandToEdit,add);
    Shell shell=getShell();
    if (shell != null) {
      WizardDialog dialog=new WizardDialog(getShell(),wizard);
      if (dialog.open() == Window.OK) {
        ServiceCommand newServiceCommand=wizard.getServiceCommand();
        CommandTerminal updatedTerminal=newServiceCommand != null && wizard.applyTerminalToAllCommands() ? newServiceCommand.getCommandTerminal() : null;
        applyTerminalToAllCommands(updatedTerminal);
        if (newServiceCommand != null) {
          updateCommandViewerInput(serviceCommandToEdit,newServiceCommand,service);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * If add is true, it will ignore any currently selected command, and simply add a new command. Otherwise it will attempt to edit the currently selected command, if one exists. If add is false, and there are no selected command, it will add a new command
 * @param add true if adding a new command even if there is a currentlyselected command. False will ONLY edit an existing command, if one is currently selected. Otherwise it will add a new command.
 */
protected void addOrEditCommand(boolean add){
  ServiceCommand serviceCommandToEdit=null;
  if (add) {
    serviceCommandToEdit=new ServiceCommand();
    CommandTerminal defaultTerminal=serviceCommands.getDefaultTerminal();
    serviceCommandToEdit.setCommandTerminal(defaultTerminal);
  }
 else {
    serviceCommandToEdit=getSelectedCommand();
  }
  ServerService service=getSelectedService();
  if (service != null) {
    ServiceCommandWizard wizard=new ServiceCommandWizard(service,serviceCommandToEdit,add);
    Shell shell=getShell();
    if (shell != null) {
      WizardDialog dialog=new WizardDialog(getShell(),wizard);
      if (dialog.open() == Window.OK) {
        ServiceCommand newServiceCommand=wizard.getServiceCommand();
        CommandTerminal updatedTerminal=newServiceCommand != null && wizard.applyTerminalToAllCommands() ? newServiceCommand.getCommandTerminal() : null;
        if (newServiceCommand != null) {
          updateCommandViewerInput(serviceCommandToEdit,newServiceCommand,service);
          applyTerminalToAllCommands(updatedTerminal);
        }
      }
    }
  }
}
Program: 10865
Project: 10865
Buggy source:
/** 
 * @param toDelete to remove from list of existing commands in the givenwrapper
 * @param toAdd to add to the list of existing commands in the given wrapper
 * @param wrapper containing the old value, and that should contain the newvalue.
 */
protected void updateCommandViewerInput(ServiceCommand toDelete,ServiceCommand toAdd,ServerService service){
  if (service != null && (toDelete != null || toAdd != null)) {
    List<ServiceCommand> commands=service.getCommands();
    List<ServiceCommand> newCommands=new ArrayList<ServiceCommand>();
    if (commands != null) {
      for (      ServiceCommand existingCommand : commands) {
        if (!existingCommand.equals(toDelete)) {
          newCommands.add(existingCommand);
        }
      }
    }
    if (toAdd != null) {
      newCommands.add(toAdd);
    }
    service.setCommands(newCommands);
    setServiceCommandInput(service);
  }
}

Fixed version (ground truth):
/** 
 * @param toDelete to remove from list of existing commands in the givenwrapper
 * @param toAdd to add to the list of existing commands in the given wrapper
 * @param wrapper containing the old value, and that should contain the newvalue.
 */
protected void updateCommandViewerInput(ServiceCommand toDelete,ServiceCommand toAdd,ServerService service){
  if (service != null && (toDelete != null || toAdd != null)) {
    List<ServiceCommand> commands=service.getCommands();
    List<ServiceCommand> newCommands=new ArrayList<ServiceCommand>();
    if (commands != null) {
      for (      ServiceCommand existingCommand : commands) {
        if (!existingCommand.equals(toDelete)) {
          newCommands.add(existingCommand);
        }
      }
    }
    if (toAdd != null) {
      newCommands.add(toAdd);
    }
    service.setCommands(newCommands);
    setServiceCommandInput(service,toAdd);
  }
}
Program: 10866
Project: 10866
Buggy source:
protected void refreshButtons(){
  ServiceCommand selectedCommand=getSelectedCommand();
  ServerService serviceWrapper=getSelectedService();
  if (selectedCommand != null) {
    addCommandButton.setEnabled(false);
    deleteCommandButton.setEnabled(true);
    editCommandButton.setEnabled(true);
  }
 else   if (serviceWrapper != null) {
    addCommandButton.setEnabled(true);
    deleteCommandButton.setEnabled(false);
    editCommandButton.setEnabled(false);
  }
 else {
    addCommandButton.setEnabled(false);
    deleteCommandButton.setEnabled(false);
    editCommandButton.setEnabled(false);
  }
}

Fixed version (ground truth):
protected void refreshButtons(){
  ServiceCommand selectedCommand=getSelectedCommand();
  ServerService serviceWrapper=getSelectedService();
  if (selectedCommand != null) {
    addCommandButton.setEnabled(true);
    deleteCommandButton.setEnabled(true);
    editCommandButton.setEnabled(true);
  }
 else   if (serviceWrapper != null) {
    addCommandButton.setEnabled(true);
    deleteCommandButton.setEnabled(false);
    editCommandButton.setEnabled(false);
  }
 else {
    addCommandButton.setEnabled(false);
    deleteCommandButton.setEnabled(false);
    editCommandButton.setEnabled(false);
  }
}
Program: 10867
Project: 10867
Buggy source:
protected void setServerInput(){
  serviceViewer.setInput(commands);
  setServiceCommandInput(null);
  setStatus(null);
}

Fixed version (ground truth):
protected void setServerInput(){
  serviceViewer.setInput(services);
  if (services != null && !services.isEmpty()) {
    serviceViewer.setSelection(new StructuredSelection(services.get(0)),true);
    setServiceCommandInput(services.get(0),null);
  }
  setStatus(null);
}
Program: 10868
Project: 10868
Buggy source:
protected void handleChange(EventObject eventSource){
  if (eventSource != null) {
    Object source=eventSource.getSource();
    if (source instanceof Control) {
      Control control=(Control)source;
      Object dataObj=control.getData();
      if (dataObj instanceof ControlData) {
        ControlData controlData=(ControlData)dataObj;
switch (controlData) {
case Add:
          addOrEditCommand();
        break;
case Delete:
      deleteCommand();
    break;
case Edit:
  addOrEditCommand();
break;
}
}
}
 else if (source == serviceViewer) {
ServerService serverService=getSelectedService();
setServiceCommandInput(serverService);
}
}
refreshButtons();
}

Fixed version (ground truth):
protected void handleChange(EventObject eventSource){
  if (eventSource != null) {
    Object source=eventSource.getSource();
    if (source instanceof Control) {
      Control control=(Control)source;
      Object dataObj=control.getData();
      if (dataObj instanceof ControlData) {
        ControlData controlData=(ControlData)dataObj;
switch (controlData) {
case Add:
          addOrEditCommand(true);
        break;
case Delete:
      deleteCommand();
    break;
case Edit:
  addOrEditCommand(false);
break;
}
}
}
 else if (source == serviceViewer) {
ServerService serverService=getSelectedService();
setServiceCommandInput(serverService,null);
}
}
refreshButtons();
}
Program: 10869
Project: 10869
Buggy source:
public TunnelServiceCommands getUpdatedCommands(){
  serviceCommands.setServices(commands);
  return serviceCommands;
}

Fixed version (ground truth):
public TunnelServiceCommands getUpdatedCommands(){
  serviceCommands.setServices(services);
  return serviceCommands;
}
Program: 10870
Project: 10870
Buggy source:
protected void setServiceCommandInput(ServerService service){
  if (service != null && service.getCommands() != null) {
    serviceCommandsViewer.setInput(service.getCommands());
  }
 else {
    serviceCommandsViewer.setInput(new ArrayList<ServerService>(0));
  }
}

Fixed version (ground truth):
protected void setServiceCommandInput(ServerService service,ServiceCommand commandToSelect){
  if (service != null && service.getCommands() != null) {
    serviceCommandsViewer.setInput(service.getCommands());
    if (commandToSelect != null) {
      serviceCommandsViewer.setSelection(new StructuredSelection(commandToSelect),true);
    }
  }
 else {
    serviceCommandsViewer.setInput(new ArrayList<ServerService>(0));
  }
}
Program: 10871
Project: 10871
Buggy source:
public ServiceTunnelCommandPart(TunnelServiceCommands serviceCommands){
  this.serviceCommands=serviceCommands;
  commands=(serviceCommands != null && serviceCommands.getServices() != null) ? new ArrayList<ServerService>(serviceCommands.getServices()) : new ArrayList<ServerService>();
}

Fixed version (ground truth):
public ServiceTunnelCommandPart(TunnelServiceCommands serviceCommands){
  this.serviceCommands=serviceCommands;
  services=(serviceCommands != null && serviceCommands.getServices() != null) ? new ArrayList<ServerService>(serviceCommands.getServices()) : new ArrayList<ServerService>();
}
Program: 10872
Project: 10872
Buggy source:
protected void addOrEditCommand(){
  ServiceCommand serviceCommand=getSelectedCommand();
  ServerService service=getSelectedService();
  if (service != null) {
    ServiceCommandWizard wizard=new ServiceCommandWizard(serviceCommand);
    Shell shell=getShell();
    if (shell != null) {
      WizardDialog dialog=new WizardDialog(getShell(),wizard);
      if (dialog.open() == Window.OK) {
        ServiceCommand newServiceCommand=wizard.getServiceCommand();
        if (newServiceCommand != null) {
          updateCommandViewerInput(serviceCommand,newServiceCommand,service);
        }
      }
    }
  }
}

Fixed version (ground truth):
/** 
 * If add is true, it will ignore any currently selected command, and simply add a new command. Otherwise it will attempt to edit the currently selected command, if one exists. If add is false, and there are no selected command, it will add a new command
 * @param add true if adding a new command even if there is a currentlyselected command. False will ONLY edit an existing command, if one is currently selected. Otherwise it will add a new command.
 */
protected void addOrEditCommand(boolean add){
  ServiceCommand serviceCommandToEdit=add ? null : getSelectedCommand();
  ServerService service=getSelectedService();
  if (service != null) {
    ServiceCommandWizard wizard=add ? new ServiceCommandWizard(service) : new ServiceCommandWizard(service,serviceCommandToEdit);
    Shell shell=getShell();
    if (shell != null) {
      WizardDialog dialog=new WizardDialog(getShell(),wizard);
      if (dialog.open() == Window.OK) {
        ServiceCommand newServiceCommand=wizard.getServiceCommand();
        if (newServiceCommand != null) {
          updateCommandViewerInput(serviceCommandToEdit,newServiceCommand,service);
        }
      }
    }
  }
}
Program: 10873
Project: 10873
Buggy source:
public void start(){
  Thread thread=new Thread(this);
  thread.start();
}

Fixed version (ground truth):
public void start(){
  BufferedReader reader=new BufferedReader(new InputStreamReader(processInput));
  try {
    String line=reader.readLine();
    while (line != null) {
      if (outputBuffer != null) {
        outputBuffer.append(line);
        outputBuffer.append(' ');
      }
      line=reader.readLine();
    }
  }
 catch (  IOException e) {
    CloudFoundryPlugin.logError("String_Node_Str" + processName,e);
  }
 finally {
    if (processInput != null) {
      IOUtils.closeQuietly(processInput);
    }
  }
}
Program: 10874
Project: 10874
Buggy source:
public void run(){
  BufferedReader reader=new BufferedReader(new InputStreamReader(processInput));
  try {
    String line=reader.readLine();
    while (line != null) {
      if (outputBuffer != null) {
        outputBuffer.append(line);
        outputBuffer.append(' ');
      }
      line=reader.readLine();
    }
  }
 catch (  IOException e) {
    CloudFoundryPlugin.logError("String_Node_Str" + processName,e);
  }
 finally {
    if (processInput != null) {
      IOUtils.closeQuietly(processInput);
    }
  }
}

Fixed version (ground truth):
/** 
 * Returns when the process has exited without errors. This will wait for the process to exist, therefore will block the current thread in which it is running. If any errors occur, throws CoreException CoreException
 * @throws CoreException if any errors occur while the process is beinglaunched
 */
public void run() throws CoreException {
  Exception error=null;
  Process p=null;
  try {
    List<String> cmdArgs=getCommandArguments();
    if (cmdArgs == null || cmdArgs.isEmpty()) {
      throw new CoreException(getErrorStatus("String_Node_Str"));
    }
 else {
      p=new ProcessBuilder(cmdArgs).start();
      if (p == null) {
        throw new CoreException(getErrorStatus("String_Node_Str"));
      }
 else {
        StringBuffer errorBuffer=new StringBuffer();
        handleProcessIOAsynch(p,null,errorBuffer);
        p.waitFor();
        if (errorBuffer.length() > 0) {
          throw new CoreException(getErrorStatus(errorBuffer.toString()));
        }
 else         if (p.exitValue() != 0) {
          throw new CoreException(getErrorStatus("String_Node_Str" + p.exitValue()));
        }
      }
    }
  }
 catch (  InterruptedException ex) {
    error=ex;
  }
catch (  IOException ioe) {
    error=ioe;
  }
catch (  SecurityException se) {
    error=se;
  }
 finally {
    if (p != null) {
      p.destroy();
    }
  }
  if (error != null) {
    throw error instanceof CoreException ? (CoreException)error : CloudUtil.toCoreException(error);
  }
}
Program: 10875
Project: 10875
Buggy source:
/** 
 * The process IO needs to be handled in order to not block the process.This will cause separate threads to be spawned for each input
 * @param p
 * @return
 * @throws IOException
 */
protected void handleProcessIOAsynch(Process p,StringBuffer inputBuffer,StringBuffer errorBuffer){
  InputStream in=p.getInputStream();
  InputStream error=p.getErrorStream();
  if (in != null) {
    new ProcessStreamHandler(in,inputBuffer,getLaunchName()).start();
  }
  if (error != null) {
    new ProcessStreamHandler(error,errorBuffer,getLaunchName()).start();
  }
}

Fixed version (ground truth):
/** 
 * The process IO needs to be handled in order to not block the process.
 * @param p
 * @return
 * @throws IOException
 */
protected void handleProcessIOAsynch(Process p,StringBuffer inputBuffer,StringBuffer errorBuffer){
  InputStream in=p.getInputStream();
  InputStream error=p.getErrorStream();
  if (in != null) {
    new ProcessStreamHandler(in,inputBuffer,getLaunchName()).start();
  }
  if (error != null) {
    new ProcessStreamHandler(error,errorBuffer,getLaunchName()).start();
  }
}
Program: 10877
Project: 10877
Buggy source:
public static CommandTerminal getDefaultOSTerminal(){
  String os=PlatformUtil.getOS();
  String terminalCommand=null;
  if (Platform.OS_MACOSX.equals(os)) {
    terminalCommand="String_Node_Str";
  }
 else   if (Platform.OS_LINUX.equals(os)) {
  }
 else   if (Platform.OS_WIN32.equals(os)) {
    terminalCommand="String_Node_Str";
  }
  if (terminalCommand != null) {
    CommandTerminal terminal=new CommandTerminal();
    terminal.setTerminalLaunchCommand(terminalCommand);
    return terminal;
  }
  return null;
}

Fixed version (ground truth):
public static CommandTerminal getDefaultOSTerminal(){
  String os=PlatformUtil.getOS();
  String terminalCommand=null;
  if (Platform.OS_MACOSX.equals(os)) {
    terminalCommand="String_Node_Str";
  }
 else   if (Platform.OS_LINUX.equals(os)) {
  }
 else   if (Platform.OS_WIN32.equals(os)) {
    terminalCommand="String_Node_Str";
  }
  if (terminalCommand != null) {
    CommandTerminal terminal=new CommandTerminal();
    terminal.setTerminal(terminalCommand);
    return terminal;
  }
  return null;
}
Program: 10878
Project: 10878
Buggy source:
protected void launchExternalCommand(){
  if (serviceCommand.usesTerminal()) {
    Process p=null;
    try {
      CommandTerminal terminalCommand=serviceCommand.getCommandTerminal();
      String terminalCommandValue=terminalCommand.getTerminalLaunchCommand();
      String[] terminalCommands=terminalCommandValue.split("String_Node_Str");
      List<String> cmdArgs=new ArrayList<String>();
      for (      String terminalCom : terminalCommands) {
        cmdArgs.add(terminalCom);
      }
      if (!addExternalToolCommand(cmdArgs)) {
        CloudFoundryPlugin.logError("String_Node_Str");
        return;
      }
      p=new ProcessBuilder(cmdArgs).start();
      if (p == null) {
        CloudFoundryPlugin.logError("String_Node_Str" + serviceCommand.getExternalApplicationLaunchInfo().getExecutableName() + "String_Node_Str");
      }
 else {
        handleProcessInput(p);
        p.waitFor();
        if (p.exitValue() != 0) {
          CloudFoundryPlugin.logError("String_Node_Str" + p.exitValue());
        }
      }
    }
 catch (    InterruptedException ex) {
      CloudFoundryPlugin.logError("String_Node_Str",ex);
    }
catch (    IOException ioe) {
    }
 finally {
      if (p != null) {
        p.destroy();
      }
    }
  }
}

Fixed version (ground truth):
protected void launchExternalCommand(){
  if (serviceCommand.usesTerminal()) {
    Process p=null;
    try {
      CommandTerminal terminalCommand=serviceCommand.getCommandTerminal();
      String terminalCommandValue=terminalCommand.getTerminal();
      String[] terminalCommands=terminalCommandValue.split("String_Node_Str");
      List<String> cmdArgs=new ArrayList<String>();
      for (      String terminalCom : terminalCommands) {
        cmdArgs.add(terminalCom);
      }
      if (!addExternalToolCommand(cmdArgs)) {
        CloudFoundryPlugin.logError("String_Node_Str");
        return;
      }
      p=new ProcessBuilder(cmdArgs).start();
      if (p == null) {
        CloudFoundryPlugin.logError("String_Node_Str" + serviceCommand.getExternalApplication().getExecutableNameAndPath() + "String_Node_Str");
      }
 else {
        handleProcessInput(p);
        p.waitFor();
        if (p.exitValue() != 0) {
          CloudFoundryPlugin.logError("String_Node_Str" + p.exitValue());
        }
      }
    }
 catch (    InterruptedException ex) {
      CloudFoundryPlugin.logError("String_Node_Str",ex);
    }
catch (    IOException ioe) {
    }
 finally {
      if (p != null) {
        p.destroy();
      }
    }
  }
}
Program: 10879
Project: 10879
Buggy source:
protected String getLaunchName(){
  return serviceCommand.getExternalApplicationLaunchInfo().getDisplayName();
}

Fixed version (ground truth):
protected String getLaunchName(){
  return serviceCommand.getExternalApplication().getDisplayName();
}
Program: 10880
Project: 10880
Buggy source:
protected boolean addExternalToolCommand(List<String> processCommands) throws IOException {
  String appOptions=serviceCommand.getOptions() != null ? serviceCommand.getOptions().getOptions() : null;
  if (Platform.OS_MACOSX.equals(PlatformUtil.getOS())) {
    StringWriter optionsWr=new StringWriter();
    optionsWr.append(serviceCommand.getExternalApplicationLaunchInfo().getExecutableName());
    if (appOptions != null) {
      optionsWr.append(' ');
      optionsWr.append(appOptions);
    }
    File scriptFile=getScriptFile(optionsWr.toString());
    if (scriptFile != null && scriptFile.exists()) {
      processCommands.add(scriptFile.getAbsolutePath());
      return true;
    }
  }
 else {
    processCommands.add(serviceCommand.getExternalApplicationLaunchInfo().getExecutableName());
    if (appOptions != null) {
      processCommands.add(appOptions);
    }
    return true;
  }
  return false;
}

Fixed version (ground truth):
protected boolean addExternalToolCommand(List<String> processCommands) throws IOException {
  String appOptions=serviceCommand.getOptions() != null ? serviceCommand.getOptions().getOptions() : null;
  if (Platform.OS_MACOSX.equals(PlatformUtil.getOS())) {
    StringWriter optionsWr=new StringWriter();
    optionsWr.append(serviceCommand.getExternalApplication().getExecutableNameAndPath());
    if (appOptions != null) {
      optionsWr.append(' ');
      optionsWr.append(appOptions);
    }
    File scriptFile=getScriptFile(optionsWr.toString());
    if (scriptFile != null && scriptFile.exists()) {
      processCommands.add(scriptFile.getAbsolutePath());
      return true;
    }
  }
 else {
    processCommands.add(serviceCommand.getExternalApplication().getExecutableNameAndPath());
    if (appOptions != null) {
      processCommands.add(appOptions);
    }
    return true;
  }
  return false;
}
Program: 10882
Project: 10882
Buggy source:
@Override public void widgetSelected(SelectionEvent event){
  int selectionIndex=predefinedCommands.getSelectionIndex();
  if (selectionIndex != -1) {
    setPredefinedCommand(predefined.get(selectionIndex));
  }
}

Fixed version (ground truth):
@Override public void widgetSelected(SelectionEvent event){
  int selectionIndex=predefinedCommands.getSelectionIndex();
  if (selectionIndex != -1) {
    int predefIndex=selectionIndex - 1;
    ServiceCommand value=predefIndex >= 0 && predefIndex < predefined.size() ? predefined.get(predefIndex) : null;
    setPredefinedCommand(value);
  }
}
Program: 10883
Project: 10883
Buggy source:
protected void setPredefinedCommand(ServiceCommand predefinedCommand){
  if (predefinedCommand != null) {
    displayNameVal=predefinedCommand.getExternalApplication().getDisplayName();
    if (displayNameVal != null) {
      displayName.setText(displayNameVal);
    }
    optionsVal=predefinedCommand.getOptions().getOptions() != null ? predefinedCommand.getOptions().getOptions() : null;
    if (optionsVal != null) {
      options.setText(optionsVal);
    }
    locationVal=predefinedCommand.getExternalApplication().getExecutableNameAndPath();
    if (locationVal != null) {
      locationField.setText(locationVal);
    }
  }
  validate(true);
}

Fixed version (ground truth):
protected void setPredefinedCommand(ServiceCommand predefinedCommand){
  displayNameVal=predefinedCommand != null ? predefinedCommand.getExternalApplication().getDisplayName() : "String_Node_Str";
  if (displayNameVal != null) {
    displayName.setText(displayNameVal);
  }
  optionsVal=predefinedCommand != null ? (predefinedCommand.getOptions().getOptions() != null ? predefinedCommand.getOptions().getOptions() : "String_Node_Str") : "String_Node_Str";
  if (optionsVal != null) {
    options.setText(optionsVal);
  }
  locationVal=predefinedCommand != null ? predefinedCommand.getExternalApplication().getExecutableNameAndPath() : "String_Node_Str";
  if (locationVal != null) {
    locationField.setText(locationVal);
  }
  validate(true);
}
Program: 10885
Project: 10885
Buggy source:
public void handleChange(PartChangeEvent event){
  if (event != null) {
    partStatus=event.getStatus();
    if (partStatus == null || partStatus.isOK()) {
      setErrorMessage(null);
      setPageComplete(true);
    }
 else {
      if (ValueValidationUtil.isEmpty(partStatus.getMessage())) {
        setErrorMessage(null);
        setPageComplete(false);
      }
 else {
        setErrorMessage(partStatus.getMessage());
      }
    }
  }
}

Fixed version (ground truth):
public void handleChange(PartChangeEvent event){
  if (event != null) {
    partStatus=event.getStatus();
    if (partStatus == null || partStatus.isOK()) {
      setErrorMessage(null);
      setPageComplete(true);
    }
 else {
      if (ValueValidationUtil.isEmpty(partStatus.getMessage())) {
        setErrorMessage(null);
      }
 else {
        setErrorMessage(partStatus.getMessage());
      }
      setPageComplete(false);
    }
  }
}
Program: 10886
Project: 10886
Buggy source:
public void createControl(Composite parent){
  displayPart=addNewCommand ? new AddCommandDisplayPart(service,serviceCommand) : new EditCommandDisplayPart(service,serviceCommand);
  displayPart.addPartChangeListener(new IPartChangeListener(){
    public void handleChange(    PartChangeEvent event){
      if (event != null) {
        partStatus=event.getStatus();
        if (partStatus == null || partStatus.isOK()) {
          setErrorMessage(null);
          setPageComplete(true);
        }
 else {
          if (ValueValidationUtil.isEmpty(partStatus.getMessage())) {
            setErrorMessage(null);
            setPageComplete(false);
          }
 else {
            setErrorMessage(partStatus.getMessage());
          }
        }
      }
    }
  }
);
  Control control=displayPart.createPart(parent);
  setControl(control);
}

Fixed version (ground truth):
public void createControl(Composite parent){
  displayPart=addNewCommand ? new AddCommandDisplayPart(service,serviceCommand) : new EditCommandDisplayPart(service,serviceCommand);
  displayPart.addPartChangeListener(new IPartChangeListener(){
    public void handleChange(    PartChangeEvent event){
      if (event != null) {
        partStatus=event.getStatus();
        if (partStatus == null || partStatus.isOK()) {
          setErrorMessage(null);
          setPageComplete(true);
        }
 else {
          if (ValueValidationUtil.isEmpty(partStatus.getMessage())) {
            setErrorMessage(null);
          }
 else {
            setErrorMessage(partStatus.getMessage());
          }
          setPageComplete(false);
        }
      }
    }
  }
);
  Control control=displayPart.createPart(parent);
  setControl(control);
}