Program: 117852
Project: 117852
Buggy source:
public void debug(){
  setHideconsoleLine(false);
  if ((processContext.getProcess()) instanceof org.talend.designer.core.ui.editor.process.Process) {
    ((org.talend.designer.core.ui.editor.process.Process)processContext.getProcess()).checkDifferenceWithRepository();
  }
  final IPreferenceStore preferenceStore=DebugUITools.getPreferenceStore();
  final boolean oldValueConsoleOnOut=preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT);
  final boolean oldValueConsoleOnErr=preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR);
  preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT,false);
  preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR,false);
  checkSaveBeforeRunSelection();
  if (contextComposite.promptConfirmLauch()) {
    setRunnable(false);
    final IContext context=contextComposite.getSelectedContext();
    IRunnableWithProgress worker=new IRunnableWithProgress(){
      @Override public void run(      IProgressMonitor monitor){
        IProcessor processor=ProcessorUtilities.getProcessor(processContext.getProcess(),processContext.getProcess().getProperty(),context);
        monitor.beginTask("String_Node_Str",IProgressMonitor.UNKNOWN);
        try {
          ProcessorUtilities.generateCode(processContext.getProcess(),context,false,false,true,monitor);
          ILaunchConfiguration config=((Processor)processor).getDebugConfiguration(processContext.getStatisticsPort(),processContext.getTracesPort(),null);
          if (!JobErrorsChecker.hasErrors(ProcessComposite.this.getShell())) {
            if (config != null) {
              DebugUITools.launch(config,ILaunchManager.DEBUG_MODE);
            }
 else {
              MessageDialog.openInformation(getShell(),Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
            }
          }
        }
 catch (        ProcessorException e) {
          IStatus status=new Status(IStatus.ERROR,RunProcessPlugin.PLUGIN_ID,IStatus.OK,"String_Node_Str",e);
          RunProcessPlugin.getDefault().getLog().log(status);
          MessageDialog.openError(getShell(),Messages.getString("String_Node_Str"),"String_Node_Str");
        }
 finally {
          monitor.done();
        }
      }
    }
;
    IProgressService progressService=PlatformUI.getWorkbench().getProgressService();
    try {
      progressService.runInUI(PlatformUI.getWorkbench().getProgressService(),worker,ResourcesPlugin.getWorkspace().getRoot());
    }
 catch (    InvocationTargetException e) {
      ExceptionHandler.process(e);
    }
catch (    InterruptedException e) {
      ExceptionHandler.process(e);
    }
  }
  debugMode=true;
  try {
    Thread thread=new Thread(){
      @Override public void run(){
        while (debugMode) {
          final IProcess process=DebugUITools.getCurrentProcess();
          if (process != null && process.isTerminated()) {
            getDisplay().asyncExec(new Runnable(){
              @Override public void run(){
                setRunnable(true);
                killBtn.setEnabled(false);
                preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT,oldValueConsoleOnOut);
                preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR,oldValueConsoleOnErr);
                if (isAddedStreamListener) {
                  process.getStreamsProxy().getOutputStreamMonitor().removeListener(streamListener);
                  isAddedStreamListener=false;
                  if (processContext.isRunning()) {
                    final String endingPattern=Messages.getString("String_Node_Str");
                    MessageFormat mf=new MessageFormat(endingPattern);
                    String byeMsg;
                    try {
                      byeMsg="String_Node_Str" + mf.format(new Object[]{processContext.getProcess().getName(),new Date(),new Integer(process.getExitValue())});
                      processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT,byeMsg));
                    }
 catch (                    DebugException e) {
                      ExceptionHandler.process(e);
                    }
                    processContext.setRunning(false);
                  }
                }
                debugMode=false;
              }
            }
);
          }
 else {
            if (process != null) {
              getDisplay().asyncExec(new Runnable(){
                @Override public void run(){
                  setRunnable(false);
                  killBtn.setEnabled(true);
                  processContext.setRunning(true);
                  processContext.setDebugProcess(process);
                  if (!isAddedStreamListener) {
                    process.getStreamsProxy().getOutputStreamMonitor().addListener(streamListener);
                    ClearPerformanceAction clearPerfAction=new ClearPerformanceAction();
                    clearPerfAction.setProcess(processContext.getProcess());
                    clearPerfAction.run();
                    ClearTraceAction clearTraceAction=new ClearTraceAction();
                    clearTraceAction.setProcess(processContext.getProcess());
                    clearTraceAction.run();
                    isAddedStreamListener=true;
                    final String startingPattern=Messages.getString("String_Node_Str");
                    MessageFormat mf=new MessageFormat(startingPattern);
                    String welcomeMsg=mf.format(new Object[]{processContext.getProcess().getName(),new Date()});
                    processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT,welcomeMsg + "String_Node_Str"));
                  }
                }
              }
);
            }
 else {
              getDisplay().asyncExec(new Runnable(){
                @Override public void run(){
                  setRunnable(true);
                  killBtn.setEnabled(false);
                }
              }
);
            }
          }
          try {
            Thread.sleep(2000);
          }
 catch (          InterruptedException e) {
            ExceptionHandler.process(e);
          }
        }
      }
    }
;
    thread.start();
  }
 catch (  Exception e) {
    ExceptionHandler.process(e);
    processContext.addErrorMessage(e);
    kill();
  }
}

