Multiple problems with NonBlockingGenericDialog

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Multiple problems with NonBlockingGenericDialog

dscho
I just got notified by Gabriel Landini that there is a serious problem with the NonBlockingGenericDialog, introduced recently. While trying to reproduce it, I encountered another -- rather funny! -- bug: if you double-click the text tool icon multiple times before the dialog actually shows up (e.g. because you happen to use your computer efficiently, read: you overload your computer with work), the dialog will accumulate the same fields multiple times, in semi-random order:



It seems to be caused by both the `run()` and the `showDialog()` method in `ij.plugin.Text` lacking the `synchronized` attribute: https://github.com/imagej/imagej1/blob/4a71939ced48c291c7d01e903aa3ac6fc9b854fb/ij/plugin/Text.java#L23

The problem I *really* wanted to reproduce, though, seems to be caused by NonBlockingGenericDialog inserting itself into the Window menu *outside* the event dispatch thread. That is not allowed, and leads to a deadlock:

-- snipsnap --
[...]

Found one Java-level deadlock:
=============================
"Thread-11":
  waiting to lock monitor 0x00007fbf2c012ba0 (object 0x0000000692d84a80, a java.awt.Component$AWTTreeLock),
  which is held by "Run$_AWT-EventQueue-0"
"Run$_AWT-EventQueue-0":
  waiting to lock monitor 0x00007fbf240027e0 (object 0x000000068d737710, a ij.gui.NonBlockingGenericDialog),
  which is held by "Thread-11"

Java stack information for the threads listed above:
===================================================

"Thread-11":
        at java.awt.Menu.insert(Menu.java:286)
        - waiting to lock <0x0000000692d84a80> (a java.awt.Component$AWTTreeLock)
        at ij.Menus.insertWindowMenuItem(Menus.java:1207)
        - locked <0x00000007f8792cb8> (a java.lang.Class for ij.Menus)
        at ij.WindowManager.addWindow(WindowManager.java:247)
        - locked <0x00000007f87a4fc0> (a java.lang.Class for ij.WindowManager)
        at ij.gui.NonBlockingGenericDialog.showDialog(NonBlockingGenericDialog.java:17)
        - locked <0x000000068d737710> (a ij.gui.NonBlockingGenericDialog)
        at ij.plugin.Text.showDialog(Text.java:70)
        at ij.plugin.Text.run(Text.java:27)
        at ij.IJ.runPlugIn(IJ.java:169)
        at ij.IJ.runPlugIn(IJ.java:152)
        at ij.plugin.SimpleCommands$1.run(SimpleCommands.java:44)
        at java.lang.Thread.run(Thread.java:662)
"Run$_AWT-EventQueue-0":
        at java.awt.Component.addComponentListener(Component.java:4987)
        - waiting to lock <0x000000068d737710> (a ij.gui.NonBlockingGenericDialog)
        [...]