Program: 120926
Project: 120926
Buggy source:
@Override protected void doRun(){
  IStructuredSelection selection=(IStructuredSelection)getSelection();
  if (repositoryNode == null && selection != null) {
    repositoryNode=(RepositoryNode)selection.getFirstElement();
  }
  IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
  IRepositoryViewObject nodeObject=repositoryNode.getObject();
  boolean locked=false;
  if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
    if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
      locked=true;
    }
  }
  if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
    final String title="String_Node_Str";
    String nodeName=nodeObject.getRepositoryObjectType().getLabel();
    final String message="String_Node_Str";
    Display.getDefault().syncExec(new Runnable(){
      @Override public void run(){
        MessageDialog dialog=new MessageDialog(new Shell(),title,null,message,MessageDialog.ERROR,new String[]{IDialogConstants.OK_LABEL},0);
        dialog.open();
      }
    }
);
    return;
  }
  DatabaseConnectionItem dbConnectionItem=null;
  ConnectionParameters connParameters=new ConnectionParameters();
  if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
    dbConnectionItem=(DatabaseConnectionItem)repositoryNode.getObject().getProperty().getItem();
    connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
    connParameters.setRepositoryId(repositoryNode.getObject().getId());
    connParameters.setQuery("String_Node_Str");
  }
 else   if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
    QueryRepositoryObject queryRepositoryObject=(QueryRepositoryObject)repositoryNode.getObject();
    dbConnectionItem=(DatabaseConnectionItem)queryRepositoryObject.getProperty().getItem();
    connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
    connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
    connParameters.setQueryObject(queryRepositoryObject.getQuery());
    connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
    connParameters.setFirstOpenSqlBuilder(true);
  }
 else   if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
    dbConnectionItem=(DatabaseConnectionItem)repositoryNode.getObject().getProperty().getItem();
    connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
    connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
    connParameters.setMetadataTable((MetadataTableRepositoryObject)repositoryNode.getObject());
    connParameters.setQuery("String_Node_Str");
  }
  IRepositoryView viewPart=getViewPart();
  Display display=null;
  if (viewPart != null) {
    display=viewPart.getViewer().getControl().getDisplay();
  }
 else {
    display=Display.getCurrent();
    if (display == null) {
      display=Display.getDefault();
    }
  }
  Shell parentShell=new Shell(display);
  TextUtil.setDialogTitle(TalendTextUtils.SQL_BUILDER_TITLE_REP);
  Connection connection=dbConnectionItem.getConnection();
  String selectedContext=null;
  if (connection.isContextMode()) {
    ContextItem contextItem=ContextUtils.getContextItemById2(connection.getContextId());
    if (contextItem != null && connection.isContextMode()) {
      ContextSetsSelectionDialog setsDialog=new ContextSetsSelectionDialog(null,contextItem,false);
      setsDialog.open();
      selectedContext=setsDialog.getSelectedContext();
    }
  }
  SQLBuilderDialog dial=new SQLBuilderDialog(parentShell,repositoryNode,selectedContext);
  if (connection instanceof DatabaseConnection) {
    IMetadataConnection imetadataConnection=ConvertionHelper.convert(connection,true);
    connParameters.setSchema(imetadataConnection.getSchema() == null ? "String_Node_Str" : imetadataConnection.getSchema());
  }
  connParameters.setNodeReadOnly(false);
  connParameters.setFromRepository(true);
  dial.setConnParameters(connParameters);
  dial.open();
  IRepositoryView view=getViewPart();
  if (view != null) {
    view.refreshView();
  }
}

