code: public void setOwner(String src, String username, String group
    ) throws IOException {
      INode[] inodes = null;
      writeLock();
      try {
        if (isInSafeMode()) {
          throw new SafeModeException("Cannot set permission for " + src, safeMode);
        }
        inodes = dir.getExistingPathINodes(src);
        if (isPermissionCheckingEnabled(inodes)) {
          FSPermissionChecker pc = checkOwner(src, inodes);
          if (!pc.isSuper) {
            if (username != null && !pc.user.equals(username)) {
              if (this.permissionAuditOnly) {
                // do not throw the exception, we would like to only log.
                LOG.warn("PermissionAudit failed on " + src + 
                    ": non-super user cannot change owner.");
              } else {
                throw new AccessControlException("Non-super user cannot change owner.");
              }
            }
            if (group != null && !pc.containsGroup(group)) {
              if (this.permissionAuditOnly) {
                // do not throw the exception, we would like to only log.
                LOG.warn("PermissionAudit failed on " + src + 
                    ": user does not belong to " + group + " .");
              } else {
                throw new AccessControlException("User does not belong to " + group
                    + " .");
              }
            }
          }
        }
        dir.setOwner(src, username, group);
      } finally {
        writeUnlock();
      }
      getEditLog().logSync(false);
      if (auditLog.isInfoEnabled()) {
        logAuditEvent(getCurrentUGI(),
          Server.getRemoteIp(),
          "setOwner", src, null, getLastINode(inodes));
      }
    }
docs: Set owner for an existing file.
  
  @throws IOException