Program: 129025
Project: 129025
Buggy source:
public static List<TdColumn> extractColumns(DatabaseMetaData dbMetaData,TableNode tableNode,IMetadataConnection metadataConnection,String databaseType){
  columnIndex=0;
  List<TdColumn> metadataColumns=new ArrayList<TdColumn>();
  HashMap<String,String> primaryKeys=new HashMap<String,String>();
  try {
    String catalogName=null;
    String schemaName=null;
    TableNode parent=tableNode.getParent();
    if (parent != null) {
      if (parent.getType() == TableNode.CATALOG) {
        catalogName=parent.getValue();
      }
 else       if (parent.getType() == TableNode.SCHEMA) {
        schemaName=parent.getValue();
        TableNode catalogNode=parent.getParent();
        if (catalogNode != null) {
          catalogName=catalogNode.getValue();
        }
      }
    }
    boolean isAccess=EDatabaseTypeName.ACCESS.getDisplayName().equals(metadataConnection.getDbType());
    boolean isHive=MetadataConnectionUtils.isHive(dbMetaData);
    if (!isHive) {
      try {
        ResultSet keys;
        if (!isAccess) {
          keys=dbMetaData.getPrimaryKeys(catalogName,schemaName,tableNode.getValue());
        }
 else {
          keys=dbMetaData.getIndexInfo(catalogName,schemaName,tableNode.getValue(),true,true);
        }
        primaryKeys.clear();
        while (keys.next()) {
          primaryKeys.put(keys.getString("String_Node_Str"),"String_Node_Str");
        }
        keys.close();
      }
 catch (      Exception e) {
        log.error(e.toString());
      }
      Connection connection=dbMetaData.getConnection();
      checkUniqueKeyConstraint(tableNode.getValue(),primaryKeys,connection);
    }
    String tableName=tableNode.getValue();
    ResultSet columns;
    if (ExtractMetaDataUtils.isUseAllSynonyms()) {
      String sql="String_Node_Str" + tableName + "String_Node_Str";
      Statement stmt=ExtractMetaDataUtils.conn.createStatement();
      ExtractMetaDataUtils.setQueryStatementTimeout(stmt);
      columns=stmt.executeQuery(sql);
    }
 else {
      columns=dbMetaData.getColumns(catalogName,schemaName,tableName,null);
    }
    IRepositoryService repositoryService=CoreRuntimePlugin.getInstance().getRepositoryService();
    boolean isMSSQL=EDatabaseTypeName.MSSQL.getDisplayName().equals(metadataConnection.getDbType());
    while (columns.next()) {
      Boolean b=false;
      String fetchTableName=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
      fetchTableName=ManagementTextUtils.filterSpecialChar(fetchTableName);
      if (fetchTableName.equals(tableName) || databaseType.equals(EDatabaseTypeName.SQLITE.getDisplayName())) {
        TdColumn metadataColumn=RelationalFactory.eINSTANCE.createTdColumn();
        String label=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        label=ManagementTextUtils.filterSpecialChar(label);
        String sub="String_Node_Str";
        String sub2="String_Node_Str";
        String label2=label;
        if (label != null && label.length() > 0 && label.startsWith("String_Node_Str")) {
          sub=label.substring(1);
          if (sub != null && sub.length() > 0) {
            sub2=sub.substring(1);
          }
        }
        if (coreService.isKeyword(label) || coreService.isKeyword(sub) || coreService.isKeyword(sub2)) {
          label="String_Node_Str" + label;
          b=true;
        }
        metadataColumn.setLabel(label);
        metadataColumn.setOriginalField(label2);
        if (repositoryService != null) {
          label=repositoryService.validateColumnName(label,columnIndex);
          metadataColumn.setLabel(label);
        }
        columnIndex++;
        if (primaryKeys != null && !primaryKeys.isEmpty() && primaryKeys.get(metadataColumn.getOriginalField()) != null) {
          metadataColumn.setKey(true);
        }
 else {
          metadataColumn.setKey(false);
        }
        String typeName="String_Node_Str";
        if (ExtractMetaDataUtils.isUseAllSynonyms()) {
          typeName="String_Node_Str";
        }
        String dbType=ExtractMetaDataUtils.getStringMetaDataInfo(columns,typeName,null).toUpperCase();
        dbType=dbType.trim();
        dbType=ManagementTextUtils.filterSpecialChar(dbType);
        dbType=handleDBtype(dbType);
        metadataColumn.setSourceType(dbType);
        Integer columnSize;
        columnSize=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
        metadataColumn.setLength(columnSize);
        String talendType=null;
        if (metadataConnection.getMapping() != null) {
          mappingTypeRetriever=MetadataTalendType.getMappingTypeRetriever(metadataConnection.getMapping());
        }
        Integer intMetaDataInfo=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
        talendType=mappingTypeRetriever.getDefaultSelectedTalendType(dbType,columnSize,intMetaDataInfo);
        talendType=ManagementTextUtils.filterSpecialChar(talendType);
        if (talendType == null) {
          if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
            talendType=JavaTypesManager.getDefaultJavaType().getId();
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
 else {
            talendType="String_Node_Str";
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
        }
 else {
        }
        metadataColumn.setTalendType(talendType);
        boolean isNullable=ExtractMetaDataUtils.getBooleanMetaDataInfo(columns,"String_Node_Str");
        metadataColumn.setNullable(isNullable);
        String commentInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        if (commentInfo != null && commentInfo.length() > 0) {
          commentInfo=ManagementTextUtils.filterSpecialChar(commentInfo);
        }
        metadataColumn.setComment(commentInfo);
        if (!isAccess) {
          TDColumnAttributeHelper.addColumnAttribute(label,label2,dbType,columnSize,intMetaDataInfo,commentInfo,columns,metadataColumn,(DatabaseConnection)metadataConnection.getCurrentConnection());
        }
        if (isMSSQL && "String_Node_Str".equals(dbType)) {
          Integer ident1=0;
          Integer ident2=0;
          try {
            PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + tableNode.getValue() + "String_Node_Str"+ "String_Node_Str"+ tableNode.getValue()+ "String_Node_Str");
            ResultSet resultSet=null;
            ExtractMetaDataUtils.setQueryStatementTimeout(statement);
            if (statement.execute()) {
              resultSet=statement.getResultSet();
              while (resultSet.next()) {
                String st1=resultSet.getString(1);
                String st2=resultSet.getString(2);
                Integer valueOf1=Integer.valueOf(st1);
                if (valueOf1 != null) {
                  ident1=valueOf1;
                }
                Integer valueOf2=Integer.valueOf(st2);
                if (valueOf2 != null) {
                  ident2=valueOf2;
                }
              }
            }
            resultSet.close();
            statement.close();
          }
 catch (          Exception e) {
            log.error(e.toString());
          }
          metadataColumn.setLength(ident1);
          metadataColumn.setPrecision(ident2);
        }
 else {
          metadataColumn.setPrecision(intMetaDataInfo);
        }
        String stringMetaDataInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",dbMetaData);
        if (stringMetaDataInfo != null && stringMetaDataInfo.length() > 0 && stringMetaDataInfo.charAt(0) == 0x0) {
          stringMetaDataInfo="String_Node_Str";
        }
        stringMetaDataInfo=ManagementTextUtils.filterSpecialChar(stringMetaDataInfo);
        metadataColumn.setDefaultValue(stringMetaDataInfo);
        if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
          if (dbType.equals("String_Node_Str")) {
            metadataColumn.setLength(metadataColumn.getPrecision());
            metadataColumn.setPrecision(-1);
          }
        }
        metadataColumns.add(metadataColumn);
      }
    }
    if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
      try {
        PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + tableNode.getValue() + "String_Node_Str");
        ResultSet keys=null;
        ExtractMetaDataUtils.setQueryStatementTimeout(statement);
        if (statement.execute()) {
          keys=statement.getResultSet();
          int i=0;
          while (keys.next()) {
            MetadataColumn metadataColumn=metadataColumns.get(i++);
            metadataColumn.setComment(ManagementTextUtils.filterSpecialChar(keys.getString("String_Node_Str")));
          }
        }
        keys.close();
        statement.close();
      }
 catch (      Exception e) {
        log.error(e.toString());
      }
    }
    columns.close();
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
catch (  Exception e) {
    ExceptionHandler.process(e);
    log.error(e.toString());
    throw new RuntimeException(e);
  }
  return metadataColumns;
}