Fixed version (ground truth):
@Override protected void doRun(){
  IStructuredSelection selection=(IStructuredSelection)getSelection();
  if (repositoryNode == null && selection != null) {
    repositoryNode=(RepositoryNode)selection.getFirstElement();
  }
  IProxyRepositoryFactory factory=ProxyRepositoryFactory.getInstance();
  IRepositoryViewObject nodeObject=repositoryNode.getObject();
  boolean locked=false;
  if (!factory.getRepositoryContext().isEditableAsReadOnly()) {
    if (nodeObject.getRepositoryStatus() == ERepositoryStatus.LOCK_BY_OTHER) {
      locked=true;
    }
  }
  if (locked || RepositoryManager.isOpenedItemInEditor(nodeObject)) {
    final String title="String_Node_Str";
    String nodeName=nodeObject.getRepositoryObjectType().getLabel();
    final String message="String_Node_Str";
    Display.getDefault().syncExec(new Runnable(){
      @Override public void run(){
        MessageDialog dialog=new MessageDialog(new Shell(),title,null,message,MessageDialog.ERROR,new String[]{IDialogConstants.OK_LABEL},0);
        dialog.open();
      }
    }
);
    return;
  }
  DatabaseConnectionItem dbConnectionItem=null;
  boolean readOnly=false;
  ConnectionParameters connParameters=new ConnectionParameters();
  if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CONNECTIONS) {
    dbConnectionItem=(DatabaseConnectionItem)repositoryNode.getObject().getProperty().getItem();
    connParameters.setRepositoryName(repositoryNode.getObject().getLabel());
    connParameters.setRepositoryId(repositoryNode.getObject().getId());
    connParameters.setQuery("String_Node_Str");
  }
 else   if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_QUERY) {
    QueryRepositoryObject queryRepositoryObject=(QueryRepositoryObject)repositoryNode.getObject();
    readOnly=SubItemHelper.isDeleted(queryRepositoryObject.getAbstractMetadataObject());
    dbConnectionItem=(DatabaseConnectionItem)queryRepositoryObject.getProperty().getItem();
    connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
    connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
    connParameters.setQueryObject(queryRepositoryObject.getQuery());
    connParameters.setQuery(queryRepositoryObject.getQuery().getValue());
    connParameters.setFirstOpenSqlBuilder(true);
  }
 else   if (repositoryNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
    dbConnectionItem=(DatabaseConnectionItem)repositoryNode.getObject().getProperty().getItem();
    connParameters.setRepositoryName(dbConnectionItem.getProperty().getLabel());
    connParameters.setRepositoryId(dbConnectionItem.getProperty().getId());
    connParameters.setMetadataTable((MetadataTableRepositoryObject)repositoryNode.getObject());
    connParameters.setQuery("String_Node_Str");
  }
  IRepositoryView viewPart=getViewPart();
  Display display=null;
  if (viewPart != null) {
    display=viewPart.getViewer().getControl().getDisplay();
  }
 else {
    display=Display.getCurrent();
    if (display == null) {
      display=Display.getDefault();
    }
  }
  Shell parentShell=new Shell(display);
  TextUtil.setDialogTitle(TalendTextUtils.SQL_BUILDER_TITLE_REP);
  Connection connection=dbConnectionItem.getConnection();
  String selectedContext=null;
  if (connection.isContextMode()) {
    ContextItem contextItem=ContextUtils.getContextItemById2(connection.getContextId());
    if (contextItem != null && connection.isContextMode()) {
      ContextSetsSelectionDialog setsDialog=new ContextSetsSelectionDialog(null,contextItem,false);
      setsDialog.open();
      selectedContext=setsDialog.getSelectedContext();
    }
  }
  SQLBuilderDialog dial=new SQLBuilderDialog(parentShell,repositoryNode,selectedContext);
  dial.setReadOnly(readOnly);
  if (connection instanceof DatabaseConnection) {
    IMetadataConnection imetadataConnection=ConvertionHelper.convert(connection,true);
    connParameters.setSchema(imetadataConnection.getSchema() == null ? "String_Node_Str" : imetadataConnection.getSchema());
  }
  connParameters.setNodeReadOnly(readOnly);
  connParameters.setFromRepository(true);
  dial.setConnParameters(connParameters);
  dial.open();
  IRepositoryView view=getViewPart();
  if (view != null) {
    view.refreshView();
  }
}