[
https://issues.apache.org/jira/browse/ZOOKEEPER-2804?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16045965#comment-16045965
]
ASF GitHub Bot commented on ZOOKEEPER-2804:
-------------------------------------------
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.
> Node creation fails with NPE if ACLs are null
> ---------------------------------------------
>
> Key: ZOOKEEPER-2804
> URL: https://issues.apache.org/jira/browse/ZOOKEEPER-2804
> Project: ZooKeeper
> Issue Type: Bug
> Reporter: Bhupendra Kumar Jain
>
> If null ACLs are passed then zk node creation or set ACL fails with NPE
> {code}
> java.lang.NullPointerException
> at
> org.apache.zookeeper.server.PrepRequestProcessor.removeDuplicates(PrepRequestProcessor.java:1301)
> at
> org.apache.zookeeper.server.PrepRequestProcessor.fixupACL(PrepRequestProcessor.java:1341)
> at
> org.apache.zookeeper.server.PrepRequestProcessor.pRequest2Txn(PrepRequestProcessor.java:519)
> at
> org.apache.zookeeper.server.PrepRequestProcessor.pRequest(PrepRequestProcessor.java:1126)
> at
> org.apache.zookeeper.server.PrepRequestProcessor.run(PrepRequestProcessor.java:178)
> {code}
> Expected to handle null in server and return proper error code to client
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)