Strange ConcurrentModificationException

Discussion in 'Plugin Development' started by iZanax, Feb 1, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    iZanax

    I've Issues with ConcurrentModificationException, I run this code onEnable(), and sometimes it will give this Error and sometimes not. I've tried several methods to fix this, like Set<String> ips = getServer().getIPBans() or a Iterator (iterator.hasnext , next)
    But both are giving the same error, The strange thing is this happens like half the time, So I have totally no clue what It can be : (

    PHP:
    for(String ip getServer().getIPBans()) {
        
    getServer().unbanIP(ip);
    }
    * My guess is that onEnable() + IPBans are a bad combination, but how this can be fixed : (?
    * Delayed it with 5 seconds, still half of the times this problem, have no clue now.

    Thanks in Advance!
    Zanax
     
  2. Offline

    RealDope

    You can't edit the list while looping through the list. Add them to another list and then remove afterwards.

    Code:JAVA
    1.  
    2. List<String> toRemove = new ArrayList<String>();
    3.  
    4. for(OfflinePlayer op : pl.getServer().getBannedPlayers()) {
    5. toRemove.add(op.getName());
    6. }
    7. for(String s : toRemove) {
    8. getServer().getOfflinePlayer(s).setBanned(false);
    9. }
    10.  
     
  3. Offline

    iZanax

    Realdope,

    I've found out that getIPBans the problem causer is,
    I tried to delete all IPbans at any moment, and It still occur that I get this CME.
    So I have no clue what I can do ; (
     
  4. Offline

    vildaberper

    Code:
    for(String ip : getServer().getIPBans().clone()) {
        getServer().unbanIP(ip);
    }
    You can't modify the set while you're looping through it (getServer().unBanIP(ip) does that), you'll have to clone it first.
     
  5. Offline

    Sagacious_Zed Bukkit Docs

    Just showing a for loop does not really show the context that it is running in.
     
Thread Status:
Not open for further replies.

Share This Page