From 07b503504a5935154dbca0d2c3a67cbd9750804b Mon Sep 17 00:00:00 2001 From: Colin McDonald Date: Sat, 16 Jul 2016 14:39:50 -0400 Subject: [PATCH] Reset copiedRanks at the end of each iteration in User#getRanksScoped. This is a fix for an issue where the Iterator#remove call used here would fail if there was more than one other conflicting grants. We change this method to use a Set#remove to prevent the issues caused by trying to call Iterator#remove() multiple times and throwing an IllegalStateException. --- src/main/java/net/frozenorb/apiv3/model/User.java | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/frozenorb/apiv3/model/User.java b/src/main/java/net/frozenorb/apiv3/model/User.java index 88612cd..0b7dd5f 100644 --- a/src/main/java/net/frozenorb/apiv3/model/User.java +++ b/src/main/java/net/frozenorb/apiv3/model/User.java @@ -611,17 +611,12 @@ public final class User { return ImmutableList.of(Rank.findById("default")); } - Iterator iterator = grantedRanks.iterator(); - Set copiedRanks = ImmutableSet.copyOf(grantedRanks); - // This is to remove redundant ranks. Say they have mod, mod-plus, admin, and youtuber, // we should remove mod and mod-plus as it'll be made redundant by the higher ranked admin. - while (iterator.hasNext()) { - Rank rank = iterator.next(); - + for (Rank grantedRank : ImmutableSet.copyOf(grantedRanks)) { // Check all other ranks for inherited collision - for (Rank otherRank : copiedRanks) { - if (otherRank == rank) { + for (Rank otherRank : ImmutableSet.copyOf(grantedRanks)) { + if (grantedRank == otherRank) { continue; } @@ -629,8 +624,8 @@ public final class User { // Iterate up the inheritance tree to detect rank redundancies. while (parent.getInheritsFromId() != null) { - if (parent == rank) { - iterator.remove(); + if (parent == grantedRank) { + grantedRanks.remove(grantedRank); } parent = Rank.findById(parent.getInheritsFromId());