Program: 11952
Project: 11952
Buggy source:
public void run(IAction action){
  store=getIPreferenceStore();
  Configuration config=getConfiguration(store,selection);
  PropertiesLoader props=getPropertiesLoader(config.language);
  StructuredSelection structuredSelection=null;
  InputStream inputStream=null;
  FileOutputStream outputStream=null;
  OutputStreamWriter writer=null;
  String projectName=null;
  String testCaseFileName=null;
  String testCaseCreateFilePath=null;
  String resourcePathForTargetClassFile=null;
  String resourcePathForTestClassFile=null;
  try {
    if (selection instanceof StructuredSelection) {
      structuredSelection=(StructuredSelection)selection;
    }
    if (isNotSelected(structuredSelection)) {
      openWarningForRequired(props);
      return;
    }
 else     if (isSelectedSeveral(structuredSelection)) {
      openWarningForSelectOneOnly(props);
      return;
    }
    projectName=getProjectName(structuredSelection);
    resourcePathForTargetClassFile=getResourcePathForTargetClassFile(structuredSelection);
    String projectRootAbsolutePath=getWorkspaceRootAbsolutePath(getIWorkspaceRoot()) + StringValue.DirectorySeparator.General + projectName+ StringValue.DirectorySeparator.General;
    resourcePathForTestClassFile=resourcePathForTargetClassFile.replaceFirst(config.directoryPathOfProductSourceCode,config.directoryPathOfTestSourceCode).replace(StringValue.FileExtension.JavaFile,StringValue.JUnit.TestClassNameSuffix + StringValue.FileExtension.JavaFile);
    testCaseCreateFilePath=projectRootAbsolutePath + getResourcePathForTargetClassFile(structuredSelection).replace(config.directoryPathOfProductSourceCode,config.directoryPathOfTestSourceCode).replace(StringValue.FileExtension.JavaFile,StringValue.JUnit.TestClassNameSuffix + StringValue.FileExtension.JavaFile);
    testCaseFileName=(getClassNameFromResourcePathForTargetClassFile(resourcePathForTargetClassFile) + StringValue.FileExtension.JavaFile).replace(StringValue.FileExtension.JavaFile,StringValue.JUnit.TestClassNameSuffix + StringValue.FileExtension.JavaFile);
    String testCaseCreateDirPath=testCaseCreateFilePath.replaceFirst("String_Node_Str","String_Node_Str");
    File testDir=new File(testCaseCreateDirPath);
    String[] dirArr=testCaseCreateDirPath.split(StringValue.DirectorySeparator.General);
    String tmpDirPath=StringValue.Empty;
    String tmpResourceDirPath=StringValue.Empty;
    for (    String each : dirArr) {
      tmpDirPath+=StringValue.DirectorySeparator.General + each;
      File tmpDir=new File(tmpDirPath);
      if (tmpDir.getPath().length() <= projectRootAbsolutePath.length()) {
        continue;
      }
      tmpResourceDirPath+=StringValue.DirectorySeparator.General + each;
      if (!tmpDir.exists()) {
        if (!tmpDir.mkdir()) {
          System.err.println("String_Node_Str" + tmpDir.getPath());
        }
        String parentPathOfCreatedDir=projectName + StringValue.DirectorySeparator.General + tmpResourceDirPath+ "String_Node_Str";
        if (!ResourceRefreshUtil.refreshLocal(null,parentPathOfCreatedDir)) {
          System.err.println("String_Node_Str" + parentPathOfCreatedDir);
        }
      }
    }
    if (!testDir.mkdirs()) {
      System.err.println("String_Node_Str");
    }
    String pathOfTestCaseDir=projectName + StringValue.DirectorySeparator.General + resourcePathForTestClassFile+ "String_Node_Str";
    if (!ResourceRefreshUtil.refreshLocal(null,pathOfTestCaseDir)) {
      openWarningForResourceRefreshError(props);
      return;
    }
    try {
      File outputIOFile=new File(testCaseCreateDirPath + StringValue.DirectorySeparator.General + testCaseFileName);
      String msg=props.get(Dialog.Common.alreadyExist) + "String_Node_Str" + testCaseFileName+ "String_Node_Str"+ StringValue.LineFeed+ props.get(Dialog.Common.confirmToProceed);
      if (outputIOFile.exists() && !openConfirm(props,msg)) {
        return;
      }
      IResource targetClassResource=getIWorkspaceRoot().findMember("String_Node_Str" + projectName + "String_Node_Str"+ resourcePathForTargetClassFile);
      IFile targetClassFile=(IFile)targetClassResource;
      String absolutePath=projectRootAbsolutePath + StringValue.DirectorySeparator.General;
      config.directoryPathOfProductSourceCode=absolutePath + config.directoryPathOfProductSourceCode;
      config.directoryPathOfTestSourceCode=absolutePath + config.directoryPathOfTestSourceCode;
      String encoding=UniversalDetectorUtil.getDetectedEncoding(EclipseIFileUtil.getInputStreamFrom(targetClassFile));
      InputStream targetInputStream=EclipseIFileUtil.getInputStreamFrom(targetClassFile);
      String sourceCodeString=IOUtil.readAsString(targetInputStream,encoding);
      LineBreakProvider lineBreakProvider=new LineBreakProvider(config,null);
      TestCaseGenerator generator=TestCaseGeneratorFactory.create(config,lineBreakProvider);
      generator.initialize(new ClassMetaExtractor(config).extract(sourceCodeString));
      outputStream=new FileOutputStream(testCaseCreateDirPath + StringValue.DirectorySeparator.General + testCaseFileName);
      String charset=null;
      if (config.outputFileEncoding != null) {
        charset=config.outputFileEncoding;
      }
 else {
        charset=getDetectedCharsetFrom(targetClassFile,config.outputFileEncoding);
      }
      writer=new OutputStreamWriter(outputStream,charset);
      writer.write(generator.getNewTestCaseSourceCode());
    }
 catch (    InvalidPreferenceException ipe) {
      ipe.printStackTrace();
      openWarning(props,props.get(Dialog.Common.invalidPreference));
      return;
    }
catch (    FileNotFoundException fnfe) {
      fnfe.printStackTrace();
    }
 finally {
      IOUtils.closeQuietly(writer);
      IOUtils.closeQuietly(outputStream);
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
 finally {
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(outputStream);
    IOUtils.closeQuietly(writer);
  }
  if (!ResourceRefreshUtil.refreshLocal(null,projectName + StringValue.DirectorySeparator.General + resourcePathForTestClassFile+ "String_Node_Str")) {
    openWarningForResourceRefreshError(props);
    System.err.println("String_Node_Str");
    return;
  }
  int retryCount=0;
  IEditorPart editorPart=null;
  ThreadUtil.sleep(1500);
  while (true) {
    try {
      IProject project=getIProject(projectName);
      IFile testCaseFile=getIFile(project,resourcePathForTestClassFile);
      IWorkbenchPage page=getIWorkbenchPage();
      editorPart=getIEditorPart(page,testCaseFile);
      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){
  store=getIPreferenceStore();
  Configuration config=getConfiguration(store,selection);
  PropertiesLoader props=getPropertiesLoader(config.language);
  StructuredSelection structuredSelection=null;
  InputStream inputStream=null;
  FileOutputStream outputStream=null;
  OutputStreamWriter writer=null;
  String projectName=null;
  String testCaseFileName=null;
  String testCaseCreateFilePath=null;
  String resourcePathForTargetClassFile=null;
  String resourcePathForTestClassFile=null;
  try {
    if (selection instanceof StructuredSelection) {
      structuredSelection=(StructuredSelection)selection;
    }
    if (isNotSelected(structuredSelection)) {
      openWarningForRequired(props);
      return;
    }
 else     if (isSelectedSeveral(structuredSelection)) {
      openWarningForSelectOneOnly(props);
      return;
    }
    projectName=getProjectName(structuredSelection);
    resourcePathForTargetClassFile=getResourcePathForTargetClassFile(structuredSelection);
    String projectRootAbsolutePath=getIWorkspaceRoot().findMember(projectName).getLocationURI().getPath() + StringValue.DirectorySeparator.General;
    resourcePathForTestClassFile=resourcePathForTargetClassFile.replaceFirst(config.directoryPathOfProductSourceCode,config.directoryPathOfTestSourceCode).replace(StringValue.FileExtension.JavaFile,StringValue.JUnit.TestClassNameSuffix + StringValue.FileExtension.JavaFile);
    testCaseCreateFilePath=projectRootAbsolutePath + getResourcePathForTargetClassFile(structuredSelection).replace(config.directoryPathOfProductSourceCode,config.directoryPathOfTestSourceCode).replace(StringValue.FileExtension.JavaFile,StringValue.JUnit.TestClassNameSuffix + StringValue.FileExtension.JavaFile);
    testCaseFileName=(getClassNameFromResourcePathForTargetClassFile(resourcePathForTargetClassFile) + StringValue.FileExtension.JavaFile).replace(StringValue.FileExtension.JavaFile,StringValue.JUnit.TestClassNameSuffix + StringValue.FileExtension.JavaFile);
    String testCaseCreateDirPath=testCaseCreateFilePath.replaceFirst("String_Node_Str","String_Node_Str");
    File testDir=new File(testCaseCreateDirPath);
    String[] dirArr=testCaseCreateDirPath.split(StringValue.DirectorySeparator.General);
    String tmpDirPath=StringValue.Empty;
    String tmpResourceDirPath=StringValue.Empty;
    for (    String each : dirArr) {
      tmpDirPath+=StringValue.DirectorySeparator.General + each;
      File tmpDir=new File(tmpDirPath);
      if (tmpDir.getPath().length() <= projectRootAbsolutePath.length()) {
        continue;
      }
      tmpResourceDirPath+=StringValue.DirectorySeparator.General + each;
      if (!tmpDir.exists()) {
        if (!tmpDir.mkdir()) {
          System.err.println("String_Node_Str" + tmpDir.getPath());
        }
        String parentPathOfCreatedDir=projectName + StringValue.DirectorySeparator.General + tmpResourceDirPath+ "String_Node_Str";
        if (!ResourceRefreshUtil.refreshLocal(null,parentPathOfCreatedDir)) {
          System.err.println("String_Node_Str" + parentPathOfCreatedDir);
        }
      }
    }
    if (!testDir.mkdirs()) {
      System.err.println("String_Node_Str");
    }
    String pathOfTestCaseDir=projectName + StringValue.DirectorySeparator.General + resourcePathForTestClassFile+ "String_Node_Str";
    if (!ResourceRefreshUtil.refreshLocal(null,pathOfTestCaseDir)) {
      openWarningForResourceRefreshError(props);
      return;
    }
    try {
      File outputIOFile=new File(testCaseCreateDirPath + StringValue.DirectorySeparator.General + testCaseFileName);
      String msg=props.get(Dialog.Common.alreadyExist) + "String_Node_Str" + testCaseFileName+ "String_Node_Str"+ StringValue.LineFeed+ props.get(Dialog.Common.confirmToProceed);
      if (outputIOFile.exists() && !openConfirm(props,msg)) {
        return;
      }
      IResource targetClassResource=getIWorkspaceRoot().findMember("String_Node_Str" + projectName + "String_Node_Str"+ resourcePathForTargetClassFile);
      IFile targetClassFile=(IFile)targetClassResource;
      String absolutePath=projectRootAbsolutePath + StringValue.DirectorySeparator.General;
      config.directoryPathOfProductSourceCode=absolutePath + config.directoryPathOfProductSourceCode;
      config.directoryPathOfTestSourceCode=absolutePath + config.directoryPathOfTestSourceCode;
      String encoding=UniversalDetectorUtil.getDetectedEncoding(EclipseIFileUtil.getInputStreamFrom(targetClassFile));
      InputStream targetInputStream=EclipseIFileUtil.getInputStreamFrom(targetClassFile);
      String sourceCodeString=IOUtil.readAsString(targetInputStream,encoding);
      LineBreakProvider lineBreakProvider=new LineBreakProvider(config,null);
      TestCaseGenerator generator=TestCaseGeneratorFactory.create(config,lineBreakProvider);
      generator.initialize(new ClassMetaExtractor(config).extract(sourceCodeString));
      outputStream=new FileOutputStream(testCaseCreateDirPath + StringValue.DirectorySeparator.General + testCaseFileName);
      String charset=null;
      if (config.outputFileEncoding != null) {
        charset=config.outputFileEncoding;
      }
 else {
        charset=getDetectedCharsetFrom(targetClassFile,config.outputFileEncoding);
      }
      writer=new OutputStreamWriter(outputStream,charset);
      writer.write(generator.getNewTestCaseSourceCode());
    }
 catch (    InvalidPreferenceException ipe) {
      ipe.printStackTrace();
      openWarning(props,props.get(Dialog.Common.invalidPreference));
      return;
    }
catch (    FileNotFoundException fnfe) {
      fnfe.printStackTrace();
    }
 finally {
      IOUtils.closeQuietly(writer);
      IOUtils.closeQuietly(outputStream);
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
 finally {
    IOUtils.closeQuietly(inputStream);
    IOUtils.closeQuietly(outputStream);
    IOUtils.closeQuietly(writer);
  }
  if (!ResourceRefreshUtil.refreshLocal(null,projectName + StringValue.DirectorySeparator.General + resourcePathForTestClassFile+ "String_Node_Str")) {
    openWarningForResourceRefreshError(props);
    System.err.println("String_Node_Str");
    return;
  }
  int retryCount=0;
  IEditorPart editorPart=null;
  ThreadUtil.sleep(1500);
  while (true) {
    try {
      IProject project=getIProject(projectName);
      IFile testCaseFile=getIFile(project,resourcePathForTestClassFile);
      IWorkbenchPage page=getIWorkbenchPage();
      editorPart=getIEditorPart(page,testCaseFile);
      if (editorPart == null) {
        throw new NullPointerException();
      }
      break;
    }
 catch (    Exception e) {
      retryCount++;
      if (retryCount > 3) {
        break;
      }
      ThreadUtil.sleep(1500);
    }
  }
  editorPart.setFocus();
}