Skip to content

Commit 22ebd4e

Browse files
committed
HADOOP-18074 - clean up of unnecessary null variable
1 parent 92bfea8 commit 22ebd4e

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/LdapGroupsMapping.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,7 @@ List<String> lookupGroup(SearchResult result, DirContext c,
512512
List<String> doGetGroups(String user, int goUpHierarchy)
513513
throws NamingException {
514514
DirContext c = getDirContext();
515+
List<String> groups = new ArrayList<>();
515516

516517
// Search for the user. We'll only ever need to look at the first result
517518
NamingEnumeration<SearchResult> results = c.search(userbaseDN,
@@ -520,11 +521,10 @@ List<String> doGetGroups(String user, int goUpHierarchy)
520521
if (!results.hasMoreElements()) {
521522
LOG.debug("doGetGroups({}) returned no groups because the " +
522523
"user is not found.", user);
523-
return new ArrayList<>();
524+
return groups;
524525
}
525526
SearchResult result = results.nextElement();
526527

527-
List<String> groups = null;
528528
if (useOneQuery) {
529529
try {
530530
/**
@@ -538,7 +538,6 @@ List<String> doGetGroups(String user, int goUpHierarchy)
538538
memberOfAttr + "' attribute." +
539539
"Returned user object: " + result.toString());
540540
}
541-
groups = new ArrayList<>();
542541
NamingEnumeration groupEnumeration = groupDNAttr.getAll();
543542
while (groupEnumeration.hasMore()) {
544543
String groupDN = groupEnumeration.next().toString();
@@ -547,14 +546,12 @@ List<String> doGetGroups(String user, int goUpHierarchy)
547546
} catch (NamingException e) {
548547
// If the first lookup failed, fall back to the typical scenario.
549548
// In order to force the fallback, we need to reset groups collection.
550-
if (groups != null) {
551-
groups.clear();
552-
}
549+
groups.clear();
553550
LOG.info("Failed to get groups from the first lookup. Initiating " +
554551
"the second LDAP query using the user's DN.", e);
555552
}
556553
}
557-
if (groups == null || groups.isEmpty() || goUpHierarchy > 0) {
554+
if (groups.isEmpty() || goUpHierarchy > 0) {
558555
groups = lookupGroup(result, c, goUpHierarchy);
559556
}
560557
LOG.debug("doGetGroups({}) returned {}", user, groups);

0 commit comments

Comments
 (0)