Program: 137022
Project: 137022
Buggy source:
public void findSqlExplorerTableNode(Connection providerConnection,Package parentPackageElement,String tableName,String activeTabName){
  if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
    ITDQRepositoryService service=(ITDQRepositoryService)GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
    if (service != null) {
      service.changePerspectiveAction(SQLExplorerPluginPerspective.class.getName());
    }
 else {
      return;
    }
  }
  Collection<Alias> aliases=SQLExplorerPlugin.getDefault().getAliasManager().getAliases();
  String url=JavaSqlFactory.getURL(providerConnection);
  User currentUser=null;
  for (  Alias alias : aliases) {
    if (alias.getUrl().equals(url)) {
      currentUser=alias.getDefaultUser();
      OpenPasswordConnectDialogAction openDlgAction=new OpenPasswordConnectDialogAction(alias,alias.getDefaultUser(),false);
      openDlgAction.run();
      break;
    }
  }
  Shell shell=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
  if (currentUser == null) {
    MessageDialog.openWarning(shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + tableName);
    return;
  }
  DatabaseNode root=currentUser.getMetaDataSession().getRoot();
  root.load();
  List<INode> catalogs=root.getCatalogs();
  List<INode> schemas=root.getSchemas();
  Catalog doSwitch=SwitchHelpers.CATALOG_SWITCH.doSwitch(parentPackageElement);
  Schema schema=SwitchHelpers.SCHEMA_SWITCH.doSwitch(parentPackageElement);
  INode catalogOrSchemaNode=null;
  if (doSwitch != null) {
    if (catalogs.size() != 0) {
      for (      INode catalogNode : catalogs) {
        if (parentPackageElement.getName().equalsIgnoreCase(catalogNode.getName())) {
          catalogOrSchemaNode=catalogNode;
          break;
        }
      }
    }
 else {
      catalogOrSchemaNode=root;
    }
  }
 else {
    if (schemas.size() == 0) {
      Catalog shcmeaOfCatalogNode=CatalogHelper.getParentCatalog(parentPackageElement);
      for (      INode catalogNode : catalogs) {
        if (shcmeaOfCatalogNode.getName().equalsIgnoreCase(catalogNode.getName())) {
          catalogOrSchemaNode=catalogNode;
          break;
        }
      }
    }
    for (    INode schemaNode : schemas) {
      if (parentPackageElement.getName().equalsIgnoreCase(schemaNode.getName())) {
        catalogOrSchemaNode=schemaNode;
        break;
      }
    }
  }
  if (catalogOrSchemaNode == null) {
    throw new NullPointerException(Messages.getString("String_Node_Str"));
  }
  if (schema != null) {
    if (catalogOrSchemaNode.getSchemaName() == null) {
      catalogOrSchemaNode.setSchemaName(schema.getName());
    }
 else     if (!StringUtils.equals(catalogOrSchemaNode.getSchemaName(),schema.getName())) {
      if (catalogOrSchemaNode.isChildrenLoaded()) {
        SQLExplorerPlugin.getDefault().getDatabaseStructureView().refreshSessionTrees(currentUser.getMetaDataSession());
        List<INode> catalogs2=currentUser.getMetaDataSession().getRoot().getCatalogs();
        if (catalogs2.size() != 0) {
          for (          INode catalogNode : catalogs2) {
            if (catalogOrSchemaNode.getName().equalsIgnoreCase(catalogNode.getName())) {
              catalogOrSchemaNode=catalogNode;
              catalogOrSchemaNode.setSchemaName(schema.getName());
              break;
            }
          }
        }
      }
    }
  }
  INode[] childNodes=catalogOrSchemaNode.getChildNodes();
  TableFolderNode tableFolderNode=null;
  for (  INode node : childNodes) {
    if ("String_Node_Str".equals(node.getQualifiedName())) {
      tableFolderNode=(TableFolderNode)node;
      break;
    }
  }
  if (tableFolderNode == null) {
    log.fatal(Messages.getString("String_Node_Str"));
  }
 else {
    INode[] tableNodes=tableFolderNode.getChildNodes();
    for (    INode node : tableNodes) {
      if (tableName.equalsIgnoreCase(node.getName())) {
        DetailTabManager.setActiveTabName(activeTabName);
        DatabaseStructureView dsView=SQLExplorerPlugin.getDefault().getDatabaseStructureView();
        dsView.setSessionSelectionNode(currentUser.getMetaDataSession(),new StructuredSelection(node));
        SQLExplorerPlugin.getDefault().getConnectionsView().getTreeViewer().setSelection(new StructuredSelection(currentUser));
        return;
      }
    }
  }
  MessageDialog.openWarning(shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + tableName);
}

