Program: 127786
Project: 127786
Buggy source:
public static void resetPerspective(){
  boolean reset=false;
  IPath path=WorkbenchPlugin.getDefault().getDataLocation();
  if (path == null) {
    return;
  }
  final File stateFile=path.append("String_Node_Str").toFile();
  final boolean stateExist=stateFile.exists();
  if (stateFile == null || !stateExist) {
    reset=true;
  }
  FileInputStream input=null;
  final IPerspectiveRegistry perspectiveRegistry=WorkbenchPlugin.getDefault().getPerspectiveRegistry();
  if (stateFile != null && stateExist) {
    try {
      input=new FileInputStream(stateFile);
      BufferedReader reader=new BufferedReader(new InputStreamReader(input,"String_Node_Str"));
      IMemento memento=XMLMemento.createReadRoot(reader);
      IMemento[] windowArray=memento.getChildren(IWorkbenchConstants.TAG_WINDOW);
      for (int cw=0; windowArray != null && cw < windowArray.length; cw++) {
        final IMemento windowMem=windowArray[cw];
        IMemento[] pageArray=windowMem.getChildren(IWorkbenchConstants.TAG_PAGE);
        for (int i=0; pageArray != null && i < pageArray.length; i++) {
          final IMemento pageMem=pageArray[i];
          IMemento pespectiveMem=pageMem.getChild(IWorkbenchConstants.TAG_PERSPECTIVES);
          if (pespectiveMem != null) {
            String activePerspectiveID=pespectiveMem.getString(IWorkbenchConstants.TAG_ACTIVE_PERSPECTIVE);
            IPerspectiveDescriptor perspectiveDesc=perspectiveRegistry.findPerspectiveWithId(activePerspectiveID);
            if (perspectiveDesc != null && perspectiveDesc instanceof PerspectiveDescriptor) {
              String originalId=((PerspectiveDescriptor)perspectiveDesc).getOriginalId();
              perspectiveDesc=perspectiveRegistry.findPerspectiveWithId(originalId);
            }
            if (perspectiveDesc == null) {
              stateFile.delete();
              reset=true;
              break;
            }
          }
        }
      }
    }
 catch (    FileNotFoundException e) {
    }
catch (    UnsupportedEncodingException e) {
    }
catch (    WorkbenchException e) {
    }
 finally {
      if (input != null) {
        try {
          input.close();
        }
 catch (        IOException e) {
        }
      }
    }
  }
  for (  IPerspectiveDescriptor pd : perspectiveRegistry.getPerspectives()) {
    if (pd instanceof PerspectiveDescriptor) {
      PerspectiveDescriptor descriptor=(PerspectiveDescriptor)pd;
      if (descriptor.getOriginalId() != null) {
        IPerspectiveDescriptor findPerspective=perspectiveRegistry.findPerspectiveWithId(descriptor.getOriginalId());
        if (findPerspective == null) {
          perspectiveRegistry.deletePerspective(pd);
        }
      }
    }
  }
  if (reset) {
    IPreferenceStore store=WorkbenchPlugin.getDefault().getPreferenceStore();
    String customPerspectives=store.getString(IPreferenceConstants.PERSPECTIVES);
    String[] perspectivesList=StringConverter.asArray(customPerspectives);
    for (int i=0; i < perspectivesList.length; i++) {
      store.setValue(perspectivesList[i] + "String_Node_Str","String_Node_Str");
    }
    store.setValue(IPreferenceConstants.PERSPECTIVES,"String_Node_Str");
    if (store.needsSaving() && store instanceof IPersistentPreferenceStore) {
      try {
        ((IPersistentPreferenceStore)store).save();
      }
 catch (      IOException e) {
      }
    }
    File folder=path.toFile();
    if (folder.isDirectory()) {
      File[] fileList=folder.listFiles();
      for (int nX=0; nX < fileList.length; nX++) {
        File file=fileList[nX];
        if (file.getName().endsWith("String_Node_Str")) {
          file.delete();
        }
      }
    }
  }
}

