I'm surprised that I couldn't find a quick solution for this. I've been coding Java Swing application for a very long time. Myself, I've always coded things up nicely, so that the code only ever interacts with the various visual elements from inside the AWT thread, all nicely event driven. When outside events happens, like say, incoming data that needs displaying, I would lock a data structure, and then have the visual code repaint it, on the AWT threat. No problem there. But the problem is that there are other coders on the project, and some people have contributed code that is difficult to check up on. There are now bugs that I suspect are caused by code making changes to Swing outside the AWT thread, on another thread.
What I am after, is some sort of simple mechanism, that traps and blocks, and/or show stacktraces of offending code, that incorrectly interact with Swing on the wrong thread. Unfortunately, the javax.swing code doesn't have any checks built in. I'm thinking, make the environment headless somehow, trap some sort of low level thing, that only puts things back during a dispatched AWT event. Or, doing something very drastic, like using a custom classloader, that somehow swap out entire packages. Perhaps it's possible for different threads to have their own classloader? If that is possible, then the AWT thread might be set to see the normal javax.swing stuff, and other threads a rigged fake javax.swing.
Or, perhaps some IDEs have built in tricks to do this? I'm using IntelliJ IDEA.
Does anyone know of any tricks? It's only need during development. So overriding javax.swing using a bootclassloader is ok. I can't be the first one looking for this?