Bug ScriptMenu.init

Veracity

Developer
Staff member
I see this now and then. Five times just now in the same session.

What I did:

1) Logged in
2) Pressed button 3 - "call VeracityMeatFarm"
3) Logged out

VMF runs other scripts. For this character: Garden Harvester, VeracitySpacegate, Ezandora's Bastille, my breakfast script

That would be five scripts.

Code:
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
    at java.base/java.util.ArrayList$Itr.checkForComodification(ArrayList.java:1013)
    at java.base/java.util.ArrayList$Itr.next(ArrayList.java:967)
    at net.sourceforge.kolmafia.swingui.menu.ScriptMenu.init(ScriptMenu.java:69)
    at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:318)
    at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:771)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:722)
    at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:716)
    at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
    at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:741)
    at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
    at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
    at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
 

fronobulax

Developer
Staff member
I saw this in tests for https://github.com/kolmafia/kolmafia/pull/1441.

The error was in GearChangePanelTest which had nothing to do with my changes. Intuition or an unfounded guess made me wonder whether ScriptMenu.init was being invoked multiple times because no character was logged in. I changed my test so that there was a logged in character during the test and the error went away.
 

fronobulax

Developer
Staff member
1) Logged in
2) Pressed button 3 - "call VeracityMeatFarm"
3) Logged out

For my edification did you wait until VMF had finished before logging out or did you log out after VMF had started (but not finished)?

If the latter what is the expected/desired behavior when a script is running and the user attempts to log out?

I would expect that a logout would either stop all scripts, execute the logout script and then log out of KoL OR logout would be added to a queue and otherwise do nothing until scripts had finished.
 

Veracity

Developer
Staff member
I waited until my script had run to completion.

The point being, these exceptions are all in the AWT event thread - and I was not performing any GUI actions whatsoever after I pressed the button and started the script until the script finished and I logged out by closing the main window and returning to the login frame.
 

MCroft

Developer
Staff member
Any chance this is related to the scriptMRUlist? What I'm wondering is if there's some sort of race condition/concurrency violation adding each of the five scripts to the most recent list.

I know it's hard to test since it is intermittent, but maybe it would go away if you turned off the script menu features in the prefs.
 

fronobulax

Developer
Staff member
I have seen this or something similar in tests so it presumably happens with the default values. It is definitely intermittent in tests and has happened both locally on Windows and on GitHub. Look at failed tests from the CalendarFrameTest PR.

I reluctantly stopped using the scriptMRU menu weeks ago. I was seeing cases where there were extra elements inserted to the point that it was unusable. Something, perhaps the synchronization, made it so that the characters that used it took significantly more wall clock time than not using it. So I sucked it up and trained myself to use bookmarks and navigate the file system to launch scripts. In my dark moments I consider ripping the feature out since I'm not certain anyone else continues to use it, but I have not gotten to the point of socializing that idea.

In any event, the array that is causing the problem is built either from the MRU list or from the file system so what varies would be the content and not whether the list is built, or rebuilt.

For the most part anything I can do, veracity can do better, but I expect to poke at this "soon" if there is no resolution.
 

fronobulax

Developer
Staff member
Since I alluded, without evidence, to problems with the Scripts menu, see the attached which looks like problems I have seen intermittently since Hola's changes. I have seen this with and without the Scripts MRU enabled.

I ran my turns and had to leave for a meeting. I closed my laptop, putting it in sleep mode and went away for a couple of hours. I woke up the laptop, went to KoLmafia to run my end of day script and saw the menu rendered. I cannot say for sure whether the menu rendered correctly before my absence or not. (Archive is the first subdirectory in my scripts directory)>

Capture.JPG
 

Linknoid

Member
I ran my turns and had to leave for a meeting. I closed my laptop, putting it in sleep mode and went away for a couple of hours. I woke up the laptop, went to KoLmafia to run my end of day script and saw the menu rendered. I cannot say for sure whether the menu rendered correctly before my absence or not. (Archive is the first subdirectory in my scripts directory)>
I've been seeing such behavior since I upgraded to Java 17. Switching users or going to sleep makes the Scripts menu do weird stuff. I assumed it was a bug in Java, not in KoLmafia, so I never reported it. I've just gotten used to dealing with it.

Observed behavior:

* Sometimes the menu items are giant like in the screenshot above.

* Sometimes the menu isn't loaded at all, and it's missing the "Refresh menu" item.

* I have enough menu items to require scroll arrows, and sometimes these scroll arrows get duplicated a bunch of times, so I can't scroll all the way to the bottom. If I "Refresh menu" for this state, it usually reduces the number of extra scroll arrows down to 1 or 2, and I can scroll through the menu a single time before corrupting again, at which point I have to "Refresh menu" again.

* If I have 3 windows open, sometimes one of them gets the giant menu items, one doesn't load at all, and the 3rd gets the extra arrows, in which case I can refresh menu on the 3rd window and access the menu items that way.

I've noticed similar weirdnesses in Firefox's bookmarks, so I think something is going on beyond the scope of KoLmafia. Maybe a Java bug, or maybe a Windows bug.
 

fronobulax

Developer
Staff member
Thanks. I think I was on Java 17 long enough that it might not be the trigger but if I'm not the only one seeing it that is incentive to track it down. I wish my hypothesis that it is related to Scriptmenu.init and when it is called could be proved or eliminated :)
 
Top