Fixed version (ground truth):
public static void resetPerspective(){
  boolean reset=false;
  IPath path=WorkbenchPlugin.getDefault().getDataLocation();
  if (path == null) {
    return;
  }
  final File stateFile=path.append("String_Node_Str").toFile();
  final boolean stateExist=stateFile.exists();
  if (stateFile == null || !stateExist) {
    reset=true;
  }
  FileInputStream input=null;
  final IPerspectiveRegistry perspectiveRegistry=WorkbenchPlugin.getDefault().getPerspectiveRegistry();
  if (stateFile != null && stateExist) {
    try {
      input=new FileInputStream(stateFile);
      BufferedReader reader=new BufferedReader(new InputStreamReader(input,"String_Node_Str"));
      IMemento memento=XMLMemento.createReadRoot(reader);
      IMemento[] windowArray=memento.getChildren(IWorkbenchConstants.TAG_WINDOW);
      for (int cw=0; windowArray != null && cw < windowArray.length; cw++) {
        final IMemento windowMem=windowArray[cw];
        IMemento[] pageArray=windowMem.getChildren(IWorkbenchConstants.TAG_PAGE);
        for (int i=0; pageArray != null && i < pageArray.length; i++) {
          final IMemento pageMem=pageArray[i];
          IMemento pespectiveMem=pageMem.getChild(IWorkbenchConstants.TAG_PERSPECTIVES);
          if (pespectiveMem != null) {
            String activePerspectiveID=pespectiveMem.getString(IWorkbenchConstants.TAG_ACTIVE_PERSPECTIVE);
            IPerspectiveDescriptor perspectiveDesc=perspectiveRegistry.findPerspectiveWithId(activePerspectiveID);
            if (perspectiveDesc != null && perspectiveDesc instanceof PerspectiveDescriptor) {
              String originalId=((PerspectiveDescriptor)perspectiveDesc).getOriginalId();
              perspectiveDesc=perspectiveRegistry.findPerspectiveWithId(originalId);
            }
            if (perspectiveDesc == null) {
              stateFile.delete();
              reset=true;
              break;
            }
          }
        }
      }
    }
 catch (    FileNotFoundException e) {
    }
catch (    UnsupportedEncodingException e) {
    }
catch (    WorkbenchException e) {
    }
 finally {
      if (input != null) {
        try {
          input.close();
        }
 catch (        IOException e) {
        }
      }
    }
  }
  for (  IPerspectiveDescriptor pd : perspectiveRegistry.getPerspectives()) {
    if (pd instanceof PerspectiveDescriptor) {
      PerspectiveDescriptor descriptor=(PerspectiveDescriptor)pd;
      if (descriptor.getOriginalId() != null) {
        IPerspectiveDescriptor findPerspective=perspectiveRegistry.findPerspectiveWithId(descriptor.getOriginalId());
        if (findPerspective == null) {
          perspectiveRegistry.deletePerspective(pd);
        }
      }
    }
  }
  if (reset) {
    IPreferenceStore store=WorkbenchPlugin.getDefault().getPreferenceStore();
    String customPerspectives=store.getString(IPreferenceConstants.PERSPECTIVES);
    String[] perspectivesList=StringConverter.asArray(customPerspectives);
    for (    String element : perspectivesList) {
      store.setValue(element + "String_Node_Str","String_Node_Str");
    }
    store.setValue(IPreferenceConstants.PERSPECTIVES,"String_Node_Str");
    if (store.needsSaving() && store instanceof IPersistentPreferenceStore) {
      try {
        ((IPersistentPreferenceStore)store).save();
      }
 catch (      IOException e) {
      }
    }
    File folder=path.toFile();
    if (folder.isDirectory()) {
      File[] fileList=folder.listFiles();
      for (      File file : fileList) {
        if (file.getName().endsWith("String_Node_Str")) {
          file.delete();
        }
      }
    }
  }
}