I am getting an ArrayIndexOutOfBoundsException in my RequestHandler, and it's apparently happening in ArrayList.fastRemove(). This is the offending code in my extension:
if (_playerHashMap.containsKey(location)) {
List<Entity> playerList = _playerHashMap.get(location);
if (playerList.contains(player)) {
playerList.remove(player); // <-- this is where the exception occurs
}
}
The exception is fairly rare, and it occurs even when I'm the only client connected to the server, so I'm not sure what the cause could be. Since the line right before verifies that the Player is in the List, I can only assume that two requests are being executed simultaneously. Does that seem plausible?
Could you please report the full stack trace of the error?
The List.remove(...) method is not documented to throw an ArrayOutOfBoundException. What kind of list implementation are you using?
Thanks,
it's a concurrency issue with the ArrayList. If two threads are running the same remove() operation "simultaneously" the problem will arise. In general all Java standard List implementations are not thread safe.
Two basic possible solutions:
1- synchronize manually
2- User Collections.synchronizedList(...) ( see Oracle javadoc )