Fixed version (ground truth):
@Override public void findSqlExplorerTableNode(Connection providerConnection,Package parentPackageElement,String tableName,String activeTabName){
  if (GlobalServiceRegister.getDefault().isServiceRegistered(ITDQRepositoryService.class)) {
    ITDQRepositoryService service=(ITDQRepositoryService)GlobalServiceRegister.getDefault().getService(ITDQRepositoryService.class);
    if (service != null) {
      service.changePerspectiveAction(SQLExplorerPluginPerspective.class.getName());
    }
 else {
      return;
    }
  }
  Collection<Alias> aliases=SQLExplorerPlugin.getDefault().getAliasManager().getAliases();
  String url=JavaSqlFactory.getURL(providerConnection);
  User currentUser=null;
  for (  Alias alias : aliases) {
    if (alias.getUrl().equals(url)) {
      currentUser=alias.getDefaultUser();
      OpenPasswordConnectDialogAction openDlgAction=new OpenPasswordConnectDialogAction(alias,alias.getDefaultUser(),false);
      openDlgAction.run();
      break;
    }
  }
  Shell shell=PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
  if (currentUser == null) {
    MessageDialog.openWarning(shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + tableName);
    return;
  }
  DatabaseNode root=currentUser.getMetaDataSession().getRoot();
  root.load();
  List<INode> catalogs=root.getCatalogs();
  List<INode> schemas=root.getSchemas();
  Catalog doSwitch=SwitchHelpers.CATALOG_SWITCH.doSwitch(parentPackageElement);
  Schema schema=SwitchHelpers.SCHEMA_SWITCH.doSwitch(parentPackageElement);
  INode catalogOrSchemaNode=null;
  if (doSwitch != null) {
    if (catalogs.size() != 0) {
      for (      INode catalogNode : catalogs) {
        if (parentPackageElement.getName().equalsIgnoreCase(catalogNode.getName())) {
          catalogOrSchemaNode=catalogNode;
          break;
        }
      }
    }
 else {
      catalogOrSchemaNode=root;
    }
  }
 else {
    if (schemas.size() == 0) {
      Catalog shcmeaOfCatalogNode=CatalogHelper.getParentCatalog(parentPackageElement);
      for (      INode catalogNode : catalogs) {
        if (shcmeaOfCatalogNode.getName().equalsIgnoreCase(catalogNode.getName())) {
          catalogOrSchemaNode=catalogNode;
          break;
        }
      }
    }
    for (    INode schemaNode : schemas) {
      if (parentPackageElement.getName().equalsIgnoreCase(schemaNode.getName())) {
        catalogOrSchemaNode=schemaNode;
        break;
      }
    }
  }
  if (catalogOrSchemaNode == null) {
    throw new NullPointerException(Messages.getString("String_Node_Str"));
  }
  if (schema != null) {
    if (catalogOrSchemaNode.getSchemaName() == null) {
      catalogOrSchemaNode.setSchemaName(schema.getName());
    }
 else     if (!StringUtils.equals(catalogOrSchemaNode.getSchemaName(),schema.getName())) {
      if (catalogOrSchemaNode.isChildrenLoaded()) {
        SQLExplorerPlugin.getDefault().getDatabaseStructureView().refreshSessionTrees(currentUser.getMetaDataSession());
        List<INode> catalogs2=currentUser.getMetaDataSession().getRoot().getCatalogs();
        if (catalogs2.size() != 0) {
          for (          INode catalogNode : catalogs2) {
            if (catalogOrSchemaNode.getName().equalsIgnoreCase(catalogNode.getName())) {
              catalogOrSchemaNode=catalogNode;
              catalogOrSchemaNode.setSchemaName(schema.getName());
              break;
            }
          }
        }
      }
    }
  }
  INode[] childNodes=catalogOrSchemaNode.getChildNodes();
  if (isNetezza(url)) {
    SchemaNode sNode=getNetezzaSchema(childNodes,JavaSqlFactory.getUsername(providerConnection));
    if (sNode != null) {
      childNodes=sNode.getChildNodes();
    }
  }
  TableFolderNode tableFolderNode=null;
  for (  INode node : childNodes) {
    if ("String_Node_Str".equals(node.getQualifiedName())) {
      tableFolderNode=(TableFolderNode)node;
      break;
    }
  }
  if (tableFolderNode == null) {
    log.fatal(Messages.getString("String_Node_Str"));
  }
 else {
    INode[] tableNodes=tableFolderNode.getChildNodes();
    for (    INode node : tableNodes) {
      if (tableName.equalsIgnoreCase(node.getName())) {
        DetailTabManager.setActiveTabName(activeTabName);
        DatabaseStructureView dsView=SQLExplorerPlugin.getDefault().getDatabaseStructureView();
        dsView.setSessionSelectionNode(currentUser.getMetaDataSession(),new StructuredSelection(node));
        SQLExplorerPlugin.getDefault().getConnectionsView().getTreeViewer().setSelection(new StructuredSelection(currentUser));
        return;
      }
    }
  }
  MessageDialog.openWarning(shell,Messages.getString("String_Node_Str"),Messages.getString("String_Node_Str") + tableName);
}