Github user eribeiro commented on a diff in the pull request:

    https://github.com/apache/zookeeper/pull/279#discussion_r121280993
  
    --- Diff: 
src/java/main/org/apache/zookeeper/server/PrepRequestProcessor.java ---
    @@ -915,11 +915,13 @@ protected void pRequest(Request request) throws 
RequestProcessorException {
         private List<ACL> removeDuplicates(List<ACL> acl) {
     
             ArrayList<ACL> retval = new ArrayList<ACL>();
    -        Iterator<ACL> it = acl.iterator();
    -        while (it.hasNext()) {
    -            ACL a = it.next();
    -            if (retval.contains(a) == false) {
    -                retval.add(a);
    +        if(acl != null) {
    --- End diff --
    
    ```
       if (acl != null) {
           retval.addAll(acl);
       } 
    }
    return new List<>(retval);
    ```
    
    OR
    
    ```
        if (acl != null) {
            for (ACL a: acl) {
                 if (a != null) {
                    retval.add(a);
                 }
            }
        }
    }
    return new List<>(retval);
    ```
    
    Main difference between the two code snippets is that the latter accounts 
for null entries in the `acl` List. As you know, Lists accept null entries, but 
`Set` throws `NPE`. The original code doesn't prevent that, but this can never 
be the case (sending a null ACL entry in the List), so the former snippet is 
preferrable.
    



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to