For a bukkit plugin i am coding i need to get all of a players permissions from a file, i dont want the permissions that start with "-" because those are called in another method (Perms to be removed from player) but i am getting a ConcurrentModificationException exception at for(String perms : s){
public static List<String> getPerms(Player player){
File f = new File(ServerCore.getPlugin().getDataFolder(), "permissions.yml");
FileConfiguration rankData = YamlConfiguration.loadConfiguration(f);
List<String> s = rankData.getStringList("Permissions.ranks."+ getPlayerRank(player) + ".permissions");
for(String ss : getInheritance(player)){
try{
List<String> sss = rankData.getStringList("Permissions.ranks." + ss + ".permissions");
s.addAll(sss);
}catch(Exception e){
e.printStackTrace();
}
}
List<String> results = s;
for(String perms : s){
if(!perms.startsWith("-")){
results.add(perms);
}
}
return results;
}
List<String> results = s;
The List "s" over which you are iterating is the same List as "results", into which you are adding elements. Modifying a collection with a fail-fast iterator (most non-concurrent collections) while iterating over it will throw that exception.
From context, I assume what you actually wanted was something like
List<String> results = new ArrayList();