Program: 129843
Project: 129843
Buggy source:
private static void fillSynonmsForMSSQL(IMetadataConnection iMetadataConnection,List<TdColumn> metadataColumns,NamedColumnSet table,String tableName,DatabaseMetaData dbMetaData) throws SQLException {
  String str=tableName;
  String TABLE_SCHEMA=null;
  String TABLE_NAME=null;
  String strsplit=str;
  int count=0;
  if (tableName != null) {
    while (strsplit.contains("String_Node_Str")) {
      count++;
      strsplit=strsplit.substring(strsplit.indexOf("String_Node_Str") + 1);
    }
    if (count > 1) {
      strsplit=str.substring(str.indexOf("String_Node_Str") + 1);
      str=strsplit;
    }
    TABLE_SCHEMA=str.substring(0,str.indexOf("String_Node_Str"));
    TABLE_NAME=str.substring(str.indexOf("String_Node_Str") + 1);
  }
  String synSQL="String_Node_Str" + TABLE_SCHEMA + "String_Node_Str"+ TABLE_NAME+ "String_Node_Str";
  if (!("String_Node_Str").equals(iMetadataConnection.getDatabase())) {
    synSQL+="String_Node_Str" + iMetadataConnection.getDatabase() + "String_Node_Str";
  }
  Statement sta=ExtractMetaDataUtils.conn.createStatement();
  ExtractMetaDataUtils.setQueryStatementTimeout(sta);
  ResultSet columns=sta.executeQuery(synSQL);
  String typeName=null;
  int index=0;
  while (columns.next()) {
    int column_size=0;
    String lenString=null;
    long numPrecRadix=0;
    String columnName=columns.getString(GetColumn.COLUMN_NAME.name());
    TdColumn column=ColumnHelper.createTdColumn(columnName);
    String label=column.getLabel();
    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);
      }
    }
    ICoreService coreService=CoreRuntimePlugin.getInstance().getCoreService();
    if (coreService.isKeyword(label) || coreService.isKeyword(sub) || coreService.isKeyword(sub2)) {
      label="String_Node_Str" + label;
    }
    label=MetadataToolHelper.validateColumnName(label,index);
    column.setLabel(label);
    column.setOriginalField(label2);
    if (!ExtractMetaDataUtils.needFakeDatabaseMetaData(iMetadataConnection.getDbType(),iMetadataConnection.isSqlMode())) {
      typeName=columns.getString(GetColumn.DATA_TYPE.name());
    }
    try {
      lenString="String_Node_Str";
      column_size=columns.getInt("String_Node_Str");
      if (columns.getString("String_Node_Str") != null) {
        column_size=columns.getInt("String_Node_Str");
        lenString="String_Node_Str";
      }
      column.setLength(column_size);
      numPrecRadix=columns.getLong("String_Node_Str");
      column.setPrecision(numPrecRadix);
    }
 catch (    Exception e1) {
      log.warn(e1,e1);
    }
    DatabaseConnection dbConnection=(DatabaseConnection)ConnectionHelper.getConnection(table);
    String dbmsId=dbConnection == null ? null : dbConnection.getDbmsId();
    if (dbmsId != null) {
      MappingTypeRetriever mappingTypeRetriever=MetadataTalendType.getMappingTypeRetriever(dbmsId);
      String talendType=mappingTypeRetriever.getDefaultSelectedTalendType(typeName,ExtractMetaDataUtils.getIntMetaDataInfo(columns,lenString),ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str"));
      column.setTalendType(talendType);
      String defaultSelectedDbType=MetadataTalendType.getMappingTypeRetriever(dbConnection.getDbmsId()).getDefaultSelectedDbType(talendType);
      column.setSourceType(defaultSelectedDbType);
    }
    try {
      column.setNullable("String_Node_Str".equals(columns.getString("String_Node_Str")));
    }
 catch (    Exception e) {
      log.error(e);
    }
    metadataColumns.add(column);
    index++;
  }
  columns.close();
}

