code: public static void setPermissions(Path location, Optional<String> owner, Optional<String> group, FileSystem fs,
        FsPermission permission) {
      try {
        if (!owner.isPresent()) {
          return;
        }
        if (!group.isPresent()) {
          return;
        }
        fs.setOwner(location, owner.get(), group.get());
        fs.setPermission(location, permission);
        if (!fs.isDirectory(location)) {
          return;
        }
        for (FileStatus fileStatus : fs.listStatus(location)) {
          setPermissions(fileStatus.getPath(), owner, group, fs, permission);
        }
      } catch (IOException e) {
        log.warn("Exception occurred while trying to change permissions : " + e.getMessage());
      }
    }
docs: Try to set owner and permissions for the path. Will not throw exception.