Program: 126754
Project: 126754
Buggy source:
public static void addCustomManagementToToolBar(final MetadataTableEditorView tableEditorView,final IMetadataTable table,final boolean readOnly,final MetadataTableEditorView linkedTableEditorView,final IMetadataTable linkedTable,final boolean toPropagate){
  tableEditorView.getTableViewerCreator().getTableViewer().addPostSelectionChangedListener(new ISelectionChangedListener(){
    public void selectionChanged(    SelectionChangedEvent event){
      updateToolBarButtonsOnSelection(event.getSelection(),tableEditorView,table,linkedTableEditorView,linkedTable,readOnly);
    }
  }
);
  boolean isThereCustom=false;
  for (  IMetadataColumn column : table.getListColumns()) {
    if (column.isCustom()) {
      isThereCustom=true;
    }
  }
  if (isThereCustom) {
    tableEditorView.getToolBar().getImportButton().getButton().setEnabled(false);
  }
  if (table.isReadOnly()) {
    tableEditorView.getToolBar().getAddButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getMoveDownButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getMoveUpButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false);
    ResetDBTypesPushButton resetDBTypesButton=tableEditorView.getToolBar().getResetDBTypesButton();
    if (resetDBTypesButton != null) {
      resetDBTypesButton.getButton().setEnabled(false);
    }
  }
 else {
    tableEditorView.getToolBar().getAddButton().getButton().addSelectionListener(new SelectionListener(){
      public void widgetDefaultSelected(      SelectionEvent e){
      }
      public void widgetSelected(      SelectionEvent e){
        table.sortCustomColumns();
        tableEditorView.getTableViewerCreator().getTableViewer().refresh();
      }
    }
);
  }
  SelectionListener customListener=new SelectionListener(){
    public void widgetDefaultSelected(    SelectionEvent e){
    }
    public void widgetSelected(    SelectionEvent e){
      updateToolBarButtonsOnSelection(tableEditorView.getTableViewerCreator().getTableViewer().getSelection(),tableEditorView,table,linkedTableEditorView,linkedTable,readOnly);
    }
  }
;
  tableEditorView.getToolBar().getRemoveButton().getButton().addSelectionListener(customListener);
  tableEditorView.getToolBar().getCopyButton().getButton().addSelectionListener(customListener);
  if (toPropagate) {
    if (linkedTable.isReadOnly()) {
      SelectionListener updateLinkedTableListener=new SelectionListener(){
        public void widgetDefaultSelected(        SelectionEvent e){
        }
        public void widgetSelected(        SelectionEvent e){
          MetadataToolHelper.copyTable(table,linkedTable);
          linkedTableEditorView.getTableViewerCreator().refresh();
          if (linkedTableEditorView != null) {
            linkedTableEditorView.getTableViewerCreator().getTableViewer().refresh();
          }
        }
      }
;
      tableEditorView.getToolBar().getButtons();
      for (      Object element2 : tableEditorView.getToolBar().getButtons()) {
        ExtendedPushButton element=(ExtendedPushButton)element2;
        element.getButton().addSelectionListener(updateLinkedTableListener);
      }
    }
  }
}

Fixed version (ground truth):
public static void addCustomManagementToToolBar(final MetadataTableEditorView tableEditorView,final IMetadataTable table,final boolean readOnly,final MetadataTableEditorView linkedTableEditorView,final IMetadataTable linkedTable,final boolean toPropagate){
  tableEditorView.getTableViewerCreator().getTableViewer().addPostSelectionChangedListener(new ISelectionChangedListener(){
    @Override public void selectionChanged(    SelectionChangedEvent event){
      updateToolBarButtonsOnSelection(event.getSelection(),tableEditorView,table,linkedTableEditorView,linkedTable,readOnly);
    }
  }
);
  boolean isThereCustom=false;
  for (  IMetadataColumn column : table.getListColumns()) {
    if (column.isCustom()) {
      isThereCustom=true;
    }
  }
  if (isThereCustom) {
    tableEditorView.getToolBar().getImportButton().getButton().setEnabled(false);
  }
  if (table.isReadOnly()) {
    tableEditorView.getToolBar().getAddButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getMoveDownButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getMoveUpButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getRemoveButton().getButton().setEnabled(false);
    tableEditorView.getToolBar().getPasteButton().getButton().setEnabled(false);
    ResetDBTypesPushButton resetDBTypesButton=tableEditorView.getToolBar().getResetDBTypesButton();
    if (resetDBTypesButton != null) {
      resetDBTypesButton.getButton().setEnabled(false);
    }
  }
 else {
    tableEditorView.getToolBar().getAddButton().getButton().addSelectionListener(new SelectionListener(){
      @Override public void widgetDefaultSelected(      SelectionEvent e){
      }
      @Override public void widgetSelected(      SelectionEvent e){
        table.sortCustomColumns();
        tableEditorView.getTableViewerCreator().getTableViewer().refresh();
      }
    }
);
  }
  SelectionListener customListener=new SelectionListener(){
    @Override public void widgetDefaultSelected(    SelectionEvent e){
    }
    @Override public void widgetSelected(    SelectionEvent e){
      updateToolBarButtonsOnSelection(tableEditorView.getTableViewerCreator().getTableViewer().getSelection(),tableEditorView,table,linkedTableEditorView,linkedTable,readOnly);
    }
  }
;
  tableEditorView.getToolBar().getRemoveButton().getButton().addSelectionListener(customListener);
  tableEditorView.getToolBar().getCopyButton().getButton().addSelectionListener(customListener);
  if (toPropagate) {
    if (linkedTable.isReadOnly()) {
      SelectionListener updateLinkedTableListener=new SelectionListener(){
        @Override public void widgetDefaultSelected(        SelectionEvent e){
        }
        @Override public void widgetSelected(        SelectionEvent e){
          MetadataToolHelper.copyTable(table,linkedTable);
          linkedTableEditorView.getTableViewerCreator().refresh();
          if (linkedTableEditorView != null) {
            linkedTableEditorView.getTableViewerCreator().getTableViewer().refresh();
          }
        }
      }
;
      tableEditorView.getToolBar().getButtons();
      for (      Object element2 : tableEditorView.getToolBar().getButtons()) {
        ExtendedPushButton element=(ExtendedPushButton)element2;
        element.getButton().addSelectionListener(updateLinkedTableListener);
      }
    }
  }
}