Program: 125821
Project: 125821
Buggy source:
/** 
 * ggu Comment method "cloneOriginalValueConnection". only clone the properties of connection.
 * @param selectedContext
 */
public static DatabaseConnection cloneOriginalValueConnection(DatabaseConnection dbConn,boolean defaultContext,String selectedContext){
  if (dbConn == null) {
    return null;
  }
  ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(null,dbConn,selectedContext,defaultContext);
  DatabaseConnection cloneConn=ConnectionFactory.eINSTANCE.createDatabaseConnection();
  String server=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getServerName());
  String username=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getUsername());
  String password=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getRawPassword());
  String port=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getPort());
  String sidOrDatabase=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getSID());
  String datasource=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDatasourceName());
  String filePath=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getFileFieldName());
  String schemaOracle=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getUiSchema());
  String dbRootPath=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDBRootPath());
  String additionParam=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getAdditionalParams());
  String url=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getURL());
  String className=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDriverClass());
  String jarPath=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDriverJarPath());
  String dbmsID=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDbmsId());
  filePath=TalendQuoteUtils.removeQuotes(filePath);
  dbRootPath=TalendQuoteUtils.removeQuotes(dbRootPath);
  cloneConn.setAdditionalParams(additionParam);
  cloneConn.setDatasourceName(datasource);
  cloneConn.setDBRootPath(dbRootPath);
  cloneConn.setFileFieldName(filePath);
  cloneConn.setRawPassword(password);
  cloneConn.setPort(port);
  cloneConn.setUiSchema(schemaOracle);
  cloneConn.setServerName(server);
  cloneConn.setSID(sidOrDatabase);
  cloneConn.setUsername(username);
  cloneConn.setDriverJarPath(jarPath);
  cloneConn.setComment(dbConn.getComment());
  cloneConn.setDatabaseType(dbConn.getDatabaseType());
  cloneConn.setDbmsId(dbmsID);
  cloneConn.setDivergency(dbConn.isDivergency());
  cloneConn.setDbVersionString(dbConn.getDbVersionString());
  cloneConn.setId(dbConn.getId());
  cloneConn.setLabel(dbConn.getLabel());
  cloneConn.setNullChar(dbConn.getNullChar());
  cloneConn.setProductId(dbConn.getProductId());
  cloneConn.setSqlSynthax(dbConn.getSqlSynthax());
  cloneConn.setStandardSQL(dbConn.isStandardSQL());
  cloneConn.setStringQuote(dbConn.getStringQuote());
  cloneConn.setSynchronised(dbConn.isSynchronised());
  cloneConn.setSystemSQL(dbConn.isSystemSQL());
  cloneConn.setVersion(dbConn.getVersion());
  cloneConn.setReadOnly(dbConn.isReadOnly());
  cloneConn.setDriverClass(className);
  cloneConn.setName(dbConn.getName());
  cloneOtherParameters(dbConn,cloneConn);
  if (dbConn.isSetSQLMode()) {
    cloneConn.setSQLMode(dbConn.isSQLMode());
  }
 else {
    cloneConn.setSQLMode(true);
  }
  if (EDatabaseTypeName.HIVE.equals(EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType()))) {
    String hadoopUserName=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_USERNAME);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_USERNAME,ContextParameterUtils.getOriginalValue(contextType,hadoopUserName));
    String jobTracker=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL,ContextParameterUtils.getOriginalValue(contextType,jobTracker));
    String nameNode=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL,ContextParameterUtils.getOriginalValue(contextType,nameNode));
    String hivePrincipal=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_HIVEPRINCIPLA);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_HIVEPRINCIPLA,ContextParameterUtils.getOriginalValue(contextType,hivePrincipal));
    String hiveMetadata=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_METASTOREURL);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_METASTOREURL,ContextParameterUtils.getOriginalValue(contextType,hiveMetadata));
    String driverPath=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERJAR_PATH);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERJAR_PATH,ContextParameterUtils.getOriginalValue(contextType,driverPath));
    String driverClass=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERCLASS);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERCLASS,ContextParameterUtils.getOriginalValue(contextType,driverClass));
    String hiveUserName=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_USERNAME);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_USERNAME,ContextParameterUtils.getOriginalValue(contextType,hiveUserName));
    String hivePassword=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_PASSWORD);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_PASSWORD,ContextParameterUtils.getOriginalValue(contextType,hivePassword));
    String ktPrincipal=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,ktPrincipal));
    String keytab=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB,ContextParameterUtils.getOriginalValue(contextType,keytab));
    String template=null;
    String hiveServerVersion=HiveServerVersionInfo.HIVE_SERVER_1.getKey();
    EMap<String,String> parameterMap=dbConn.getParameters();
    if (parameterMap != null) {
      hiveServerVersion=parameterMap.get(ConnParameterKeys.HIVE_SERVER_VERSION);
    }
    if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
      template=DbConnStrForHive.URL_HIVE_2_TEMPLATE;
    }
 else {
      template=DbConnStrForHive.URL_HIVE_1_TEMPLATE;
    }
    String newURl=DatabaseConnStrUtil.getHiveURLString(cloneConn,server,port,sidOrDatabase,template);
    cloneConn.setURL(newURl);
    return cloneConn;
  }
  if (EDatabaseTypeName.HBASE.equals(EDatabaseTypeName.getTypeFromDbType(cloneConn.getDatabaseType()))) {
    String hbaseMasterPrin=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_MASTERPRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_MASTERPRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,hbaseMasterPrin));
    String hbaseRegionPrin=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_REGIONSERVERPRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_REGIONSERVERPRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,hbaseRegionPrin));
    String hbaseKeyTabPrin=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,hbaseKeyTabPrin));
    String hbaseKeyTab=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB,ContextParameterUtils.getOriginalValue(contextType,hbaseKeyTab));
  }
  if (EDatabaseTypeName.IBMDB2.equals(EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType()))) {
    String cursorForDb2="String_Node_Str";
    String database=sidOrDatabase + cursorForDb2;
    String newURL=DatabaseConnStrUtil.getURLString(cloneConn.getDatabaseType(),dbConn.getDbVersionString(),server,username,password,port,database,filePath.toLowerCase(),datasource,dbRootPath,additionParam);
    cloneConn.setURL(newURL);
    return cloneConn;
  }
  if (contextType != null && !EDatabaseTypeName.GENERAL_JDBC.equals(EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType()))) {
    String newURL=DatabaseConnStrUtil.getURLString(cloneConn.getDatabaseType(),dbConn.getDbVersionString(),server,username,password,port,sidOrDatabase,filePath.toLowerCase(),datasource,dbRootPath,additionParam);
    cloneConn.setURL(newURL);
    return cloneConn;
  }
  if (dbConn.getURL() != null && !dbConn.getURL().equals("String_Node_Str")) {
    cloneConn.setURL(url);
  }
 else {
    String newURL=DatabaseConnStrUtil.getURLString(cloneConn.getDatabaseType(),dbConn.getDbVersionString(),server,username,password,port,sidOrDatabase,filePath.toLowerCase(),datasource,dbRootPath,additionParam);
    cloneConn.setURL(newURL);
  }
  return cloneConn;
}

