From f7d5bace435a8de151b94ccc3599a6c4de8f7daf Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Wed, 11 Apr 2018 10:40:30 -0700 Subject: [PATCH] HDFS-13428. RBF: Remove LinkedList From StateStoreFileImpl.java. Contributed by BELUGA BEHR. --- .../store/driver/impl/StateStoreFileImpl.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/driver/impl/StateStoreFileImpl.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/driver/impl/StateStoreFileImpl.java index 7d9ddc64499..6b288b35558 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/driver/impl/StateStoreFileImpl.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/store/driver/impl/StateStoreFileImpl.java @@ -26,9 +26,11 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; -import java.util.LinkedList; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import org.apache.commons.lang.ArrayUtils; import org.apache.hadoop.hdfs.server.federation.router.RBFConfigKeys; import org.apache.hadoop.hdfs.server.federation.store.records.BaseRecord; import org.slf4j.Logger; @@ -134,15 +136,16 @@ public class StateStoreFileImpl extends StateStoreFileBaseImpl { @Override protected List getChildren(String path) { - List ret = new LinkedList<>(); File dir = new File(path); File[] files = dir.listFiles(); - if (files != null) { + if (ArrayUtils.isNotEmpty(files)) { + List ret = new ArrayList<>(files.length); for (File file : files) { String filename = file.getName(); ret.add(filename); } + return ret; } - return ret; + return Collections.emptyList(); } } \ No newline at end of file