Fixed version (ground truth):
public static List<TdColumn> extractColumns(DatabaseMetaData dbMetaData,TableNode tableNode,IMetadataConnection metadataConnection,String databaseType){
  columnIndex=0;
  List<TdColumn> metadataColumns=new ArrayList<TdColumn>();
  List<String> columnLabels=new ArrayList<String>();
  HashMap<String,String> primaryKeys=new HashMap<String,String>();
  try {
    String catalogName=null;
    String schemaName=null;
    TableNode parent=tableNode.getParent();
    if (parent != null) {
      if (parent.getType() == TableNode.CATALOG) {
        catalogName=parent.getValue();
      }
 else       if (parent.getType() == TableNode.SCHEMA) {
        schemaName=parent.getValue();
        TableNode catalogNode=parent.getParent();
        if (catalogNode != null) {
          catalogName=catalogNode.getValue();
        }
      }
    }
    boolean isAccess=EDatabaseTypeName.ACCESS.getDisplayName().equals(metadataConnection.getDbType());
    boolean isHive=MetadataConnectionUtils.isHive(dbMetaData);
    if (!isHive) {
      try {
        ResultSet keys;
        if (!isAccess) {
          keys=dbMetaData.getPrimaryKeys(catalogName,schemaName,tableNode.getValue());
        }
 else {
          keys=dbMetaData.getIndexInfo(catalogName,schemaName,tableNode.getValue(),true,true);
        }
        primaryKeys.clear();
        while (keys.next()) {
          primaryKeys.put(keys.getString("String_Node_Str"),"String_Node_Str");
        }
        keys.close();
      }
 catch (      Exception e) {
        log.error(e.toString());
      }
      Connection connection=dbMetaData.getConnection();
      checkUniqueKeyConstraint(tableNode.getValue(),primaryKeys,connection);
    }
    String tableName=tableNode.getValue();
    ResultSet columns;
    if (ExtractMetaDataUtils.isUseAllSynonyms()) {
      String sql="String_Node_Str" + tableName + "String_Node_Str";
      Statement stmt=ExtractMetaDataUtils.conn.createStatement();
      ExtractMetaDataUtils.setQueryStatementTimeout(stmt);
      columns=stmt.executeQuery(sql);
    }
 else {
      columns=dbMetaData.getColumns(catalogName,schemaName,tableName,null);
    }
    IRepositoryService repositoryService=CoreRuntimePlugin.getInstance().getRepositoryService();
    boolean isMSSQL=EDatabaseTypeName.MSSQL.getDisplayName().equals(metadataConnection.getDbType());
    while (columns.next()) {
      Boolean b=false;
      String fetchTableName=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
      fetchTableName=ManagementTextUtils.filterSpecialChar(fetchTableName);
      if (fetchTableName.equals(tableName) || databaseType.equals(EDatabaseTypeName.SQLITE.getDisplayName())) {
        TdColumn metadataColumn=RelationalFactory.eINSTANCE.createTdColumn();
        String label=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        label=ManagementTextUtils.filterSpecialChar(label);
        String sub="String_Node_Str";
        String sub2="String_Node_Str";
        String label2=label;
        if (label != null && label.length() > 0 && label.startsWith("String_Node_Str")) {
          sub=label.substring(1);
          if (sub != null && sub.length() > 0) {
            sub2=sub.substring(1);
          }
        }
        if (coreService.isKeyword(label) || coreService.isKeyword(sub) || coreService.isKeyword(sub2)) {
          label="String_Node_Str" + label;
          b=true;
        }
        metadataColumn.setOriginalField(label2);
        label=MetadataToolHelper.validateColumnName(label,columnIndex,columnLabels);
        metadataColumn.setLabel(label);
        columnIndex++;
        if (primaryKeys != null && !primaryKeys.isEmpty() && primaryKeys.get(metadataColumn.getOriginalField()) != null) {
          metadataColumn.setKey(true);
        }
 else {
          metadataColumn.setKey(false);
        }
        String typeName="String_Node_Str";
        if (ExtractMetaDataUtils.isUseAllSynonyms()) {
          typeName="String_Node_Str";
        }
        String dbType=ExtractMetaDataUtils.getStringMetaDataInfo(columns,typeName,null).toUpperCase();
        dbType=dbType.trim();
        dbType=ManagementTextUtils.filterSpecialChar(dbType);
        dbType=handleDBtype(dbType);
        metadataColumn.setSourceType(dbType);
        Integer columnSize;
        columnSize=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
        metadataColumn.setLength(columnSize);
        String talendType=null;
        if (metadataConnection.getMapping() != null) {
          mappingTypeRetriever=MetadataTalendType.getMappingTypeRetriever(metadataConnection.getMapping());
        }
        Integer intMetaDataInfo=ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str");
        talendType=mappingTypeRetriever.getDefaultSelectedTalendType(dbType,columnSize,intMetaDataInfo);
        talendType=ManagementTextUtils.filterSpecialChar(talendType);
        if (talendType == null) {
          if (LanguageManager.getCurrentLanguage() == ECodeLanguage.JAVA) {
            talendType=JavaTypesManager.getDefaultJavaType().getId();
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
 else {
            talendType="String_Node_Str";
            log.warn(Messages.getString("String_Node_Str",dbType));
          }
        }
 else {
        }
        metadataColumn.setTalendType(talendType);
        boolean isNullable=ExtractMetaDataUtils.getBooleanMetaDataInfo(columns,"String_Node_Str");
        metadataColumn.setNullable(isNullable);
        String commentInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",null);
        if (commentInfo != null && commentInfo.length() > 0) {
          commentInfo=ManagementTextUtils.filterSpecialChar(commentInfo);
        }
        metadataColumn.setComment(commentInfo);
        if (!isAccess) {
          TDColumnAttributeHelper.addColumnAttribute(label,label2,dbType,columnSize,intMetaDataInfo,commentInfo,columns,metadataColumn,(DatabaseConnection)metadataConnection.getCurrentConnection());
        }
        if (isMSSQL && "String_Node_Str".equals(dbType)) {
          Integer ident1=0;
          Integer ident2=0;
          try {
            PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + tableNode.getValue() + "String_Node_Str"+ "String_Node_Str"+ tableNode.getValue()+ "String_Node_Str");
            ResultSet resultSet=null;
            ExtractMetaDataUtils.setQueryStatementTimeout(statement);
            if (statement.execute()) {
              resultSet=statement.getResultSet();
              while (resultSet.next()) {
                String st1=resultSet.getString(1);
                String st2=resultSet.getString(2);
                Integer valueOf1=Integer.valueOf(st1);
                if (valueOf1 != null) {
                  ident1=valueOf1;
                }
                Integer valueOf2=Integer.valueOf(st2);
                if (valueOf2 != null) {
                  ident2=valueOf2;
                }
              }
            }
            resultSet.close();
            statement.close();
          }
 catch (          Exception e) {
            log.error(e.toString());
          }
          metadataColumn.setLength(ident1);
          metadataColumn.setPrecision(ident2);
        }
 else {
          metadataColumn.setPrecision(intMetaDataInfo);
        }
        String stringMetaDataInfo=ExtractMetaDataUtils.getStringMetaDataInfo(columns,"String_Node_Str",dbMetaData);
        if (stringMetaDataInfo != null && stringMetaDataInfo.length() > 0 && stringMetaDataInfo.charAt(0) == 0x0) {
          stringMetaDataInfo="String_Node_Str";
        }
        stringMetaDataInfo=ManagementTextUtils.filterSpecialChar(stringMetaDataInfo);
        metadataColumn.setDefaultValue(stringMetaDataInfo);
        if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
          if (dbType.equals("String_Node_Str")) {
            metadataColumn.setLength(metadataColumn.getPrecision());
            metadataColumn.setPrecision(-1);
          }
        }
        metadataColumns.add(metadataColumn);
        columnLabels.add(metadataColumn.getLabel());
      }
    }
    if (EDatabaseTypeName.ORACLEFORSID.getDisplayName().equals(metadataConnection.getDbType()) || EDatabaseTypeName.ORACLESN.getDisplayName().equals(metadataConnection.getDbType())) {
      try {
        PreparedStatement statement=ExtractMetaDataUtils.conn.prepareStatement("String_Node_Str" + tableNode.getValue() + "String_Node_Str");
        ResultSet keys=null;
        ExtractMetaDataUtils.setQueryStatementTimeout(statement);
        if (statement.execute()) {
          keys=statement.getResultSet();
          int i=0;
          while (keys.next()) {
            MetadataColumn metadataColumn=metadataColumns.get(i++);
            metadataColumn.setComment(ManagementTextUtils.filterSpecialChar(keys.getString("String_Node_Str")));
          }
        }
        keys.close();
        statement.close();
      }
 catch (      Exception e) {
        log.error(e.toString());
      }
    }
    columns.close();
  }
 catch (  SQLException e) {
    e.printStackTrace();
  }
catch (  Exception e) {
    ExceptionHandler.process(e);
    log.error(e.toString());
    throw new RuntimeException(e);
  }
  return metadataColumns;
}