Program: 12093
Project: 12093
Buggy source:
public void run(IAction action){
  InputStream javaFileIStream=null;
  OutputStreamWriter testFileOSWriter=null;
  FileOutputStream fos=null;
  boolean refreshFlag=true;
  String projectName=null;
  String testCaseDirResource=null;
  String testCaseResource=null;
  try {
    IWorkspaceRoot workspaceRoot=ResourcesPlugin.getWorkspace().getRoot();
    String testTargetClassname=null;
    String testCaseFilename=null;
    String testCaseClassname=null;
    String testCaseCreateDirpath=null;
    StructuredSelection structuredSelection=null;
    if (selection instanceof StructuredSelection)     structuredSelection=(StructuredSelection)selection;
    if (structuredSelection != null && structuredSelection.size() == 0) {
      Shell shell=new Shell();
      MessageDialog.openWarning(shell,STR.Dialog.Common.TITLE,STR.Dialog.Common.REQUIRED);
      refreshFlag=false;
    }
 else     if (structuredSelection != null && structuredSelection.size() > 1) {
      Shell shell=new Shell();
      MessageDialog.openWarning(shell,STR.Dialog.Common.TITLE,STR.Dialog.Common.SELECT_ONLY_ONE);
      refreshFlag=false;
    }
 else {
      String pathFromProjectRoot=ResourcePathUtil.getPathStartsFromProjectRoot(structuredSelection);
      String[] dirArrFromProjectRoot=pathFromProjectRoot.split(STR.DIR_SEP);
      String selected=STR.EMPTY;
      int len=dirArrFromProjectRoot.length;
      for (int i=2; i < len - 1; i++)       selected+=dirArrFromProjectRoot[i] + STR.DIR_SEP;
      selected+=dirArrFromProjectRoot[len - 1];
      projectName=dirArrFromProjectRoot[1];
      String testTargetClassFilename=dirArrFromProjectRoot[dirArrFromProjectRoot.length - 1];
      testTargetClassname=testTargetClassFilename.replace(STR.JAVA_EXP,STR.EMPTY);
      testCaseClassname=testTargetClassname + STR.SUFFIX_OF_TESTCASE;
      testCaseFilename=testCaseClassname + STR.JAVA_EXP;
      String projectRootPath=workspaceRoot.getLocation() + STR.DIR_SEP + projectName+ STR.DIR_SEP;
      testCaseResource=selected.replace(STR.SRC_MAIN_JAVA,STR.SRC_TEST_JAVA).replace(STR.JAVA_EXP,STR.SUFFIX_OF_TESTCASE + STR.JAVA_EXP);
      String[] selectedDirArr=selected.split(STR.DIR_SEP);
      testCaseDirResource="String_Node_Str";
      int selectedDirArrLength=selectedDirArr.length;
      for (int i=0; i < selectedDirArrLength - 1; i++)       testCaseDirResource+=selectedDirArr[i] + STR.DIR_SEP;
      testCaseDirResource=testCaseDirResource.replace(STR.SRC_MAIN_JAVA,STR.SRC_TEST_JAVA);
      testCaseCreateDirpath=projectRootPath + testCaseDirResource;
      File testDir=new File(testCaseCreateDirpath);
      String[] dirArr=testCaseCreateDirpath.split(STR.DIR_SEP);
      String tmpDirPath=STR.EMPTY;
      String tmpResourceDirPath=STR.EMPTY;
      for (      String each : dirArr) {
        tmpDirPath+=STR.DIR_SEP + each;
        File tmpDir=new File(tmpDirPath);
        if (tmpDir.getPath().length() <= projectRootPath.length())         continue;
        tmpResourceDirPath+=STR.DIR_SEP + each;
        if (!tmpDir.exists()) {
          if (!tmpDir.mkdir())           System.err.println("String_Node_Str" + tmpDir.getPath());
          if (!ResourceRefreshUtil.refreshLocal(null,projectName + STR.DIR_SEP + tmpResourceDirPath+ "String_Node_Str")) {
            String msg=STR.Dialog.Common.RESOURCE_REFRESH_ERROR;
            MessageDialog.openWarning(new Shell(),STR.Dialog.Common.TITLE,msg);
            System.err.println("String_Node_Str");
          }
        }
      }
      if (!testDir.mkdirs())       System.err.println("String_Node_Str");
      if (!ResourceRefreshUtil.refreshLocal(null,projectName + STR.DIR_SEP + testCaseDirResource)) {
        MessageDialog.openWarning(new Shell(),STR.Dialog.Common.TITLE,STR.Dialog.Common.RESOURCE_REFRESH_ERROR);
        System.err.println("String_Node_Str");
      }
      try {
        File outputFile=new File(testCaseCreateDirpath + STR.DIR_SEP + testCaseFilename);
        String msg=STR.Dialog.Common.ALREADY_EXIST + "String_Node_Str" + testCaseFilename+ "String_Node_Str"+ STR.LINE_FEED+ STR.Dialog.Common.CONFIRM_PROCEED;
        if (!outputFile.exists() || MessageDialog.openConfirm(new Shell(),STR.Dialog.Common.TITLE,msg)) {
          String targetClass="String_Node_Str" + projectName + "String_Node_Str"+ selected;
          IResource targetClassResource=workspaceRoot.findMember(targetClass);
          IFile file=(IFile)targetClassResource;
          List<GeneratingMethodInfo> testMethods=TestCaseGenerateUtil.getTestMethodsFromTarget(file);
          fos=new FileOutputStream(testCaseCreateDirpath + STR.DIR_SEP + testCaseFilename);
          testFileOSWriter=new OutputStreamWriter(fos);
          StringBuffer sb=new StringBuffer();
          String CRLF=STR.CARRIAGE_RETURN + STR.LINE_FEED;
          String testPackageString=STR.EMPTY;
          String[] tmpDirArr=selected.split(STR.DIR_SEP);
          StringBuffer dirSb=new StringBuffer();
          int packageArrLen=tmpDirArr.length - 2;
          for (int i=3; i < packageArrLen; i++) {
            dirSb.append(tmpDirArr[i]);
            dirSb.append("String_Node_Str");
          }
          dirSb.append(tmpDirArr[packageArrLen]);
          testPackageString=dirSb.toString();
          sb.append("String_Node_Str");
          sb.append(testPackageString);
          sb.append("String_Node_Str");
          sb.append(CRLF);
          sb.append(CRLF);
          sb.append("String_Node_Str");
          sb.append(CRLF);
          boolean enabledNotBlankMethods=Activator.getDefault().getPreferenceStore().getBoolean(STR.Preference.TestMethodGen.METHOD_SAMPLE_IMPLEMENTATION);
          if (enabledNotBlankMethods) {
            sb.append(CRLF);
            List<String> importedPackageList=testMethods.get(0).importList;
            for (            String importedPackage : importedPackageList) {
              sb.append("String_Node_Str");
              sb.append(importedPackage);
              sb.append("String_Node_Str");
              sb.append(CRLF);
            }
          }
          sb.append(CRLF);
          sb.append("String_Node_Str");
          sb.append(testCaseClassname);
          sb.append("String_Node_Str");
          sb.append(CRLF);
          sb.append(CRLF);
          for (          GeneratingMethodInfo testMethod : testMethods) {
            sb.append("String_Node_Str");
            sb.append(testMethod.testMethodName);
            sb.append("String_Node_Str");
            sb.append(CRLF);
            sb.append("String_Node_Str");
            sb.append(STR.AUTO_GEN_MSG_TODO);
            sb.append(CRLF);
            if (enabledNotBlankMethods) {
              String notBlankSourceCode=TestCaseGenerateUtil.getNotBlankTestMethodSource(testMethod,testMethods,testTargetClassname);
              sb.append(notBlankSourceCode);
            }
            sb.append("String_Node_Str");
            sb.append(CRLF);
            sb.append(CRLF);
          }
          sb.append("String_Node_Str");
          sb.append(CRLF);
          testFileOSWriter.write(sb.toString());
        }
      }
 catch (      FileNotFoundException fnfe) {
        fnfe.printStackTrace();
      }
 finally {
        FileResourceUtil.close(testFileOSWriter);
        FileResourceUtil.close(fos);
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
 finally {
    FileResourceUtil.close(javaFileIStream);
    FileResourceUtil.close(testFileOSWriter);
  }
  if (refreshFlag && !ResourceRefreshUtil.refreshLocal(null,projectName + STR.DIR_SEP + testCaseDirResource+ "String_Node_Str")) {
    MessageDialog.openWarning(new Shell(),STR.Dialog.Common.TITLE,STR.Dialog.Common.RESOURCE_REFRESH_ERROR);
    System.err.println("String_Node_Str");
  }
 else {
    int retryCount=0;
    IEditorPart editorPart=null;
    ThreadUtil.sleep(1500);
    while (true) {
      try {
        IWorkspace workspace=ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root=workspace.getRoot();
        IProject project=root.getProject(projectName);
        IFile testCaseFile=project.getFile(testCaseResource);
        String editorId=IDE.getEditorDescriptor(testCaseFile.getName()).getId();
        IWorkbenchPage page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        editorPart=IDE.openEditor(page,testCaseFile,editorId);
        if (editorPart == null)         throw new NullPointerException();
        break;
      }
 catch (      Exception e) {
        retryCount++;
        if (retryCount > 3)         break;
        ThreadUtil.sleep(1500);
      }
    }
    editorPart.setFocus();
  }
}

Fixed version (ground truth):
public void run(IAction action){
  InputStream javaFileIStream=null;
  OutputStreamWriter testFileOSWriter=null;
  FileOutputStream fos=null;
  boolean refreshFlag=true;
  String projectName=null;
  String testCaseDirResource=null;
  String testCaseResource=null;
  try {
    IWorkspaceRoot workspaceRoot=ResourcesPlugin.getWorkspace().getRoot();
    String testTargetClassname=null;
    String testCaseFilename=null;
    String testCaseClassname=null;
    String testCaseCreateDirpath=null;
    StructuredSelection structuredSelection=null;
    if (selection instanceof StructuredSelection)     structuredSelection=(StructuredSelection)selection;
    if (structuredSelection != null && structuredSelection.size() == 0) {
      Shell shell=new Shell();
      MessageDialog.openWarning(shell,STR.Dialog.Common.TITLE,STR.Dialog.Common.REQUIRED);
      refreshFlag=false;
    }
 else     if (structuredSelection != null && structuredSelection.size() > 1) {
      Shell shell=new Shell();
      MessageDialog.openWarning(shell,STR.Dialog.Common.TITLE,STR.Dialog.Common.SELECT_ONLY_ONE);
      refreshFlag=false;
    }
 else {
      String pathFromProjectRoot=ResourcePathUtil.getPathStartsFromProjectRoot(structuredSelection);
      String[] dirArrFromProjectRoot=pathFromProjectRoot.split(STR.DIR_SEP);
      String selected=STR.EMPTY;
      int len=dirArrFromProjectRoot.length;
      for (int i=2; i < len - 1; i++)       selected+=dirArrFromProjectRoot[i] + STR.DIR_SEP;
      selected+=dirArrFromProjectRoot[len - 1];
      projectName=dirArrFromProjectRoot[1];
      String testTargetClassFilename=dirArrFromProjectRoot[dirArrFromProjectRoot.length - 1];
      testTargetClassname=testTargetClassFilename.replace(STR.JAVA_EXP,STR.EMPTY);
      testCaseClassname=testTargetClassname + STR.SUFFIX_OF_TESTCASE;
      testCaseFilename=testCaseClassname + STR.JAVA_EXP;
      String projectRootPath=workspaceRoot.getLocation() + STR.DIR_SEP + projectName+ STR.DIR_SEP;
      testCaseResource=selected.replace(STR.SRC_MAIN_JAVA,STR.SRC_TEST_JAVA).replace(STR.JAVA_EXP,STR.SUFFIX_OF_TESTCASE + STR.JAVA_EXP);
      String[] selectedDirArr=selected.split(STR.DIR_SEP);
      testCaseDirResource="String_Node_Str";
      int selectedDirArrLength=selectedDirArr.length;
      for (int i=0; i < selectedDirArrLength - 1; i++)       testCaseDirResource+=selectedDirArr[i] + STR.DIR_SEP;
      testCaseDirResource=testCaseDirResource.replace(STR.SRC_MAIN_JAVA,STR.SRC_TEST_JAVA);
      testCaseCreateDirpath=projectRootPath + testCaseDirResource;
      File testDir=new File(testCaseCreateDirpath);
      String[] dirArr=testCaseCreateDirpath.split(STR.DIR_SEP);
      String tmpDirPath=STR.EMPTY;
      String tmpResourceDirPath=STR.EMPTY;
      for (      String each : dirArr) {
        tmpDirPath+=STR.DIR_SEP + each;
        File tmpDir=new File(tmpDirPath);
        if (tmpDir.getPath().length() <= projectRootPath.length())         continue;
        tmpResourceDirPath+=STR.DIR_SEP + each;
        if (!tmpDir.exists()) {
          if (!tmpDir.mkdir())           System.err.println("String_Node_Str" + tmpDir.getPath());
          if (!ResourceRefreshUtil.refreshLocal(null,projectName + STR.DIR_SEP + tmpResourceDirPath+ "String_Node_Str")) {
            String msg=STR.Dialog.Common.RESOURCE_REFRESH_ERROR;
            MessageDialog.openWarning(new Shell(),STR.Dialog.Common.TITLE,msg);
            System.err.println("String_Node_Str");
          }
        }
      }
      if (!testDir.mkdirs())       System.err.println("String_Node_Str");
      if (!ResourceRefreshUtil.refreshLocal(null,projectName + STR.DIR_SEP + testCaseDirResource)) {
        MessageDialog.openWarning(new Shell(),STR.Dialog.Common.TITLE,STR.Dialog.Common.RESOURCE_REFRESH_ERROR);
        System.err.println("String_Node_Str");
      }
      try {
        File outputFile=new File(testCaseCreateDirpath + STR.DIR_SEP + testCaseFilename);
        String msg=STR.Dialog.Common.ALREADY_EXIST + "String_Node_Str" + testCaseFilename+ "String_Node_Str"+ STR.LINE_FEED+ STR.Dialog.Common.CONFIRM_PROCEED;
        if (!outputFile.exists() || MessageDialog.openConfirm(new Shell(),STR.Dialog.Common.TITLE,msg)) {
          String targetClass="String_Node_Str" + projectName + "String_Node_Str"+ selected;
          IResource targetClassResource=workspaceRoot.findMember(targetClass);
          IFile file=(IFile)targetClassResource;
          List<GeneratingMethodInfo> testMethods=TestCaseGenerateUtil.getTestMethodsFromTarget(file);
          fos=new FileOutputStream(testCaseCreateDirpath + STR.DIR_SEP + testCaseFilename);
          testFileOSWriter=new OutputStreamWriter(fos);
          StringBuffer sb=new StringBuffer();
          String CRLF=STR.CARRIAGE_RETURN + STR.LINE_FEED;
          String testPackageString=STR.EMPTY;
          String[] tmpDirArr=selected.split(STR.DIR_SEP);
          StringBuffer dirSb=new StringBuffer();
          int packageArrLen=tmpDirArr.length - 2;
          for (int i=3; i < packageArrLen; i++) {
            dirSb.append(tmpDirArr[i]);
            dirSb.append("String_Node_Str");
          }
          dirSb.append(tmpDirArr[packageArrLen]);
          testPackageString=dirSb.toString();
          sb.append("String_Node_Str");
          sb.append(testPackageString);
          sb.append("String_Node_Str");
          sb.append(CRLF);
          sb.append(CRLF);
          sb.append("String_Node_Str");
          sb.append(CRLF);
          boolean enabledTestMethodsGen=Activator.getDefault().getPreferenceStore().getBoolean(STR.Preference.TestMethodGen.ENABLE);
          boolean enabledNotBlankMethods=Activator.getDefault().getPreferenceStore().getBoolean(STR.Preference.TestMethodGen.METHOD_SAMPLE_IMPLEMENTATION);
          if (enabledTestMethodsGen && enabledNotBlankMethods) {
            sb.append(CRLF);
            List<String> importedPackageList=testMethods.get(0).importList;
            for (            String importedPackage : importedPackageList) {
              sb.append("String_Node_Str");
              sb.append(importedPackage);
              sb.append("String_Node_Str");
              sb.append(CRLF);
            }
          }
          sb.append(CRLF);
          sb.append("String_Node_Str");
          sb.append(testCaseClassname);
          sb.append("String_Node_Str");
          sb.append(CRLF);
          sb.append(CRLF);
          if (enabledTestMethodsGen) {
            for (            GeneratingMethodInfo testMethod : testMethods) {
              sb.append("String_Node_Str");
              sb.append(testMethod.testMethodName);
              sb.append("String_Node_Str");
              sb.append(CRLF);
              sb.append("String_Node_Str");
              sb.append(STR.AUTO_GEN_MSG_TODO);
              sb.append(CRLF);
              if (enabledNotBlankMethods) {
                String notBlankSourceCode=TestCaseGenerateUtil.getNotBlankTestMethodSource(testMethod,testMethods,testTargetClassname);
                sb.append(notBlankSourceCode);
              }
              sb.append("String_Node_Str");
              sb.append(CRLF);
              sb.append(CRLF);
            }
          }
          sb.append("String_Node_Str");
          sb.append(CRLF);
          testFileOSWriter.write(sb.toString());
        }
      }
 catch (      FileNotFoundException fnfe) {
        fnfe.printStackTrace();
      }
 finally {
        FileResourceUtil.close(testFileOSWriter);
        FileResourceUtil.close(fos);
      }
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
 finally {
    FileResourceUtil.close(javaFileIStream);
    FileResourceUtil.close(testFileOSWriter);
  }
  if (refreshFlag && !ResourceRefreshUtil.refreshLocal(null,projectName + STR.DIR_SEP + testCaseDirResource+ "String_Node_Str")) {
    MessageDialog.openWarning(new Shell(),STR.Dialog.Common.TITLE,STR.Dialog.Common.RESOURCE_REFRESH_ERROR);
    System.err.println("String_Node_Str");
  }
 else {
    int retryCount=0;
    IEditorPart editorPart=null;
    ThreadUtil.sleep(1500);
    while (true) {
      try {
        IWorkspace workspace=ResourcesPlugin.getWorkspace();
        IWorkspaceRoot root=workspace.getRoot();
        IProject project=root.getProject(projectName);
        IFile testCaseFile=project.getFile(testCaseResource);
        String editorId=IDE.getEditorDescriptor(testCaseFile.getName()).getId();
        IWorkbenchPage page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
        editorPart=IDE.openEditor(page,testCaseFile,editorId);
        if (editorPart == null)         throw new NullPointerException();
        break;
      }
 catch (      Exception e) {
        retryCount++;
        if (retryCount > 3)         break;
        ThreadUtil.sleep(1500);
      }
    }
    editorPart.setFocus();
  }
}