From 7be2c002b350594e9bfbd256c8abc2cad42d49ea Mon Sep 17 00:00:00 2001 From: Chris Nauroth Date: Wed, 26 Feb 2014 16:22:56 +0000 Subject: [PATCH] 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 --- hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ .../hadoop/hdfs/server/namenode/AclFeature.java | 14 +++++++------- .../hadoop/hdfs/server/namenode/AclStorage.java | 2 +- .../hadoop/hdfs/server/namenode/FSAclBaseTest.java | 7 +++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 52620bf7ef..ae8a2dbeac 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -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 diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclFeature.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclFeature.java index 1849c9f28d..1c5f469b3b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclFeature.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclFeature.java @@ -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 EMPTY_ENTRY_LIST = Collections.emptyList(); + public static final ImmutableList EMPTY_ENTRY_LIST = + ImmutableList.of(); - private final List entries; + private final ImmutableList entries; - public AclFeature(List entries) { + public AclFeature(ImmutableList entries) { this.entries = entries; } - public List getEntries() { + public ImmutableList getEntries() { return entries; } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclStorage.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclStorage.java index c40bd63732..a79bb393f9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclStorage.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/AclStorage.java @@ -328,7 +328,7 @@ private static AclFeature createAclFeature(List accessEntries, // Add all default entries to the feature. featureEntries.addAll(defaultEntries); - return new AclFeature(Collections.unmodifiableList(featureEntries)); + return new AclFeature(ImmutableList.copyOf(featureEntries)); } /** diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSAclBaseTest.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSAclBaseTest.java index 5b03c7df13..d3dc844d01 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSAclBaseTest.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/namenode/FSAclBaseTest.java @@ -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 entries = aclFeature.getEntries(); + assertNotNull(entries); + assertFalse(entries.isEmpty()); } else { assertNull(aclFeature); }