Program: 137694
Project: 137694
Buggy source:
/** 
 * DOC bZhou Comment method "openInSqlEditor".
 * @param tdDataProvider
 * @param query
 * @param editorName
 * @return the specified sql editor.
 */
public SQLEditor openInSqlEditor(Connection tdDataProvider,String query,String editorName){
  String lEditorName=editorName;
  if (lEditorName == null) {
    lEditorName=String.valueOf(SQLExplorerPlugin.getDefault().getEditorSerialNo());
  }
  String username=JavaSqlFactory.getUsername(tdDataProvider);
  if (username == null || "String_Node_Str".equals(username)) {
    MessageUI.openWarning(DefaultMessagesImpl.getString("String_Node_Str"));
    return null;
  }
  SQLExplorerPlugin sqlPlugin=SQLExplorerPlugin.getDefault();
  AliasManager aliasManager=sqlPlugin.getAliasManager();
  Alias alias=aliasManager.getAlias(tdDataProvider.getName());
  if (alias == null) {
    Collection<Connection> allDataProviders=new ArrayList<Connection>();
    List<Connection> conns=new ArrayList<Connection>();
    try {
      for (      ConnectionItem connItem : ProxyRepositoryFactory.getInstance().getMetadataConnectionsItem()) {
        conns.add(connItem.getConnection());
      }
    }
 catch (    PersistenceException e) {
      Log.error(e,e);
    }
    allDataProviders.addAll(conns);
    for (    Connection dataProvider : allDataProviders) {
      if (dataProvider.getName().equals(tdDataProvider.getName())) {
        CWMPlugin.getDefault().addConnetionAliasToSQLPlugin(dataProvider);
        openInSqlEditor(tdDataProvider,query,lEditorName);
      }
    }
  }
 else {
    try {
      Connection connection=SwitchHelpers.CONNECTION_SWITCH.doSwitch(tdDataProvider);
      if (connection != null) {
        String userName=JavaSqlFactory.getUsername(connection);
        SQLEditorInput input=new SQLEditorInput("String_Node_Str" + alias.getName() + "String_Node_Str"+ lEditorName+ "String_Node_Str");
        net.sourceforge.sqlexplorer.dbproduct.User user=alias.getUser(userName);
        DatabaseConnection databaseConnection=SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(connection);
        if (databaseConnection != null) {
          IMetadataConnection metadataConnection=ConvertionHelper.convert(databaseConnection);
          if (metadataConnection != null) {
            user.setMetadataConnection(metadataConnection);
          }
        }
        input.setUser(user);
        IWorkbenchPage page=SQLExplorerPlugin.getDefault().getActivePage();
        SQLEditor editorPart=(SQLEditor)page.openEditor(input,SQLEditor.class.getName());
        editorPart.setText(query);
        return editorPart;
      }
    }
 catch (    PartInitException e) {
      log.error(e,e);
    }
  }
  return null;
}

Fixed version (ground truth):
/** 
 * DOC bZhou Comment method "openInSqlEditor".
 * @param tdDataProvider
 * @param query
 * @param editorName
 * @return the specified sql editor.
 */
public SQLEditor openInSqlEditor(Connection tdDataProvider,String query,String editorName){
  String lEditorName=editorName;
  if (lEditorName == null) {
    lEditorName=String.valueOf(SQLExplorerPlugin.getDefault().getEditorSerialNo());
  }
  SQLExplorerPlugin sqlPlugin=SQLExplorerPlugin.getDefault();
  AliasManager aliasManager=sqlPlugin.getAliasManager();
  Alias alias=aliasManager.getAlias(tdDataProvider.getName());
  if (alias == null) {
    Collection<Connection> allDataProviders=new ArrayList<Connection>();
    List<Connection> conns=new ArrayList<Connection>();
    try {
      for (      ConnectionItem connItem : ProxyRepositoryFactory.getInstance().getMetadataConnectionsItem()) {
        conns.add(connItem.getConnection());
      }
    }
 catch (    PersistenceException e) {
      Log.error(e,e);
    }
    allDataProviders.addAll(conns);
    for (    Connection dataProvider : allDataProviders) {
      if (dataProvider.getName().equals(tdDataProvider.getName())) {
        CWMPlugin.getDefault().addConnetionAliasToSQLPlugin(dataProvider);
        openInSqlEditor(tdDataProvider,query,lEditorName);
      }
    }
  }
 else {
    try {
      Connection connection=SwitchHelpers.CONNECTION_SWITCH.doSwitch(tdDataProvider);
      if (connection != null) {
        String userName=JavaSqlFactory.getUsername(connection);
        SQLEditorInput input=new SQLEditorInput("String_Node_Str" + alias.getName() + "String_Node_Str"+ lEditorName+ "String_Node_Str");
        net.sourceforge.sqlexplorer.dbproduct.User user=alias.hasNoUserName() ? alias.getDefaultUser() : alias.getUser(userName);
        DatabaseConnection databaseConnection=SwitchHelpers.DATABASECONNECTION_SWITCH.doSwitch(connection);
        if (databaseConnection != null) {
          IMetadataConnection metadataConnection=ConvertionHelper.convert(databaseConnection);
          if (metadataConnection != null) {
            user.setMetadataConnection(metadataConnection);
          }
        }
        input.setUser(user);
        IWorkbenchPage page=SQLExplorerPlugin.getDefault().getActivePage();
        SQLEditor editorPart=(SQLEditor)page.openEditor(input,SQLEditor.class.getName());
        editorPart.setText(query);
        return editorPart;
      }
    }
 catch (    PartInitException e) {
      log.error(e,e);
    }
  }
  return null;
}