Program: 125677
Project: 125677
Buggy source:
@Override public Object[] getChildren(Object parentElement){
  TableNode tableNode=(TableNode)parentElement;
  List<TableNode> child=tableNode.getChildren();
  boolean extended=false;
  if (!child.isEmpty()) {
    for (    TableNode node : child) {
      if (node.getType() == TableNode.TABLE) {
        extended=true;
        break;
      }
    }
  }
  if (extended) {
    return child.toArray();
  }
  IMetadataConnection metadataConn=tableNode.getMetadataConn();
  Connection conn=null;
  Driver driver=null;
  DatabaseMetaData dbMetaData=null;
  ExtractMetaDataUtils extractMeta=ExtractMetaDataUtils.getInstance();
  if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConn.getDbType())) {
    try {
      dbMetaData=HiveConnectionManager.getInstance().extractDatabaseMetaData(metadataConn);
    }
 catch (    ClassNotFoundException e) {
      e.printStackTrace();
    }
catch (    InstantiationException e) {
      e.printStackTrace();
    }
catch (    IllegalAccessException e) {
      e.printStackTrace();
    }
catch (    SQLException e) {
      e.printStackTrace();
    }
  }
 else {
    List list=extractMeta.getConnectionList(metadataConn);
    if (list != null && !list.isEmpty()) {
      for (int i=0; i < list.size(); i++) {
        if (list.get(i) instanceof Connection) {
          conn=(Connection)list.get(i);
        }
        if (list.get(i) instanceof DriverShim) {
          driver=(DriverShim)list.get(i);
        }
      }
    }
    dbMetaData=extractMeta.getDatabaseMetaData(conn,metadataConn.getDbType(),metadataConn.isSqlMode(),metadataConn.getDatabase());
  }
  int type=tableNode.getType();
  orgomg.cwm.objectmodel.core.Package pack=null;
  List<MetadataTable> tableList=new ArrayList<MetadataTable>();
  if (type == tableNode.CATALOG) {
    if (tableNode.getChildren().isEmpty()) {
      pack=tableNode.getCatalog();
    }
  }
 else   if (type == tableNode.SCHEMA) {
    pack=tableNode.getSchema();
  }
  try {
    if (pack != null) {
      TableInfoParameters paras=tableNode.getParas();
      List<ETableTypes> paraType=paras.getTypes();
      Set<String> availableTableTypes=new HashSet<String>();
      for (      ETableTypes tableType : paraType) {
        availableTableTypes.add(tableType.getName());
      }
      Set<String> tableNameFilter=null;
      if (!paras.isUsedName()) {
        tableNameFilter=new HashSet<String>();
        if (paras.getSqlFiter() != null && !"String_Node_Str".equals(paras.getSqlFiter())) {
          Statement stmt=extractMeta.getConn().createStatement();
          extractMeta.setQueryStatementTimeout(stmt);
          ResultSet rsTables=stmt.executeQuery(paras.getSqlFiter());
          while (rsTables.next()) {
            String nameKey=rsTables.getString(1).trim();
            tableNameFilter.add(nameKey);
          }
          rsTables.close();
          stmt.close();
        }
      }
 else {
        tableNameFilter=paras.getNameFilters();
      }
      List<MetadataTable> tempListTables=new ArrayList<MetadataTable>();
      MetadataFillFactory dbInstance=MetadataFillFactory.getDBInstance(metadataConn);
      for (      String filter : tableNameFilter) {
        tempListTables=dbInstance.fillAll(pack,dbMetaData,metadataConn,null,filter,availableTableTypes.toArray(new String[]{}));
        for (        MetadataTable table : tempListTables) {
          boolean contains=false;
          for (          MetadataTable inListTable : tableList) {
            if (inListTable.getName().equals(table.getName())) {
              contains=true;
              break;
            }
          }
          if (!contains) {
            tableList.add(table);
          }
        }
      }
      if (tableNameFilter.isEmpty()) {
        tempListTables=dbInstance.fillAll(pack,dbMetaData,metadataConn,null,null,availableTableTypes.toArray(new String[]{}));
        for (        MetadataTable table : tempListTables) {
          boolean contains=false;
          for (          MetadataTable inListTable : tableList) {
            if (inListTable.getName().equals(table.getName())) {
              contains=true;
              break;
            }
          }
          if (!contains) {
            tableList.add(table);
          }
        }
      }
    }
  }
 catch (  Exception e) {
    ExceptionHandler.process(e);
  }
 finally {
    String dbType=metadataConn.getDbType();
    String driverClass=metadataConn.getDriverClass();
    if (conn != null) {
      ConnectionUtils.closeConnection(conn);
    }
    if (driver != null) {
      if ((driverClass != null && driverClass.equals(EDatabase4DriverClassName.JAVADB_EMBEDED.getDriverClass())) || (dbType != null && (dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_DERBYCLIENT.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_JCCJDBC.getDisplayName())|| dbType.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName())))) {
        try {
          driver.connect("String_Node_Str",null);
        }
 catch (        SQLException e) {
        }
      }
    }
  }
  transferToTableNode(tableList,tableNode);
  List<TableNode> children=tableNode.getChildren();
  return children.toArray();
}

