Bug - Not A Bug Occasional exception in headless mode

Alhifar

Member
I'm not entirely sure what is causing this, but I've been occasionally seeing this exception in my terminal while running a bot in headless mode

Code:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: sun.java2d.
HeadlessGraphicsEnvironment cannot be cast to sun.awt.Win32GraphicsEnvironment
        at sun.awt.windows.WToolkit$3.run(WToolkit.java:737)
        at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:666)
        at java.awt.EventQueue.access$400(EventQueue.java:81)
        at java.awt.EventQueue$2.run(EventQueue.java:627)
        at java.awt.EventQueue$2.run(EventQueue.java:625)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessCo
ntrolContext.java:87)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:636)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

EDIT: I forgot to mention that this doesn't actually stop mafia or, as far as I can tell, actually break anything.
 
Last edited:

Catch-22

Active member
Do you have any relevant debug logs? What version of Java are you using? What platform (eg. Windows 7 64-bit)?
 

Veracity

Developer
Staff member
Because, after all, no bugs in earlier versions remain un-fixed in Java 7, and Java 7 has no new bugs of its own!
Yeah!
 

Catch-22

Active member
I didn't say that.

Alhifar to help you further, I actually looked in to the problem. You're running KoLmafia in an environment where Windows is sending WM_DISPLAYCHANGE messages to the Java instance. This means you're running KoLmafia in a GDI window, I'm guessing a command prompt. Long story short, remove the -Djava.awt.headless=true section from your command line options and just stick with --CLI. You're telling Java that it's running in a headless environment, when it really isn't.
 

Catch-22

Active member
I tried that, but then you can't start the chat interface so the chatbot script works

I noticed earlier today that there are some sections of KoLmafia code that say things like if (StaticEntity.isHeadless) that should probably say if (!StaticEntity.isGUIRequired) instead, but I didn't think much of it.

Turns out the ChatManager was one of those places. This patch would likely fix your issue (and result in more consistent behaviour across the board for CLI mode users that are not running in a headless environment).

Patch compiles but is otherwise untested, maybe if a dev is feeling nice they can greenlight it.
 

Attachments

  • isGUIRequired.patch
    4 KB · Views: 67
Top