Java Programming
Issues With Iterating My Map
Iterator<Player> iterator = plugin.inreview.keySet().iterator();
while (iterator.hasNext()) {
Player key = (Player) iterator.next();
chat.getRecipients().remove(key);
}
This throws:
java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
Any ideas as to why this is happening? When this occurs, there is one key (with one value) in the map.
Also, it used to work until recently and I have done so much work on my Java file that I have no way to find out what made this occur. I can’t do any while loop when iterating this map which complicates things a ton!
Notes:
Chat.getRecipients()is not the same asplugin.inreview- Used to work just fine
- It is a
HashBiMap
Please, give me any hints and ideas that you may have.
Extra Details:
java.util.NoSuchElementException
at java.util.HashMap$HashIterator.nextEntry(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
at java.util.HashMap$EntryIterator.next(Unknown Source)
at com.google.common.collect.AbstractBiMap$EntrySet$1.next(AbstractBiMap.java:314)
at com.google.common.collect.AbstractBiMap$EntrySet$1.next(AbstractBiMap.java:306)
at me.geekplaya.Judge.JudgeQuit.onPlayerQuit(JudgeQuit.java:25)
at org.bukkit.plugin.java.JavaPluginLoader$2.execute(JavaPluginLoader.java:251)
at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:58)
at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:339)
at net.minecraft.server.ServerConfigurationManager.disconnect(ServerConfigurationManager.java:159)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:650)
at net.minecraft.server.NetworkManager.b(NetworkManager.java:231)
at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:92)
at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
at net.minecraft.server.MinecraftServer.h(MinecraftServer.java:471)
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:374)
at net.minecraft.server.ThreadServerApplication.run(SourceFile:417)
If the
removecall is, as you say, not operating on the iterated sequence then there must be another thread updatingplugin.inreview.Check all write accessors of
plugin.reviewand make sure no concurrent update is possible while a thread is reading using this code.Note that such a bug could fail to manifest for a long time and then suddenly become a serious issue due to changes elsewhere that affect thread timings.