Program: 123845
Project: 123845
Buggy source:
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());
  }
 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");
  }
  Shell parentShell=new Shell(getViewPart().getViewer().getControl().getDisplay());
  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((DatabaseConnection)connection,true);
    connParameters.setSchema(imetadataConnection.getSchema());
  }
  connParameters.setNodeReadOnly(false);
  connParameters.setFromRepository(true);
  dial.setConnParameters(connParameters);
  dial.open();
  RepositoryManager.getRepositoryView().refreshView();
}

Fixed version (ground truth):
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");
  }
  Shell parentShell=new Shell(getViewPart().getViewer().getControl().getDisplay());
  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((DatabaseConnection)connection,true);
    connParameters.setSchema(imetadataConnection.getSchema());
  }
  connParameters.setNodeReadOnly(false);
  connParameters.setFromRepository(true);
  dial.setConnParameters(connParameters);
  dial.open();
  RepositoryManager.getRepositoryView().refreshView();
}