Program: 72444
Project: 72444
Buggy source:
/** 
 * Builds the context menu. Single selection menu and multiple selection menu are created while selecting just single element or multiple elements
 * @param menu the menu
 */
public void buildContextMenu(IMenuManager menu){
  if (Policy.TRACING_MENU_SHOW) {
    System.out.println("String_Node_Str");
  }
  menu.removeAll();
  menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
  menu.add(new Separator());
  IStructuredSelection selection=(IStructuredSelection)getViewer().getSelection();
  if (selection != null && selection.getFirstElement() != null) {
    Object selected=selection.getFirstElement();
    if (selected instanceof ReportResourceEntry)     selected=((ReportResourceEntry)selected).getReportElement();
    if (selected instanceof ResourceEntryWrapper && ((ResourceEntryWrapper)selected).getType() == ResourceEntryWrapper.LIBRARY) {
      if (useLibraryAction.isEnabled()) {
        menu.add(useLibraryAction);
        menu.add(new Separator());
      }
      if (copyLibraryandCssAction.isEnabled()) {
        menu.add(copyLibraryandCssAction);
      }
      if (deleteLibraryandCssAction.isEnabled()) {
        menu.add(deleteLibraryandCssAction);
      }
      if (moveLibraryandCssAction.isEnabled()) {
        menu.add(moveLibraryandCssAction);
      }
      if (renameLibraryandCssAction.isEnabled()) {
        menu.add(renameLibraryandCssAction);
      }
      menu.add(new Separator());
    }
 else     if (selected instanceof ResourceEntryWrapper && ((ResourceEntryWrapper)selected).getType() == ResourceEntryWrapper.CSS_STYLE_SHEET) {
      menu.add(new UseCssInReportDesignAction(page));
      menu.add(new UseCssInThemeAction(page));
      menu.add(new Separator());
      if (copyLibraryandCssAction.isEnabled()) {
        menu.add(copyLibraryandCssAction);
      }
      if (deleteLibraryandCssAction.isEnabled()) {
        menu.add(deleteLibraryandCssAction);
      }
      if (moveLibraryandCssAction.isEnabled()) {
        menu.add(moveLibraryandCssAction);
      }
      if (renameLibraryandCssAction.isEnabled()) {
        menu.add(renameLibraryandCssAction);
      }
      menu.add(new Separator());
    }
 else     if (selected instanceof LibraryHandle) {
      if (useLibraryAction.isEnabled()) {
        menu.add(useLibraryAction);
        menu.add(new Separator());
      }
    }
 else     if (selected instanceof CssStyleSheetHandle) {
      menu.add(new UseCssInReportDesignAction(page));
      menu.add(new UseCssInThemeAction(page));
      menu.add(new Separator());
    }
 else     if (selected instanceof PathResourceEntry) {
      if (!((PathResourceEntry)selected).isFile()) {
        IMenuManager newMenu=new MenuManager(Messages.getString("String_Node_Str"));
        menu.add(newMenu);
        newMenu.add(newFolderAction);
        newMenu.add(newLibraryAction);
        if (addResourceAction.isEnabled()) {
          menu.add(addResourceAction);
        }
        menu.add(new Separator());
        if (pasteLibraryandCssAction.isEnabled()) {
          menu.add(pasteLibraryandCssAction);
        }
        if (deleteLibraryandCssAction.isEnabled()) {
          menu.add(deleteLibraryandCssAction);
        }
        if (renameLibraryandCssAction.isEnabled()) {
          menu.add(renameLibraryandCssAction);
        }
        menu.add(new Separator());
      }
 else {
        if (copyLibraryandCssAction.isEnabled()) {
          menu.add(copyLibraryandCssAction);
        }
        if (deleteLibraryandCssAction.isEnabled()) {
          menu.add(deleteLibraryandCssAction);
        }
        if (moveLibraryandCssAction.isEnabled()) {
          menu.add(moveLibraryandCssAction);
        }
        if (renameLibraryandCssAction.isEnabled()) {
          menu.add(renameLibraryandCssAction);
        }
        menu.add(new Separator());
      }
    }
    if (canAddtoReport(selected)) {
      if (selection.size() == 1) {
        AddElementtoReport addElementAction=new AddElementtoReport((StructuredViewer)getViewer());
        addElementAction.setSelectedElement(selected);
        menu.add(addElementAction);
        menu.add(new Separator());
      }
    }
    menu.add(new Separator());
    menu.add(refreshExplorerAction);
  }
 else {
    menu.add(addResourceAction);
    menu.add(new Separator());
    menu.add(refreshExplorerAction);
  }
}