Fixed version (ground truth):
private static void fillSynonmsForMSSQL(IMetadataConnection iMetadataConnection,List<TdColumn> metadataColumns,NamedColumnSet table,String tableName,DatabaseMetaData dbMetaData) throws SQLException {
  String str=tableName;
  String TABLE_SCHEMA=null;
  String TABLE_NAME=null;
  String splitstr=str;
  int position=0;
  int count=0;
  if (tableName != null) {
    while (str.contains("String_Node_Str")) {
      count++;
      splitstr=splitstr.substring(splitstr.indexOf("String_Node_Str") + 3,splitstr.length());
    }
    if (str.indexOf("String_Node_Str") == 0) {
      TABLE_NAME=str.substring(1,str.length() - 1);
    }
 else     if (str.indexOf("String_Node_Str") == -1) {
      TABLE_NAME=tableName;
    }
 else {
      if (count == 2) {
        str=str.substring(str.indexOf("String_Node_Str") + 3,str.length());
      }
      position=str.indexOf("String_Node_Str");
      TABLE_SCHEMA=str.substring(0,position);
      TABLE_NAME=str.substring(position + 3,str.length());
    }
  }
  String synSQL="String_Node_Str" + TABLE_NAME + "String_Node_Str";
  if (null != TABLE_SCHEMA) {
    synSQL+="String_Node_Str" + TABLE_SCHEMA + "String_Node_Str";
  }
  if (!("String_Node_Str").equals(iMetadataConnection.getDatabase())) {
    synSQL+="String_Node_Str" + iMetadataConnection.getDatabase() + "String_Node_Str";
  }
  Statement sta=ExtractMetaDataUtils.conn.createStatement();
  ExtractMetaDataUtils.setQueryStatementTimeout(sta);
  ResultSet columns=sta.executeQuery(synSQL);
  String typeName=null;
  int index=0;
  while (columns.next()) {
    int column_size=0;
    String lenString=null;
    long numPrecRadix=0;
    String columnName=columns.getString(GetColumn.COLUMN_NAME.name());
    TdColumn column=ColumnHelper.createTdColumn(columnName);
    String label=column.getLabel();
    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);
      }
    }
    ICoreService coreService=CoreRuntimePlugin.getInstance().getCoreService();
    if (coreService.isKeyword(label) || coreService.isKeyword(sub) || coreService.isKeyword(sub2)) {
      label="String_Node_Str" + label;
    }
    label=MetadataToolHelper.validateColumnName(label,index);
    column.setLabel(label);
    column.setOriginalField(label2);
    if (!ExtractMetaDataUtils.needFakeDatabaseMetaData(iMetadataConnection.getDbType(),iMetadataConnection.isSqlMode())) {
      typeName=columns.getString(GetColumn.DATA_TYPE.name());
    }
    try {
      lenString="String_Node_Str";
      column_size=columns.getInt("String_Node_Str");
      if (columns.getString("String_Node_Str") != null) {
        column_size=columns.getInt("String_Node_Str");
        lenString="String_Node_Str";
      }
      column.setLength(column_size);
      numPrecRadix=columns.getLong("String_Node_Str");
      column.setPrecision(numPrecRadix);
    }
 catch (    Exception e1) {
      log.warn(e1,e1);
    }
    DatabaseConnection dbConnection=(DatabaseConnection)ConnectionHelper.getConnection(table);
    String dbmsId=dbConnection == null ? null : dbConnection.getDbmsId();
    if (dbmsId != null) {
      MappingTypeRetriever mappingTypeRetriever=MetadataTalendType.getMappingTypeRetriever(dbmsId);
      String talendType=mappingTypeRetriever.getDefaultSelectedTalendType(typeName,ExtractMetaDataUtils.getIntMetaDataInfo(columns,lenString),ExtractMetaDataUtils.getIntMetaDataInfo(columns,"String_Node_Str"));
      column.setTalendType(talendType);
      String defaultSelectedDbType=MetadataTalendType.getMappingTypeRetriever(dbConnection.getDbmsId()).getDefaultSelectedDbType(talendType);
      column.setSourceType(defaultSelectedDbType);
    }
    try {
      column.setNullable("String_Node_Str".equals(columns.getString("String_Node_Str")));
    }
 catch (    Exception e) {
      log.error(e);
    }
    metadataColumns.add(column);
    index++;
  }
  columns.close();
}