Fixed version (ground truth):
public void debug(){
  setHideconsoleLine(false);
  if ((processContext.getProcess()) instanceof org.talend.designer.core.ui.editor.process.Process) {
    ((org.talend.designer.core.ui.editor.process.Process)processContext.getProcess()).checkDifferenceWithRepository();
  }
  final IPreferenceStore preferenceStore=DebugUITools.getPreferenceStore();
  final boolean oldValueConsoleOnOut=preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT);
  final boolean oldValueConsoleOnErr=preferenceStore.getBoolean(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR);
  preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT,false);
  preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR,false);
  checkSaveBeforeRunSelection();
  if (contextComposite.promptConfirmLauch()) {
    setRunnable(false);
    final IContext context=contextComposite.getSelectedContext();
    IRunnableWithProgress worker=new IRunnableWithProgress(){
      @Override public void run(      IProgressMonitor monitor){
        IProcessor processor=ProcessorUtilities.getProcessor(processContext.getProcess(),processContext.getProcess().getProperty(),context);
        monitor.beginTask("String_Node_Str",IProgressMonitor.UNKNOWN);
        try {
          ProcessorUtilities.generateCode(processContext.getProcess(),context,false,false,true,monitor);
          ILaunchConfiguration config=((Processor)processor).getDebugConfiguration(processContext.getStatisticsPort(),processContext.getTracesPort(),null);
          if (!JobErrorsChecker.hasErrors(ProcessComposite.this.getShell())) {
            if (config != null) {
              IPreferenceStore debugUiStore=DebugUITools.getPreferenceStore();
              debugUiStore.setValue(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH,Boolean.FALSE);
              DebugUITools.launch(config,ILaunchManager.DEBUG_MODE);
            }
 else {
              MessageDialog.openInformation(getShell(),Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str"));
            }
          }
        }
 catch (        ProcessorException e) {
          IStatus status=new Status(IStatus.ERROR,RunProcessPlugin.PLUGIN_ID,IStatus.OK,"String_Node_Str",e);
          RunProcessPlugin.getDefault().getLog().log(status);
          MessageDialog.openError(getShell(),Messages.getString("String_Node_Str"),"String_Node_Str");
        }
 finally {
          monitor.done();
        }
      }
    }
;
    IProgressService progressService=PlatformUI.getWorkbench().getProgressService();
    try {
      progressService.runInUI(PlatformUI.getWorkbench().getProgressService(),worker,ResourcesPlugin.getWorkspace().getRoot());
    }
 catch (    InvocationTargetException e) {
      ExceptionHandler.process(e);
    }
catch (    InterruptedException e) {
      ExceptionHandler.process(e);
    }
  }
  debugMode=true;
  try {
    Thread thread=new Thread(){
      @Override public void run(){
        while (debugMode) {
          final IProcess process=DebugUITools.getCurrentProcess();
          if (process != null && process.isTerminated()) {
            getDisplay().asyncExec(new Runnable(){
              @Override public void run(){
                setRunnable(true);
                killBtn.setEnabled(false);
                preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_OUT,oldValueConsoleOnOut);
                preferenceStore.setValue(IDebugPreferenceConstants.CONSOLE_OPEN_ON_ERR,oldValueConsoleOnErr);
                if (isAddedStreamListener) {
                  process.getStreamsProxy().getOutputStreamMonitor().removeListener(streamListener);
                  isAddedStreamListener=false;
                  if (processContext.isRunning()) {
                    final String endingPattern=Messages.getString("String_Node_Str");
                    MessageFormat mf=new MessageFormat(endingPattern);
                    String byeMsg;
                    try {
                      byeMsg="String_Node_Str" + mf.format(new Object[]{processContext.getProcess().getName(),new Date(),new Integer(process.getExitValue())});
                      processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT,byeMsg));
                    }
 catch (                    DebugException e) {
                      ExceptionHandler.process(e);
                    }
                    processContext.setRunning(false);
                  }
                }
                debugMode=false;
              }
            }
);
          }
 else {
            if (process != null) {
              getDisplay().asyncExec(new Runnable(){
                @Override public void run(){
                  setRunnable(false);
                  killBtn.setEnabled(true);
                  processContext.setRunning(true);
                  processContext.setDebugProcess(process);
                  if (!isAddedStreamListener) {
                    process.getStreamsProxy().getOutputStreamMonitor().addListener(streamListener);
                    ClearPerformanceAction clearPerfAction=new ClearPerformanceAction();
                    clearPerfAction.setProcess(processContext.getProcess());
                    clearPerfAction.run();
                    ClearTraceAction clearTraceAction=new ClearTraceAction();
                    clearTraceAction.setProcess(processContext.getProcess());
                    clearTraceAction.run();
                    isAddedStreamListener=true;
                    final String startingPattern=Messages.getString("String_Node_Str");
                    MessageFormat mf=new MessageFormat(startingPattern);
                    String welcomeMsg=mf.format(new Object[]{processContext.getProcess().getName(),new Date()});
                    processContext.addDebugResultToConsole(new ProcessMessage(MsgType.CORE_OUT,welcomeMsg + "String_Node_Str"));
                  }
                }
              }
);
            }
 else {
              getDisplay().asyncExec(new Runnable(){
                @Override public void run(){
                  setRunnable(true);
                  killBtn.setEnabled(false);
                }
              }
);
            }
          }
          try {
            Thread.sleep(2000);
          }
 catch (          InterruptedException e) {
            ExceptionHandler.process(e);
          }
        }
      }
    }
;
    thread.start();
  }
 catch (  Exception e) {
    ExceptionHandler.process(e);
    processContext.addErrorMessage(e);
    kill();
  }
}