Program: 125985
Project: 125985
Buggy source:
/** 
 * DOC ggu Comment method "restorePerspective". try to find and create the perspective. if the existed custom perspective, will use the custom one. won't create original one.
 */
protected void restorePerspective(MPerspectiveStack mPerspStack,String id){
  if (id != null && mPerspStack != null) {
    MPerspective mPersp=null;
    IPerspectiveRegistry perspectiveRegistry=workbench.getPerspectiveRegistry();
    for (    MPerspective mp : mPerspStack.getChildren()) {
      if (mp.getElementId().equals(id)) {
        mPersp=mp;
        break;
      }
 else {
        IPerspectiveDescriptor persp=perspectiveRegistry.findPerspectiveWithId(mp.getElementId());
        if (persp != null && persp instanceof PerspectiveDescriptor) {
          PerspectiveDescriptor pd=(PerspectiveDescriptor)persp;
          if (!pd.getOriginalId().equals(pd.getId()) && pd.getOriginalId().equals(id)) {
            mPersp=mp;
            break;
          }
        }
      }
    }
    IPerspectiveDescriptor perspDesc=perspectiveRegistry.findPerspectiveWithId(id);
    if (perspDesc == null) {
      if (mPersp != null) {
        mPerspStack.getChildren().remove(mPersp);
      }
      return;
    }
    if (mPersp == null) {
      String perspId=perspDesc.getId();
      WorkbenchPage workbenchPage=(WorkbenchPage)workbench.getActiveWorkbenchWindow().getActivePage();
      mPersp=(MPerspective)fModelService.cloneSnippet(fApp,perspId,fWindow);
      if (mPersp == null) {
        mPersp=fModelService.createModelElement(MPerspective.class);
        mPersp.setElementId(perspDesc.getId());
        IPerspectiveFactory factory=((PerspectiveDescriptor)perspDesc).createFactory();
        ModeledPageLayout modelLayout=new ModeledPageLayout(fWindow,fModelService,fPartService,mPersp,perspDesc,workbenchPage,true);
        factory.createInitialLayout(modelLayout);
        PerspectiveTagger.tagPerspective(mPersp,fModelService);
        PerspectiveExtensionReader reader=new PerspectiveExtensionReader();
        reader.extendLayout(getExtensionTracker(workbenchPage.getWorkbenchWindow().getShell().getDisplay()),perspDesc.getId(),modelLayout);
      }
      mPersp.setLabel(perspDesc.getLabel());
      ImageDescriptor imageDescriptor=perspDesc.getImageDescriptor();
      if (imageDescriptor != null) {
        String imageURL=MenuHelper.getImageUrl(imageDescriptor);
        mPersp.setIconURI(imageURL);
      }
      fModelService.hideLocalPlaceholders(fWindow,mPersp);
      mPerspStack.getChildren().add(mPersp);
    }
 else {
      mPerspStack.getChildren().remove(mPersp);
      mPerspStack.getChildren().add(mPersp);
    }
  }
}

Fixed version (ground truth):
/** 
 * DOC ggu Comment method "restorePerspective". try to find and create the perspective. if the existed custom perspective, will use the custom one. won't create original one.
 */
protected void restorePerspective(MPerspectiveStack mPerspStack,String id){
  if (id != null && mPerspStack != null) {
    MPerspective mPersp=null;
    IPerspectiveRegistry perspectiveRegistry=workbench.getPerspectiveRegistry();
    for (    MPerspective mp : mPerspStack.getChildren()) {
      if (mp.getElementId().equals(id)) {
        mPersp=mp;
        break;
      }
 else {
        IPerspectiveDescriptor persp=perspectiveRegistry.findPerspectiveWithId(mp.getElementId());
        if (persp != null && persp instanceof PerspectiveDescriptor) {
          PerspectiveDescriptor pd=(PerspectiveDescriptor)persp;
          if (!pd.getOriginalId().equals(pd.getId()) && pd.getOriginalId().equals(id)) {
            mPersp=mp;
            break;
          }
        }
      }
    }
    IPerspectiveDescriptor perspDesc=perspectiveRegistry.findPerspectiveWithId(id);
    if (perspDesc == null) {
      if (mPersp != null) {
        mPerspStack.getChildren().remove(mPersp);
      }
      return;
    }
    if (mPersp == null) {
      if (fWindow == null) {
        return;
      }
      String perspId=perspDesc.getId();
      WorkbenchPage workbenchPage=(WorkbenchPage)workbench.getActiveWorkbenchWindow().getActivePage();
      mPersp=(MPerspective)fModelService.cloneSnippet(fApp,perspId,fWindow);
      if (mPersp == null) {
        mPersp=fModelService.createModelElement(MPerspective.class);
        mPersp.setElementId(perspDesc.getId());
        IPerspectiveFactory factory=((PerspectiveDescriptor)perspDesc).createFactory();
        ModeledPageLayout modelLayout=new ModeledPageLayout(fWindow,fModelService,fPartService,mPersp,perspDesc,workbenchPage,true);
        factory.createInitialLayout(modelLayout);
        PerspectiveTagger.tagPerspective(mPersp,fModelService);
        PerspectiveExtensionReader reader=new PerspectiveExtensionReader();
        reader.extendLayout(getExtensionTracker(workbenchPage.getWorkbenchWindow().getShell().getDisplay()),perspDesc.getId(),modelLayout);
      }
      mPersp.setLabel(perspDesc.getLabel());
      ImageDescriptor imageDescriptor=perspDesc.getImageDescriptor();
      if (imageDescriptor != null) {
        String imageURL=MenuHelper.getImageUrl(imageDescriptor);
        mPersp.setIconURI(imageURL);
      }
      fModelService.hideLocalPlaceholders(fWindow,mPersp);
      mPerspStack.getChildren().add(mPersp);
    }
 else {
      mPerspStack.getChildren().remove(mPersp);
      mPerspStack.getChildren().add(mPersp);
    }
  }
}