Program: 121747
Project: 121747
Buggy source:
@Override protected void doRun(){
  IStructuredSelection selection=(IStructuredSelection)getSelection();
  if (repositoryNode == null && selection != null) {
    repositoryNode=(RepositoryNode)selection.getFirstElement();
  }
  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());
  }
  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();
  }
  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();
  }
}