Program: 127348
Project: 127348
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;
  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=ExtractMetaDataUtils.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=ExtractMetaDataUtils.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=ExtractMetaDataUtils.conn.createStatement();
          ExtractMetaDataUtils.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>();
      for (      String filter : tableNameFilter) {
        tempListTables=MetadataFillFactory.getDBInstance().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=MetadataFillFactory.getDBInstance().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();
    if (dbType != null && (dbType.equals(EDatabaseTypeName.HSQLDB.getDisplayName()) || dbType.equals(EDatabaseTypeName.HSQLDB_SERVER.getDisplayName()) || dbType.equals(EDatabaseTypeName.HSQLDB_WEBSERVER.getDisplayName())|| dbType.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName()))) {
      ExtractMetaDataUtils.closeConnection();
    }
    if (driver != null) {
      String driverClass=metadataConn.getDriverClass();
      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 (    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>();
      for (      String filter : tableNameFilter) {
        tempListTables=MetadataFillFactory.getDBInstance().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=MetadataFillFactory.getDBInstance().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();
    if (dbType != null && (dbType.equals(EDatabaseTypeName.HSQLDB.getDisplayName()) || dbType.equals(EDatabaseTypeName.HSQLDB_SERVER.getDisplayName()) || dbType.equals(EDatabaseTypeName.HSQLDB_WEBSERVER.getDisplayName())|| dbType.equals(EDatabaseTypeName.HSQLDB_IN_PROGRESS.getDisplayName()))) {
      extractMeta.closeConnection();
    }
    if (driver != null) {
      String driverClass=metadataConn.getDriverClass();
      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();
}