HDFS-5908. Change AclFeature to capture list of ACL entries in an ImmutableList. Contributed by Chris Nauroth.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1572142 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Chris Nauroth 2014-02-26 16:22:56 +00:00
parent c7142e7761
commit 7be2c002b3
4 changed files with 18 additions and 8 deletions

View File

@ -336,6 +336,9 @@ Trunk (Unreleased)
checks are disabled, user is superuser or user is member of supergroup. checks are disabled, user is superuser or user is member of supergroup.
(cnauroth) (cnauroth)
HDFS-5908. Change AclFeature to capture list of ACL entries in an
ImmutableList. (cnauroth)
Release 2.5.0 - UNRELEASED Release 2.5.0 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -18,26 +18,26 @@
package org.apache.hadoop.hdfs.server.namenode; package org.apache.hadoop.hdfs.server.namenode;
import java.util.Collections;
import java.util.List;
import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceAudience;
import org.apache.hadoop.fs.permission.AclEntry; import org.apache.hadoop.fs.permission.AclEntry;
import com.google.common.collect.ImmutableList;
/** /**
* Feature that represents the ACLs of the inode. * Feature that represents the ACLs of the inode.
*/ */
@InterfaceAudience.Private @InterfaceAudience.Private
public class AclFeature implements INode.Feature { public class AclFeature implements INode.Feature {
public static final List<AclEntry> EMPTY_ENTRY_LIST = Collections.emptyList(); public static final ImmutableList<AclEntry> EMPTY_ENTRY_LIST =
ImmutableList.of();
private final List<AclEntry> entries; private final ImmutableList<AclEntry> entries;
public AclFeature(List<AclEntry> entries) { public AclFeature(ImmutableList<AclEntry> entries) {
this.entries = entries; this.entries = entries;
} }
public List<AclEntry> getEntries() { public ImmutableList<AclEntry> getEntries() {
return entries; return entries;
} }
} }

View File

@ -328,7 +328,7 @@ final class AclStorage {
// Add all default entries to the feature. // Add all default entries to the feature.
featureEntries.addAll(defaultEntries); featureEntries.addAll(defaultEntries);
return new AclFeature(Collections.unmodifiableList(featureEntries)); return new AclFeature(ImmutableList.copyOf(featureEntries));
} }
/** /**

View File

@ -48,6 +48,7 @@ import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.junit.rules.ExpectedException;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
/** /**
@ -1272,6 +1273,12 @@ public abstract class FSAclBaseTest {
AclFeature aclFeature = inode.getAclFeature(); AclFeature aclFeature = inode.getAclFeature();
if (expectAclFeature) { if (expectAclFeature) {
assertNotNull(aclFeature); assertNotNull(aclFeature);
// Intentionally capturing a reference to the entries, not using nested
// calls. This way, we get compile-time enforcement that the entries are
// stored in an ImmutableList.
ImmutableList<AclEntry> entries = aclFeature.getEntries();
assertNotNull(entries);
assertFalse(entries.isEmpty());
} else { } else {
assertNull(aclFeature); assertNull(aclFeature);
} }