Question

I know that I should provide with enough information for a special bug. But it is not possible to reproduce it. I have a highly multithreaded program. I have a thread with an infinite while loop. No part of the program can interrupt this thread. I check Thread.currentThread().isInterrupted(); as much as I can. But sometimes it happens that thread stops running with a strange exception stack trace that tells it can't convert some type to Boolean in the setText mehod of some Lable and it points to the following line of the programme:

JOptionPane.showMessageDialog(null, "action finished, going to the next!");

I know that I should think differently! because I have no label to set the text which is done in this thread. In fact in the whole program I never change any text of the GUI. I just write to the console. What can be the problem? Can it be a memory leak in my code or it might be a bug of Java?

Was it helpful?

Solution

I think the issue here is that you're not supposed to invoke showMessageDialog directly. Swing expects that all GUI operations go through the main Swing thread, and as reported in this answer I suspect that the issue here is a race condition between your thread (which shouldn't do touching the GUI directly) and the Swing thread (which is supposed to handle this).

You may want to consider firing off showMessageDialog from a SwingWorker or by using invokeLater.

Hope this helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top