The following code is liable to result in a ConcurrentModificationException
(emanating from the "for" line):
for (Unit unit : bwapi.getAllUnits()) {
logger.finest("Unit " + unit.getID() + ": Type ID = "
+ unit.getTypeID());
}
The reason is, I think, because JNIBWAPI.getAllUnits() just returns
units.values(), and while my code is iterating through that, the
JNIBWAPI.gameUpdate() method is likely to be modifying the units member
variable.
The workaround is this:
for (Unit unit : bwapi.getAllUnits().toArray(new Unit[0])) {
logger.finest("Unit " + unit.getID() + ": Type ID = "
+ unit.getTypeID());
}
Not a bug, but it would be nice if the returned Collection of
JNIBWAPI.getAllUnits was threadsafe.
Original issue reported on code.google.com by jamesric...@googlemail.com on 24 Apr 2011 at 5:29
Original issue reported on code.google.com by
jamesric...@googlemail.com
on 24 Apr 2011 at 5:29