Program: 124796
Project: 124796
Buggy source:
public static void setConnectionParameters(HadoopClusterConnectionItem connectionItem,DistributionBean distribution,String version,IRetrieveConfsService confsService) throws Exception {
  HadoopClusterConnection connection=(HadoopClusterConnection)connectionItem.getConnection();
  connection.setUseCustomConfs(confsService != null);
  final DistributionVersion distributionVersion=distribution.getVersion(version,true);
  connection.setDistribution(distribution.name);
  connection.setDfVersion(distributionVersion.version);
  boolean supportYARN=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop2();
  boolean supportMR1=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop1();
  connection.setUseYarn(supportYARN && !supportMR1);
  HCRepositoryUtil.fillDefaultValuesOfHadoopCluster(connection);
  if (confsService == null) {
    return;
  }
  String namenodeURI=null;
  String ns=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.DFS_NAMESERVICES.getName());
  if (StringUtils.isNotEmpty(ns)) {
    namenodeURI="String_Node_Str" + ns;
  }
 else {
    namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI_NEW.getName());
    if (StringUtils.isEmpty(namenodeURI)) {
      namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI.getName());
    }
  }
  if (namenodeURI != null) {
    connection.setNameNodeURI(namenodeURI);
  }
  String yarnHostName=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HOSTNAME.getName());
  if (StringUtils.isNotEmpty(yarnHostName)) {
    connection.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_YARN_HOSTNAME,yarnHostName);
  }
  String rmOrJt=null;
  if (supportYARN) {
    String useRmHa=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HA_ENABLED.getName());
    boolean isUseRmHa=Boolean.valueOf(useRmHa);
    if (isUseRmHa) {
      String rmIds=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HA_RM_IDS.getName());
      if (rmIds != null) {
        String[] rmIdsArray=rmIds.split("String_Node_Str");
        if (rmIdsArray.length > 0) {
          String rmId=rmIdsArray[0];
          String adminRmIdKey=String.format(EHadoopConfProperties.YARN_RESOURCEMANAGER_ADMIN_ADDRESS_RM_ID.getName(),rmId);
          rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),adminRmIdKey);
        }
      }
    }
 else {
      rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCE_MANAGER.getName());
    }
  }
 else {
    rmOrJt=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOB_TRACKER_URI.getName());
  }
  if (rmOrJt == null && yarnHostName != null) {
    rmOrJt=replaceHostName(connection.getJobTrackerURI(),yarnHostName);
  }
  connection.setJobTrackerURI(rmOrJt);
  String rms=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCEMANAGER_SCHEDULER.getName());
  if (rms == null && yarnHostName != null) {
    rms=replaceHostName(connection.getRmScheduler(),yarnHostName);
  }
  connection.setRmScheduler(rms);
  String jh=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  if (StringUtils.isEmpty(jh)) {
    jh=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  }
  if (StringUtils.isNotEmpty(jh)) {
    connection.setJobHistory(jh);
  }
  String sd=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  if (StringUtils.isEmpty(sd)) {
    sd=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  }
  if (StringUtils.isNotEmpty(sd)) {
    connection.setStagingDirectory(sd);
  }
  String at=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.AUTHENTICATION.getName());
  if (StringUtils.isNotEmpty(at)) {
    connection.setEnableKerberos("String_Node_Str".equals(at));
  }
  if (connection.isEnableKerberos()) {
    String nnp=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.KERBEROS_PRINCIPAL.getName());
    if (StringUtils.isNotEmpty(nnp)) {
      connection.setPrincipal(nnp);
    }
    String rmOrJtPrincipal=null;
    if (supportYARN) {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RM_PRINCIPAL.getName());
    }
 else {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JT_PRINCIPAL.getName());
    }
    if (rmOrJtPrincipal != null) {
      connection.setJtOrRmPrincipal(rmOrJtPrincipal);
    }
    String jhp=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JH_PRINCIPAL.getName());
    if (StringUtils.isNotEmpty(jhp)) {
      connection.setJobHistoryPrincipal(jhp);
    }
  }
}

