Program: 4764
Project: 4764
Buggy source:
/** 
 * Gets a Yarn delegation token and stores it in the given Credentials.
 * @return the same Credentials instance as the one given in parameter.
 */
public static Credentials obtainToken(YarnConfiguration configuration,Credentials credentials){
  if (!UserGroupInformation.isSecurityEnabled()) {
    return credentials;
  }
  try {
    YarnClient yarnClient=YarnClient.createYarnClient();
    yarnClient.init(configuration);
    yarnClient.start();
    try {
      Text renewer=new Text(UserGroupInformation.getCurrentUser().getShortUserName());
      org.apache.hadoop.yarn.api.records.Token rmDelegationToken=yarnClient.getRMDelegationToken(renewer);
      List<String> services=new ArrayList<>();
      if (HAUtil.isHAEnabled(configuration)) {
        YarnConfiguration yarnConf=new YarnConfiguration(configuration);
        for (        String rmId : HAUtil.getRMHAIds(configuration)) {
          yarnConf.set(YarnConfiguration.RM_HA_ID,rmId);
          InetSocketAddress address=yarnConf.getSocketAddr(YarnConfiguration.RM_ADDRESS,YarnConfiguration.DEFAULT_RM_ADDRESS,YarnConfiguration.DEFAULT_RM_PORT);
          services.add(SecurityUtil.buildTokenService(address).toString());
        }
      }
 else {
        services.add(SecurityUtil.buildTokenService(YarnUtils.getRMAddress(configuration)).toString());
      }
      Token<TokenIdentifier> token=ConverterUtils.convertFromYarn(rmDelegationToken,null);
      token.setService(new Text(Joiner.on(',').join(services)));
      credentials.addToken(new Text(token.getService()),token);
      LOG.debug("String_Node_Str",token);
    }
  finally {
      yarnClient.stop();
    }
    return credentials;
  }
 catch (  Exception e) {
    throw Throwables.propagate(e);
  }
}

Fixed version (ground truth):
/** 
 * Gets a Yarn delegation token and stores it in the given Credentials. Also gets Yarn App Timeline Server, if it is enabled.
 * @return the same Credentials instance as the one given in parameter.
 */
public static Credentials obtainToken(YarnConfiguration configuration,Credentials credentials){
  if (!UserGroupInformation.isSecurityEnabled()) {
    return credentials;
  }
  try {
    YarnClient yarnClient=YarnClient.createYarnClient();
    yarnClient.init(configuration);
    yarnClient.start();
    try {
      if (configuration.getBoolean(Constants.Explore.TIMELINE_SERVICE_ENABLED,false)) {
        Method method=yarnClient.getClass().getDeclaredMethod("String_Node_Str");
        method.setAccessible(true);
        Token<? extends TokenIdentifier> atsToken=(Token<? extends TokenIdentifier>)method.invoke(yarnClient);
        if (atsToken != null) {
          credentials.addToken(atsToken.getService(),atsToken);
          LOG.info("String_Node_Str",atsToken);
        }
      }
      Text renewer=new Text(UserGroupInformation.getCurrentUser().getShortUserName());
      org.apache.hadoop.yarn.api.records.Token rmDelegationToken=yarnClient.getRMDelegationToken(renewer);
      List<String> services=new ArrayList<>();
      if (HAUtil.isHAEnabled(configuration)) {
        YarnConfiguration yarnConf=new YarnConfiguration(configuration);
        for (        String rmId : HAUtil.getRMHAIds(configuration)) {
          yarnConf.set(YarnConfiguration.RM_HA_ID,rmId);
          InetSocketAddress address=yarnConf.getSocketAddr(YarnConfiguration.RM_ADDRESS,YarnConfiguration.DEFAULT_RM_ADDRESS,YarnConfiguration.DEFAULT_RM_PORT);
          services.add(SecurityUtil.buildTokenService(address).toString());
        }
      }
 else {
        services.add(SecurityUtil.buildTokenService(YarnUtils.getRMAddress(configuration)).toString());
      }
      Token<TokenIdentifier> token=ConverterUtils.convertFromYarn(rmDelegationToken,null);
      token.setService(new Text(Joiner.on(',').join(services)));
      credentials.addToken(new Text(token.getService()),token);
      LOG.debug("String_Node_Str",token);
    }
  finally {
      yarnClient.stop();
    }
    return credentials;
  }
 catch (  Exception e) {
    throw Throwables.propagate(e);
  }
}