Program: 4694
Project: 4694
Buggy source:
/** 
 * Resolves the   {@link UserGroupInformation} for a given user, performing any keytab localization, if necessary.
 * @return a {@link UserGroupInformation}, based upon the information configured for a particular user
 * @throws IOException if there was any IOException during localization of the keytab
 */
@Override protected UGIWithPrincipal createUGI(ImpersonationRequest impersonationRequest) throws IOException {
  String configuredPrincipalShortName=new KerberosName(impersonationRequest.getPrincipal()).getShortName();
  if (UserGroupInformation.getCurrentUser().getShortUserName().equals(configuredPrincipalShortName)) {
    return new UGIWithPrincipal(impersonationRequest.getPrincipal(),UserGroupInformation.getCurrentUser());
  }
  URI keytabURI=URI.create(impersonationRequest.getKeytabURI());
  boolean isKeytabLocal=keytabURI.getScheme() == null || "String_Node_Str".equals(keytabURI.getScheme());
  File localKeytabFile=isKeytabLocal ? new File(keytabURI.getPath()) : localizeKeytab(locationFactory.create(keytabURI));
  try {
    String expandedPrincipal=SecurityUtil.expandPrincipal(impersonationRequest.getPrincipal());
    LOG.debug("String_Node_Str",expandedPrincipal,localKeytabFile);
    if (!Files.isReadable(localKeytabFile.toPath())) {
      throw new IOException(String.format("String_Node_Str",localKeytabFile));
    }
    UserGroupInformation loggedInUGI=UserGroupInformation.loginUserFromKeytabAndReturnUGI(expandedPrincipal,localKeytabFile.getAbsolutePath());
    return new UGIWithPrincipal(impersonationRequest.getPrincipal(),loggedInUGI);
  }
  finally {
    if (!isKeytabLocal && !localKeytabFile.delete()) {
      LOG.warn("String_Node_Str",localKeytabFile);
    }
  }
}

Fixed version (ground truth):
/** 
 * Resolves the   {@link UserGroupInformation} for a given user, performing any keytab localization, if necessary.
 * @return a {@link UserGroupInformation}, based upon the information configured for a particular user
 * @throws IOException if there was any IOException during localization of the keytab
 */
@Override protected UGIWithPrincipal createUGI(ImpersonationRequest impersonationRequest) throws IOException {
  String configuredPrincipalShortName=new KerberosName(impersonationRequest.getPrincipal()).getShortName();
  if (UserGroupInformation.getCurrentUser().getShortUserName().equals(configuredPrincipalShortName)) {
    return new UGIWithPrincipal(impersonationRequest.getPrincipal(),UserGroupInformation.getCurrentUser());
  }
  URI keytabURI=URI.create(impersonationRequest.getKeytabURI());
  boolean isKeytabLocal=keytabURI.getScheme() == null || "String_Node_Str".equals(keytabURI.getScheme());
  File localKeytabFile=isKeytabLocal ? new File(keytabURI.getPath()) : localizeKeytab(locationFactory.create(keytabURI));
  try {
    String expandedPrincipal=SecurityUtil.expandPrincipal(impersonationRequest.getPrincipal());
    LOG.debug("String_Node_Str",expandedPrincipal,localKeytabFile);
    if (!Files.isReadable(localKeytabFile.toPath())) {
      throw new IOException(String.format("String_Node_Str",localKeytabFile));
    }
    UserGroupInformation loggedInUGI;
    try {
      loggedInUGI=UserGroupInformation.loginUserFromKeytabAndReturnUGI(expandedPrincipal,localKeytabFile.getAbsolutePath());
    }
 catch (    Exception e) {
      throw new IOException(String.format("String_Node_Str" + "String_Node_Str",expandedPrincipal,keytabURI),e);
    }
    return new UGIWithPrincipal(impersonationRequest.getPrincipal(),loggedInUGI);
  }
  finally {
    if (!isKeytabLocal && !localKeytabFile.delete()) {
      LOG.warn("String_Node_Str",localKeytabFile);
    }
  }
}