Handle removal during iteration

Previously this threw UnsupportedOperationException due to
findGrantsForGrantee returning an immutable view.
This commit is contained in:
Andrew Gaul 2015-02-06 14:24:11 -08:00
parent 3e8413335d
commit eacfc8fdf1
1 changed files with 5 additions and 4 deletions

View File

@ -19,6 +19,7 @@ package org.jclouds.s3.domain;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
@ -105,10 +106,10 @@ public class AccessControlList {
* @param permission
*/
public AccessControlList revokePermission(Grantee grantee, String permission) {
Collection<Grant> grantsForGrantee = findGrantsForGrantee(grantee.getIdentifier());
for (Grant grant : grantsForGrantee) {
if (grant.getPermission().equals(permission)) {
grants.remove(grant);
for (Iterator<Grant> it = grants.iterator(); it.hasNext();) {
Grant grant = it.next();
if (grant.getGrantee().equals(grantee) && grant.getPermission().equals(permission)) {
it.remove();
}
}
return this;