Program: 97401
Project: 97401
Buggy source:
private void saveAndCloseManagedViews(Set<String> managedViewIds,boolean save){
  IWorkbench workbench=PlatformUI.getWorkbench();
  if (managedArea.getInstalledBundles().size() > 0 && workbench != null) {
    IWorkbenchPage page=null;
    if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() == null) {
      IWorkbenchWindow[] windows=workbench.getWorkbenchWindows();
      for (      IWorkbenchWindow win : windows) {
        page=win.getActivePage();
        if (page != null) {
          break;
        }
      }
    }
 else {
      page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    }
    if (page == null) {
      return;
    }
    IPerspectiveDescriptor originalPerspective=page.getPerspective();
    XMLMemento memento=XMLMemento.createWriteRoot(TAG_OTE_PRECOMPILED);
    IPerspectiveDescriptor[] pd=page.getOpenPerspectives();
    for (int i=0; i < pd.length; i++) {
      try {
        page.setPerspective(pd[i]);
      }
 catch (      Exception ex) {
      }
      IMemento perspectiveMemento=null;
      try {
        perspectiveMemento=memento.createChild(TAG_PERSPECTIVE);
        perspectiveMemento.putString("String_Node_Str",pd[i].getId());
      }
 catch (      Exception ex) {
      }
      IViewReference[] activeReferences=page.getViewReferences();
      for (      IViewReference viewReference : activeReferences) {
        if (managedViewIds.contains(viewReference.getId())) {
          if (perspectiveMemento != null) {
            try {
              IMemento viewMemento=perspectiveMemento.createChild(TAG_VIEW);
              viewMemento.putString("String_Node_Str",viewReference.getId());
              String secondaryId=viewReference.getSecondaryId();
              if (secondaryId != null) {
                viewMemento.putString("String_Node_Str",secondaryId);
              }
              IWorkbenchPart part=viewReference.getPart(false);
              if (part instanceof IViewPart) {
                IViewPart viewPart=(IViewPart)part;
                viewPart.saveState(viewMemento);
              }
            }
 catch (            Exception ex) {
            }
          }
          try {
            page.hideView(viewReference);
          }
 catch (          Throwable th) {
          }
        }
      }
    }
    if (save) {
      saveMementoToFile(memento);
    }
    page.setPerspective(originalPerspective);
  }
}

Fixed version (ground truth):
private void saveAndCloseManagedViews(Set<String> managedViewIds,boolean save){
  IWorkbench workbench=PlatformUI.getWorkbench();
  if (managedArea.getInstalledBundles().size() > 0 && workbench != null) {
    IWorkbenchPage page=null;
    if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() == null) {
      IWorkbenchWindow[] windows=workbench.getWorkbenchWindows();
      for (      IWorkbenchWindow win : windows) {
        page=win.getActivePage();
        if (page != null) {
          break;
        }
      }
    }
 else {
      page=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    }
    if (page == null) {
      return;
    }
    IPerspectiveDescriptor originalPerspective=page.getPerspective();
    XMLMemento memento=XMLMemento.createWriteRoot(TAG_OTE_PRECOMPILED);
    IPerspectiveDescriptor[] pd=page.getOpenPerspectives();
    for (int i=0; i < pd.length; i++) {
      try {
        page.setPerspective(pd[i]);
      }
 catch (      Exception ex) {
      }
      IMemento perspectiveMemento=null;
      try {
        perspectiveMemento=memento.createChild(TAG_PERSPECTIVE);
        perspectiveMemento.putString("String_Node_Str",pd[i].getId());
      }
 catch (      Exception ex) {
      }
      IViewReference[] activeReferences=page.getViewReferences();
      for (      IViewReference viewReference : activeReferences) {
        int index=viewReference.getId().indexOf("String_Node_Str");
        String id=null;
        if (index > 0) {
          id=viewReference.getId().substring(0,index);
        }
 else {
          id=viewReference.getId();
        }
        if (managedViewIds.contains(id)) {
          if (perspectiveMemento != null) {
            try {
              IMemento viewMemento=perspectiveMemento.createChild(TAG_VIEW);
              viewMemento.putString("String_Node_Str",id);
              String secondaryId=viewReference.getSecondaryId();
              if (secondaryId != null) {
                viewMemento.putString("String_Node_Str",secondaryId);
              }
              IWorkbenchPart part=viewReference.getPart(false);
              if (part instanceof IViewPart) {
                IViewPart viewPart=(IViewPart)part;
                viewPart.saveState(viewMemento);
              }
            }
 catch (            Exception ex) {
            }
          }
          try {
            page.hideView(viewReference);
          }
 catch (          Throwable th) {
          }
        }
      }
    }
    if (save) {
      saveMementoToFile(memento);
    }
    page.setPerspective(originalPerspective);
  }
}