[GitHub] [hadoop] goiri commented on a change in pull request #1974: HADOOP-17009: Embrace Immutability of Java Collections

2020-04-25 Thread GitBox


goiri commented on a change in pull request #1974:
URL: https://github.com/apache/hadoop/pull/1974#discussion_r415103835



##
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/net/NetworkTopology.java
##
@@ -196,10 +196,8 @@ protected Node getNodeForNetworkLocation(Node node) {
 loc = loc.substring(1);
   }
   InnerNode rack = (InnerNode) clusterMap.getLoc(loc);
-  if (rack == null) {
-return null;
-  }
-  return new ArrayList(rack.getChildren());
+  return (rack == null) ? Collections.emptyList()

Review comment:
   Why can we use unmodifiable here?





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org



[GitHub] [hadoop] goiri commented on a change in pull request #1974: HADOOP-17009: Embrace Immutability of Java Collections

2020-04-23 Thread GitBox


goiri commented on a change in pull request #1974:
URL: https://github.com/apache/hadoop/pull/1974#discussion_r414009203



##
File path: 
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/CompositeGroupsMapping.java
##
@@ -78,15 +79,13 @@
 user, provider.getClass().getSimpleName(), e.toString());
 LOG.debug("Stacktrace: ", e);
   }
-  if (groups != null && ! groups.isEmpty()) {
+  if (!groups.isEmpty()) {
 groupSet.addAll(groups);
 if (!combined) break;
   }
 }
 
-List results = new ArrayList(groupSet.size());
-results.addAll(groupSet);
-return results;
+return Collections.unmodifiableList(new ArrayList<>(groupSet));

Review comment:
   Now, somebody calling getGroups() would start failing if it was adding 
new things to the list while that was not the case before. I've tried using 
inmodifiable before but is kind of dangerous.





This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



-
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org