Fixed version (ground truth):
/** 
 * ggu Comment method "cloneOriginalValueConnection". only clone the properties of connection.
 * @param selectedContext
 */
public static DatabaseConnection cloneOriginalValueConnection(DatabaseConnection dbConn,boolean defaultContext,String selectedContext){
  if (dbConn == null) {
    return null;
  }
  ContextType contextType=ConnectionContextHelper.getContextTypeForContextMode(null,dbConn,selectedContext,defaultContext);
  DatabaseConnection cloneConn=ConnectionFactory.eINSTANCE.createDatabaseConnection();
  String server=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getServerName());
  String username=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getUsername());
  String password=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getRawPassword());
  String port=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getPort());
  String sidOrDatabase=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getSID());
  String datasource=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDatasourceName());
  String filePath=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getFileFieldName());
  String schemaOracle=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getUiSchema());
  String dbRootPath=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDBRootPath());
  String additionParam=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getAdditionalParams());
  String url=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getURL());
  String className=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDriverClass());
  String jarPath=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDriverJarPath());
  String dbmsID=ConnectionContextHelper.getOriginalValue(contextType,dbConn.getDbmsId());
  filePath=TalendQuoteUtils.removeQuotes(filePath);
  dbRootPath=TalendQuoteUtils.removeQuotes(dbRootPath);
  cloneConn.setAdditionalParams(additionParam);
  cloneConn.setDatasourceName(datasource);
  cloneConn.setDBRootPath(dbRootPath);
  cloneConn.setFileFieldName(filePath);
  cloneConn.setRawPassword(password);
  cloneConn.setPort(port);
  cloneConn.setUiSchema(schemaOracle);
  cloneConn.setServerName(server);
  cloneConn.setSID(sidOrDatabase);
  cloneConn.setUsername(username);
  cloneConn.setDriverJarPath(jarPath);
  cloneConn.setComment(dbConn.getComment());
  cloneConn.setDatabaseType(dbConn.getDatabaseType());
  cloneConn.setDbmsId(dbmsID);
  cloneConn.setDivergency(dbConn.isDivergency());
  cloneConn.setDbVersionString(dbConn.getDbVersionString());
  cloneConn.setId(dbConn.getId());
  cloneConn.setLabel(dbConn.getLabel());
  cloneConn.setNullChar(dbConn.getNullChar());
  cloneConn.setProductId(dbConn.getProductId());
  cloneConn.setSqlSynthax(dbConn.getSqlSynthax());
  cloneConn.setStandardSQL(dbConn.isStandardSQL());
  cloneConn.setStringQuote(dbConn.getStringQuote());
  cloneConn.setSynchronised(dbConn.isSynchronised());
  cloneConn.setSystemSQL(dbConn.isSystemSQL());
  cloneConn.setVersion(dbConn.getVersion());
  cloneConn.setReadOnly(dbConn.isReadOnly());
  cloneConn.setDriverClass(className);
  cloneConn.setName(dbConn.getName());
  cloneOtherParameters(dbConn,cloneConn);
  if (dbConn.isSetSQLMode()) {
    cloneConn.setSQLMode(dbConn.isSQLMode());
  }
 else {
    cloneConn.setSQLMode(true);
  }
  if (EDatabaseTypeName.HIVE.equals(EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType()))) {
    String hadoopUserName=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_USERNAME);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_USERNAME,ContextParameterUtils.getOriginalValue(contextType,hadoopUserName));
    String jobTracker=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_JOB_TRACKER_URL,ContextParameterUtils.getOriginalValue(contextType,jobTracker));
    String nameNode=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_NAME_NODE_URL,ContextParameterUtils.getOriginalValue(contextType,nameNode));
    String hivePrincipal=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_HIVEPRINCIPLA);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_HIVEPRINCIPLA,ContextParameterUtils.getOriginalValue(contextType,hivePrincipal));
    String hiveMetadata=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_METASTOREURL);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_METASTOREURL,ContextParameterUtils.getOriginalValue(contextType,hiveMetadata));
    String driverPath=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERJAR_PATH);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERJAR_PATH,ContextParameterUtils.getOriginalValue(contextType,driverPath));
    String driverClass=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERCLASS);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_DRIVERCLASS,ContextParameterUtils.getOriginalValue(contextType,driverClass));
    String hiveUserName=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_USERNAME);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_USERNAME,ContextParameterUtils.getOriginalValue(contextType,hiveUserName));
    String hivePassword=cloneConn.getParameters().get(ConnParameterKeys.HIVE_AUTHENTICATION_PASSWORD);
    cloneConn.getParameters().put(ConnParameterKeys.HIVE_AUTHENTICATION_PASSWORD,ContextParameterUtils.getOriginalValue(contextType,hivePassword));
    String ktPrincipal=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,ktPrincipal));
    String keytab=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB,ContextParameterUtils.getOriginalValue(contextType,keytab));
    String jdbcPropertiesString=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HIVE_JDBC_PROPERTIES);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HIVE_JDBC_PROPERTIES,HadoopRepositoryUtil.getOriginalValueOfProperties(contextType,jdbcPropertiesString));
    String propertiesString=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HIVE_PROPERTIES);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HIVE_PROPERTIES,HadoopRepositoryUtil.getOriginalValueOfProperties(contextType,propertiesString));
    String template=null;
    String hiveServerVersion=HiveServerVersionInfo.HIVE_SERVER_1.getKey();
    EMap<String,String> parameterMap=dbConn.getParameters();
    if (parameterMap != null) {
      hiveServerVersion=parameterMap.get(ConnParameterKeys.HIVE_SERVER_VERSION);
    }
    if (HiveServerVersionInfo.HIVE_SERVER_2.getKey().equals(hiveServerVersion)) {
      template=DbConnStrForHive.URL_HIVE_2_TEMPLATE;
    }
 else {
      template=DbConnStrForHive.URL_HIVE_1_TEMPLATE;
    }
    String newURl=DatabaseConnStrUtil.getHiveURLString(cloneConn,server,port,sidOrDatabase,template);
    cloneConn.setURL(newURl);
    return cloneConn;
  }
  if (EDatabaseTypeName.HBASE.equals(EDatabaseTypeName.getTypeFromDbType(cloneConn.getDatabaseType()))) {
    String hbaseMasterPrin=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_MASTERPRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_MASTERPRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,hbaseMasterPrin));
    String hbaseRegionPrin=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_REGIONSERVERPRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_HBASE_AUTHENTICATION_REGIONSERVERPRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,hbaseRegionPrin));
    String hbaseKeyTabPrin=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB_PRINCIPAL,ContextParameterUtils.getOriginalValue(contextType,hbaseKeyTabPrin));
    String hbaseKeyTab=cloneConn.getParameters().get(ConnParameterKeys.CONN_PARA_KEY_KEYTAB);
    cloneConn.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_KEYTAB,ContextParameterUtils.getOriginalValue(contextType,hbaseKeyTab));
  }
  if (EDatabaseTypeName.IBMDB2.equals(EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType()))) {
    String cursorForDb2="String_Node_Str";
    String database=sidOrDatabase + cursorForDb2;
    String newURL=DatabaseConnStrUtil.getURLString(cloneConn.getDatabaseType(),dbConn.getDbVersionString(),server,username,password,port,database,filePath.toLowerCase(),datasource,dbRootPath,additionParam);
    cloneConn.setURL(newURL);
    return cloneConn;
  }
  if (contextType != null && !EDatabaseTypeName.GENERAL_JDBC.equals(EDatabaseTypeName.getTypeFromDbType(dbConn.getDatabaseType()))) {
    String newURL=DatabaseConnStrUtil.getURLString(cloneConn.getDatabaseType(),dbConn.getDbVersionString(),server,username,password,port,sidOrDatabase,filePath.toLowerCase(),datasource,dbRootPath,additionParam);
    cloneConn.setURL(newURL);
    return cloneConn;
  }
  if (dbConn.getURL() != null && !dbConn.getURL().equals("String_Node_Str")) {
    cloneConn.setURL(url);
  }
 else {
    String newURL=DatabaseConnStrUtil.getURLString(cloneConn.getDatabaseType(),dbConn.getDbVersionString(),server,username,password,port,sidOrDatabase,filePath.toLowerCase(),datasource,dbRootPath,additionParam);
    cloneConn.setURL(newURL);
  }
  return cloneConn;
}