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.
(cnauroth)
HDFS-5908. Change AclFeature to capture list of ACL entries in an
ImmutableList. (cnauroth)
Release 2.5.0 - UNRELEASED
INCOMPATIBLE CHANGES

View File

@ -18,26 +18,26 @@
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.fs.permission.AclEntry;
import com.google.common.collect.ImmutableList;
/**
* Feature that represents the ACLs of the inode.
*/
@InterfaceAudience.Private
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;
}
public List<AclEntry> getEntries() {
public ImmutableList<AclEntry> getEntries() {
return entries;
}
}

View File

@ -328,7 +328,7 @@ private static AclFeature createAclFeature(List<AclEntry> accessEntries,
// Add all default entries to the feature.
featureEntries.addAll(defaultEntries);
return new AclFeature(Collections.unmodifiableList(featureEntries));
return new AclFeature(ImmutableList.copyOf(featureEntries));
}
/**

View File

@ -48,6 +48,7 @@
import org.junit.Test;
import org.junit.rules.ExpectedException;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
/**
@ -1272,6 +1273,12 @@ private static void assertAclFeature(Path pathToCheck,
AclFeature aclFeature = inode.getAclFeature();
if (expectAclFeature) {
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 {
assertNull(aclFeature);
}