@@ -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