Fixed version (ground truth):
/** 
 * Builds the context menu. Single selection menu and multiple selection menu are created while selecting just single element or multiple elements
 * @param menu the menu
 */
public void buildContextMenu(IMenuManager menu){
  if (Policy.TRACING_MENU_SHOW) {
    System.out.println("String_Node_Str");
  }
  resetActionStatus();
  menu.removeAll();
  menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
  menu.add(new Separator());
  IStructuredSelection selection=(IStructuredSelection)page.getSelection();
  if (selection != null && selection.getFirstElement() != null) {
    Object selected=selection.getFirstElement();
    if (selected instanceof ReportResourceEntry) {
      selected=((ReportResourceEntry)selected).getReportElement();
    }
    if (selected instanceof ResourceEntryWrapper) {
      int type=((ResourceEntryWrapper)selected).getType();
      if (type == ResourceEntryWrapper.LIBRARY) {
        menu.add(useLibraryAction);
      }
 else       if (type == ResourceEntryWrapper.CSS_STYLE_SHEET) {
        menu.add(new UseCssInReportDesignAction(page));
        menu.add(new UseCssInThemeAction(page));
      }
      if (((ResourceEntryWrapper)selected).getParent() instanceof PathResourceEntry) {
        menu.add(new Separator());
        menu.add(newMenuGroup);
        menu.add(addResourceAction);
      }
      menu.add(new Separator());
      menu.add(copyLibraryandCssAction);
      if (((ResourceEntryWrapper)selected).getParent() instanceof PathResourceEntry) {
        menu.add(pasteLibraryandCssAction);
        menu.add(deleteLibraryandCssAction);
        menu.add(moveLibraryandCssAction);
        menu.add(renameLibraryandCssAction);
        menu.add(new Separator());
      }
    }
 else     if (selected instanceof LibraryHandle) {
      menu.add(useLibraryAction);
      menu.add(new Separator());
    }
 else     if (selected instanceof CssStyleSheetHandle) {
      menu.add(new UseCssInReportDesignAction(page));
      menu.add(new UseCssInThemeAction(page));
      menu.add(new Separator());
    }
 else     if (selected instanceof PathResourceEntry) {
      menu.add(newMenuGroup);
      menu.add(addResourceAction);
      menu.add(new Separator());
      menu.add(copyLibraryandCssAction);
      menu.add(pasteLibraryandCssAction);
      menu.add(deleteLibraryandCssAction);
      menu.add(moveLibraryandCssAction);
      menu.add(renameLibraryandCssAction);
      menu.add(new Separator());
    }
 else     if (selected instanceof FragmentResourceEntry) {
      if (copyLibraryandCssAction.isEnabled()) {
        menu.add(copyLibraryandCssAction);
        menu.add(new Separator());
      }
    }
    if (canAddtoReport(selected)) {
      if (selection.size() == 1) {
        AddElementtoReport addElementAction=new AddElementtoReport((StructuredViewer)getViewer());
        addElementAction.setSelectedElement(selected);
        menu.add(addElementAction);
        menu.add(new Separator());
      }
    }
    menu.add(new Separator());
    menu.add(refreshExplorerAction);
  }
 else {
    menu.add(addResourceAction);
    menu.add(new Separator());
    menu.add(refreshExplorerAction);
  }
}