Bug - Fixed ConcurrentModificationException trying to decorate charpane

I've been getting lots of these lately. Debug log is below.
Code:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
          KoLmafia v16.3 r14475, Mac OS X, Java 1.8.0_20
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Please note: do not post this log in the KoLmafia thread of KoL's
 Gameplay-Discussion forum. If you would like the KoLmafia dev team
 to look at it, please write a bug report at kolmafia.us. Include
 specific information about what you were doing when you made this
 and include this log as an attachment.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 Timestamp: Sun Aug 24 08:20:58 EDT 2014
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


Unexpected error, debug log printed.
class java.util.ConcurrentModificationException: null
java.util.ConcurrentModificationException
	at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:901)
	at java.util.ArrayList$Itr.next(ArrayList.java:851)
	at net.sourceforge.kolmafia.webui.CharPaneDecorator.addCounters(CharPaneDecorator.java:1298)
	at net.sourceforge.kolmafia.webui.CharPaneDecorator.addCounters(CharPaneDecorator.java:1262)
	at net.sourceforge.kolmafia.webui.CharPaneDecorator.decorateEffects(CharPaneDecorator.java:708)
	at net.sourceforge.kolmafia.webui.CharPaneDecorator.decorate(CharPaneDecorator.java:133)
	at net.sourceforge.kolmafia.RequestEditorKit.applyPageAdjustments(RequestEditorKit.java:326)
	at net.sourceforge.kolmafia.RequestEditorKit.getFeatureRichHTML(RequestEditorKit.java:311)
	at net.sourceforge.kolmafia.RequestEditorKit.getFeatureRichHTML(RequestEditorKit.java:225)
	at net.sourceforge.kolmafia.request.RelayRequest.formatResponse(RelayRequest.java:361)
	at net.sourceforge.kolmafia.request.GenericRequest.run(GenericRequest.java:1429)
	at net.sourceforge.kolmafia.request.RelayRequest.run(RelayRequest.java:2576)
	at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:285)
	at net.sourceforge.kolmafia.RequestThread.postRequest(RequestThread.java:248)
	at net.sourceforge.kolmafia.webui.RelayAgent.readServerResponse(RelayAgent.java:552)
	at net.sourceforge.kolmafia.webui.RelayAgent.performRelay(RelayAgent.java:157)
	at net.sourceforge.kolmafia.webui.RelayAgent.run(RelayAgent.java:130)
 

Veracity

Developer
Staff member
What else were you doing at the time? Any scripts?

The decorator iterates over the active Counters. It does not set timers or remove timers. Yet, Java is saying that while it is so-iterating, some other thread is modifying the underlying list.

I wonder if this is a Java 8 bug.
 

Veracity

Developer
Staff member
I still wonder that - and I also wonder what other script you are running that is manipulating counters at the same time as we are attempting to decorate the charpane. If I can understand that, presumably I will understand what sort of synchronization might be necessary...

Revision 14496 makes the CharPaneDecorator iterate over an array of TurnCounters, rather than the original ArrayList. Since the decorator does all sorts of memory allocation and such which might allow thread switching to occur, this will will prevent the decorator from crashing if some other thread modifies the counters after it has fetched the array, even without synchronizing on the TurnCounter list.
 
What else were you doing at the time? Any scripts?

The decorator iterates over the active Counters. It does not set timers or remove timers. Yet, Java is saying that while it is so-iterating, some other thread is modifying the underlying list.

I wonder if this is a Java 8 bug.
Adventuring manually in the Relay Browser. No user scripts, just pure KoL and KoLmafia stuff.
 

Veracity

Developer
Staff member
Then this exception makes no sense at all.

We get an iterator for the TurnCounter list.
We iterate over the list.
Java reports that while we are doing that, some other thread modified the list.

Either something else was running and actually modifying the list, or this is a Java bug. Since you say you were nothing other than clicking in the Relay Browser, no other threads are doing anything, which would make this a Java bug.

I hope they fix it before they release Java 8 into the wild.
 

Veracity

Developer
Staff member
OK, even in Relay Browser operation we can have multiple threads, since every Browser Request is handled in its own thread.

- You finish a fight and one thread handles that.
- The browser asks for the charpane and another thread handles that.

If the first thread modifies the counter list, that could have caused the issue in the second thread. It boggles my mind that this would be happening "lots" for you recently but has never been reported before. Maybe we've been lucky.

I have not studied the code enough to figure out how that could have happened. In any case, Revision 14498 uses the big hammer of synchronization and makes the TurnCounter package thread safe everywhere. The bigger the hammer, the flatter the (squashed) bug. ;)
 
Top