Fixed version (ground truth):
@Override public Object[] getChildren(Object parentElement){
  TableNode tableNode=(TableNode)parentElement;
  List<TableNode> child=tableNode.getChildren();
  boolean extended=false;
  if (!child.isEmpty()) {
    for (    TableNode node : child) {
      if (node.getType() == TableNode.TABLE) {
        extended=true;
        break;
      }
    }
  }
  if (extended) {
    return child.toArray();
  }
  IMetadataConnection metadataConn=tableNode.getMetadataConn();
  Connection conn=null;
  Driver driver=null;
  DatabaseMetaData dbMetaData=null;
  ExtractMetaDataUtils extractMeta=ExtractMetaDataUtils.getInstance();
  if (EDatabaseTypeName.HIVE.getXmlName().equalsIgnoreCase(metadataConn.getDbType())) {
    try {
      dbMetaData=HiveConnectionManager.getInstance().extractDatabaseMetaData(metadataConn);
    }
 catch (    Exception e) {
      ExceptionHandler.process(e);
    }
  }
 else   if (EDatabaseTypeName.IMPALA.getDisplayName().equalsIgnoreCase(metadataConn.getDbType())) {
    try {
      dbMetaData=ImpalaConnectionManager.getInstance().createConnection(metadataConn).getMetaData();
    }
 catch (    Exception e) {
      ExceptionHandler.process(e);
    }
  }
 else {
    List list=extractMeta.getConnectionList(metadataConn);
    if (list != null && !list.isEmpty()) {
      for (int i=0; i < list.size(); i++) {
        if (list.get(i) instanceof Connection) {
          conn=(Connection)list.get(i);
        }
        if (list.get(i) instanceof DriverShim) {
          driver=(DriverShim)list.get(i);
        }
      }
    }
    dbMetaData=extractMeta.getDatabaseMetaData(conn,metadataConn.getDbType(),metadataConn.isSqlMode(),metadataConn.getDatabase());
  }
  int type=tableNode.getType();
  orgomg.cwm.objectmodel.core.Package pack=null;
  List<MetadataTable> tableList=new ArrayList<MetadataTable>();
  if (type == tableNode.CATALOG) {
    if (tableNode.getChildren().isEmpty()) {
      pack=tableNode.getCatalog();
    }
  }
 else   if (type == tableNode.SCHEMA) {
    pack=tableNode.getSchema();
  }
  try {
    if (pack != null) {
      TableInfoParameters paras=tableNode.getParas();
      List<ETableTypes> paraType=paras.getTypes();
      Set<String> availableTableTypes=new HashSet<String>();
      for (      ETableTypes tableType : paraType) {
        availableTableTypes.add(tableType.getName());
      }
      Set<String> tableNameFilter=null;
      if (!paras.isUsedName()) {
        tableNameFilter=new HashSet<String>();
        if (paras.getSqlFiter() != null && !"String_Node_Str".equals(paras.getSqlFiter())) {
          Statement stmt=extractMeta.getConn().createStatement();
          extractMeta.setQueryStatementTimeout(stmt);
          ResultSet rsTables=stmt.executeQuery(paras.getSqlFiter());
          while (rsTables.next()) {
            String nameKey=rsTables.getString(1).trim();
            tableNameFilter.add(nameKey);
          }
          rsTables.close();
          stmt.close();
        }
      }
 else {
        tableNameFilter=paras.getNameFilters();
      }
      List<MetadataTable> tempListTables=new ArrayList<MetadataTable>();
      MetadataFillFactory dbInstance=MetadataFillFactory.getDBInstance(metadataConn);
      for (      String filter : tableNameFilter) {
        tempListTables=dbInstance.fillAll(pack,dbMetaData,metadataConn,null,filter,availableTableTypes.toArray(new String[]{}));
        for (        MetadataTable table : tempListTables) {
          boolean contains=false;
          for (          MetadataTable inListTable : tableList) {
            if (inListTable.getName().equals(table.getName())) {
              contains=true;
              break;
            }
          }
          if (!contains) {
            tableList.add(table);
          }
        }
      }
      if (tableNameFilter.isEmpty()) {
        tempListTables=dbInstance.fillAll(pack,dbMetaData,metadataConn,null,null,availableTableTypes.toArray(new String[]{}));
        for (        MetadataTable table : tempListTables) {
          boolean contains=false;
          for (          MetadataTable inListTable : tableList) {
            if (inListTable.getName().equals(table.getName())) {
              contains=true;
              break;
            }
          }
          if (!contains) {
            tableList.add(table);
          }
        }
      }
    }
  }
 catch (  Exception e) {
    ExceptionHandler.process(e);
  }
 finally {
    String dbType=metadataConn.getDbType();
    String driverClass=metadataConn.getDriverClass();
    if (conn != null) {
      ConnectionUtils.closeConnection(conn);
    }
    if (driver != null) {
      if ((driverClass != null && driverClass.equals(EDatabase4DriverClassName.JAVADB_EMBEDED.getDriverClass())) || (dbType != null && (dbType.equals(EDatabaseTypeName.JAVADB_EMBEDED.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_DERBYCLIENT.getDisplayName()) || dbType.equals(EDatabaseTypeName.JAVADB_JCCJDBC.getDisplayName())|| dbType.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName())))) {
        try {
          driver.connect("String_Node_Str",null);
        }
 catch (        SQLException e) {
        }
      }
    }
  }
  transferToTableNode(tableList,tableNode);
  List<TableNode> children=tableNode.getChildren();
  return children.toArray();
}