code: public static String getUser(String userName, UserGroupInformation ugi) {
          if (StringUtils.isNotEmpty(userName)) {
              if (LOG.isDebugEnabled()) {
                  LOG.debug("Returning userName {}", userName);
              }
              return userName;
          }
  
          if (ugi != null && StringUtils.isNotEmpty(ugi.getShortUserName())) {
              if (LOG.isDebugEnabled()) {
                  LOG.debug("Returning ugi.getShortUserName {}", userName);
              }
              return ugi.getShortUserName();
          }
  
          try {
              return UserGroupInformation.getCurrentUser().getShortUserName();
          } catch (IOException e) {
              LOG.warn("Failed for UserGroupInformation.getCurrentUser() ", e);
              return System.getProperty("user.name");
          }
      }
docs: Returns the user. Order of preference:
  1. Given userName
  2. ugi.getShortUserName()
  3. UserGroupInformation.getCurrentUser().getShortUserName()
  4. System.getProperty("user.name")