Fixed version (ground truth):
public static void setConnectionParameters(HadoopClusterConnectionItem connectionItem,DistributionBean distribution,String version,IRetrieveConfsService confsService) throws Exception {
  HadoopClusterConnection connection=(HadoopClusterConnection)connectionItem.getConnection();
  connection.setUseCustomConfs(confsService != null);
  final DistributionVersion distributionVersion=distribution.getVersion(version,true);
  connection.setDistribution(distribution.name);
  connection.setDfVersion(distributionVersion.version);
  boolean supportYARN=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop2();
  boolean supportMR1=distributionVersion.hadoopComponent != null && distributionVersion.hadoopComponent.isHadoop1();
  connection.setUseYarn(supportYARN && !supportMR1);
  HCRepositoryUtil.fillDefaultValuesOfHadoopCluster(connection);
  if (confsService == null) {
    return;
  }
  String namenodeURI=null;
  String ns=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.DFS_NAMESERVICES.getName());
  if (StringUtils.isNotEmpty(ns)) {
    namenodeURI="String_Node_Str" + ns;
  }
 else {
    namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI_NEW.getName());
    if (StringUtils.isEmpty(namenodeURI)) {
      namenodeURI=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.FS_DEFAULT_URI.getName());
    }
  }
  if (namenodeURI != null) {
    connection.setNameNodeURI(namenodeURI);
  }
  String yarnHostName=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HOSTNAME.getName());
  if (StringUtils.isNotEmpty(yarnHostName)) {
    connection.getParameters().put(ConnParameterKeys.CONN_PARA_KEY_YARN_HOSTNAME,yarnHostName);
  }
  String rmOrJt=null;
  if (supportYARN) {
    String useRmHa=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.YARN_RESOURCEMANAGER_HA_ENABLED.getName());
    boolean isUseRmHa=Boolean.valueOf(useRmHa);
    if (isUseRmHa) {
      String adminRmIdKey=getAdminRmIdKey(confsService,EHadoopConfProperties.YARN_RESOURCEMANAGER_ADMIN_ADDRESS_RM_ID.getName());
      if (StringUtils.isNotEmpty(adminRmIdKey)) {
        rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),adminRmIdKey);
      }
    }
 else {
      rmOrJt=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCE_MANAGER.getName());
    }
  }
 else {
    rmOrJt=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOB_TRACKER_URI.getName());
  }
  if (rmOrJt == null && yarnHostName != null) {
    rmOrJt=replaceHostName(connection.getJobTrackerURI(),yarnHostName);
  }
  connection.setJobTrackerURI(rmOrJt);
  String rms=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RESOURCEMANAGER_SCHEDULER.getName());
  if (rms == null) {
    String adminRmIdKey=getAdminRmIdKey(confsService,EHadoopConfProperties.RESOURCEMANAGER_SCHEDULER_ADDRESS_RM_ID.getName());
    if (StringUtils.isNotEmpty(adminRmIdKey)) {
      rms=confsService.getConfValue(EHadoopConfs.YARN.getName(),adminRmIdKey);
    }
    if (yarnHostName != null) {
      rms=replaceHostName(connection.getRmScheduler(),yarnHostName);
    }
  }
  connection.setRmScheduler(rms);
  String jh=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  if (StringUtils.isEmpty(jh)) {
    jh=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.JOBHISTORY.getName());
  }
  if (StringUtils.isNotEmpty(jh)) {
    connection.setJobHistory(jh);
  }
  String sd=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  if (StringUtils.isEmpty(sd)) {
    sd=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.STAGING_DIR.getName());
  }
  if (StringUtils.isNotEmpty(sd)) {
    connection.setStagingDirectory(sd);
  }
  String at=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.AUTHENTICATION.getName());
  if (StringUtils.isNotEmpty(at)) {
    connection.setEnableKerberos("String_Node_Str".equals(at));
  }
  if (connection.isEnableKerberos()) {
    String nnp=confsService.getConfValue(EHadoopConfs.HDFS.getName(),EHadoopConfProperties.KERBEROS_PRINCIPAL.getName());
    if (StringUtils.isNotEmpty(nnp)) {
      connection.setPrincipal(nnp);
    }
    String rmOrJtPrincipal=null;
    if (supportYARN) {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.YARN.getName(),EHadoopConfProperties.RM_PRINCIPAL.getName());
    }
 else {
      rmOrJtPrincipal=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JT_PRINCIPAL.getName());
    }
    if (rmOrJtPrincipal != null) {
      connection.setJtOrRmPrincipal(rmOrJtPrincipal);
    }
    String jhp=confsService.getConfValue(EHadoopConfs.MAPREDUCE2.getName(),EHadoopConfProperties.JH_PRINCIPAL.getName());
    if (StringUtils.isNotEmpty(jhp)) {
      connection.setJobHistoryPrincipal(jhp);
    }
  }
}