Source:
private boolean grantPermission(String granter, String grantee, Path path, FileSystem.Permission permission) { FileSystem testFileSystem = fileSystems.getTestFileSystem(granter); FileSystem referenceFileSystem = fileSystems.getReferenceFileSystem(granter); Set<String> testExistingWriters = new TreeSet<>(testFileSystem.getSharees(path, FileSystem.Permission.WRITE)); Set<String> refExistingWriters = new TreeSet<>(referenceFileSystem.getSharees(path, FileSystem.Permission.WRITE)); if (! testExistingWriters.toString().equals(refExistingWriters.toString())) { throw new IllegalStateException("WRITE sharing mismatch. test:" + testExistingWriters + " ref:" + refExistingWriters); } if(testExistingWriters.contains(grantee)) { LOG.info("First revoke WRITE permission: user:" + granter + " grantee:" + grantee); revokePermission(granter, grantee, path, FileSystem.Permission.WRITE); } Set<String> testExistingReaders = new TreeSet<>(testFileSystem.getSharees(path, FileSystem.Permission.READ)); Set<String> refExistingReaders = new TreeSet<>(referenceFileSystem.getSharees(path, FileSystem.Permission.READ)); if (! testExistingReaders.toString().equals(refExistingReaders.toString())) { throw new IllegalStateException("READ sharing mismatch. test:" + testExistingReaders + " ref:" + refExistingReaders); } if(testExistingReaders.contains(grantee)) { LOG.info("First revoke READ permission: user:" + granter + " grantee:" + grantee); revokePermission(granter, grantee, path, FileSystem.Permission.READ); } testFileSystem.grant(path, grantee, permission); referenceFileSystem.grant(path, grantee, permission); return true; }

Target:
private boolean grantPermission(String granter, String grantee, Path path, FileSystem.Permission permission) { FileSystem testFileSystem = fileSystems.getTestFileSystem(granter); FileSystem referenceFileSystem = fileSystems.getReferenceFileSystem(granter); Set<String> testExistingWriters = new TreeSet<>(testFileSystem.getSharees(path, FileSystem.Permission.WRITE)); Set<String> refExistingWriters = new TreeSet<>(referenceFileSystem.getSharees(path, FileSystem.Permission.WRITE)); if (! testExistingWriters.toString().equals(refExistingWriters.toString())) { throw new IllegalStateException("WRITE sharing mismatch. test:" + testExistingWriters + " ref:" + refExistingWriters); } if(testExistingWriters.contains(grantee)) { LOG.info("First revoke WRITE permission: user:" + granter + " grantee:" + grantee); revokePermission(granter, grantee, path, FileSystem.Permission.WRITE); } Set<String> testExistingReaders = new TreeSet<>(testFileSystem.getSharees(path, FileSystem.Permission.READ)); Set<String> refExistingReaders = new TreeSet<>(referenceFileSystem.getSharees(path, FileSystem.Permission.READ)); if (! testExistingReaders.equals(refExistingReaders)) { throw new IllegalStateException("READ sharing mismatch. test:" + testExistingReaders + " ref:" + refExistingReaders); } if(testExistingReaders.contains(grantee)) { LOG.info("First revoke READ permission: user:" + granter + " grantee:" + grantee); revokePermission(granter, grantee, path, FileSystem.Permission.READ); } testFileSystem.grant(path, grantee, permission); referenceFileSystem.grant(path, grantee, permission); return true; }