Skip to content

Commit d357873

Browse files
authored
RANGER-5480: fix unit tests failure with error ConcurrentModificationException (apache#837)
1 parent 7a2d2da commit d357873

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

agents-common/src/main/java/org/apache/ranger/plugin/model/RangerBaseModelObject.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ public static void setNullSafeSupplier(String supplier) {
264264
}
265265
}
266266

267+
public static <T> List<T> copyOrEmpty(List<T> src) {
268+
return src == null ? new ArrayList<>() : new ArrayList<>(src);
269+
}
270+
267271
public abstract static class NullSafeSupplier {
268272
public abstract <T> List<T> toList(List<T> coll);
269273

agents-common/src/main/java/org/apache/ranger/plugin/model/RangerPolicy.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,13 @@ public RangerPolicyItem() {
921921
}
922922

923923
public RangerPolicyItem(RangerPolicyItem other) {
924-
this(other.accesses, other.users, other.groups, other.roles, other.conditions, other.delegateAdmin);
924+
this.accesses = copyOrEmpty(other.accesses);
925+
this.users = copyOrEmpty(other.users);
926+
this.groups = copyOrEmpty(other.groups);
927+
this.roles = copyOrEmpty(other.roles);
928+
this.conditions = copyOrEmpty(other.conditions);
929+
930+
setDelegateAdmin(other.delegateAdmin);
925931
}
926932

927933
public RangerPolicyItem(List<RangerPolicyItemAccess> accessTypes, List<String> users, List<String> groups, List<String> roles, List<RangerPolicyItemCondition> conditions, Boolean delegateAdmin) {

0 commit comments

Comments
 (0)