JDK-4311794 : modal dialog dispatcher thread is fired up before dialog actually appears
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 1.2.2
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-02-11
  • Updated: 2000-02-14
  • Resolved: 2000-02-14
Related Reports
Duplicate :  
Description
Problem: Modal dialogs do not block fast enough allowing for multiple
modal dialog instances to be created before the block is enabled.

Clicking on the "Create Modal Dialog..." button on applet/frame several
times in rapid succession brings up multiple dialog windows. It appears
that there's a race condition of whether the first modal dialog
invokes the modal block or the subsequent Button events are processed by
the applet's event handler. The create dialog button event is handled
before the first modal dialog instance invokes the modal block, hence
multiple dialogs are created when you only want one.

Existing bugid 4088877 reports states "this problem will be fixed in 1.2 by event queue stacking and moving modal dialog code into java." However, test cases using JDK 1.2.2 and JDK 1.3RC1 still shows that this problem still exist. 

Code for test cases are listed below :

-------------------- TestDialog.java --------------------

import java.awt.*;
import java.applet.*;

class TestDialog extends Dialog {

  public TestDialog(Frame parent, String title) {
    super(parent, title, true);
    System.err.println("create: " + title);
    setLayout(new BorderLayout(15,15));
    // do something that takes a little time
    for (int i=1; i < 100000; i++)
      new Integer(i);
    add("Center", new Label("This a test", Label.CENTER));
    add("South", new Button("Ok"));
    resize(200,80);
    System.err.println("show: " + title);
    show();
  }

  public boolean action (Event e, Object arg) {
    if (e.target instanceof Button) {
      hide();
      dispose();
      return true;
    }
    return false;
  }

}

------------------ BugDialog.java -----------------------

import java.awt.*;
import java.applet.*;

public class BugDialog extends Applet {

  int count = 1;
  boolean workaround = false;

  public BugDialog() {
    add(new Button("Create Modal Dialog..."));
    add(new Checkbox("Enable workaround"));
    resize(100,100);
  }

  public boolean action(Event e, Object o) {
    if (e.target instanceof Button)  {
      Container parent = getParent();
      while (parent != null && ! (parent instanceof Frame) )
	parent = parent.getParent();
      if (workaround) disable();
      new TestDialog((Frame)parent, "Modal Dialog " + count++);
      if (workaround) enable();
    } else if (e.target instanceof Checkbox) {
      workaround = ((Checkbox)e.target).getState();
      System.err.println("workaround " + workaround);
    } else {
      return false;
    }
      return true;

  }
  
  public static void main (String args[])
  {
    Frame f = new Frame("BugDialog");
    BugDialog d = new BugDialog();
    d.init();
    d.start();
    f.add("Center", d);
    f.pack();
    f.show();
  }

}