Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4506715

Plug-in and IE both lock/freeze after a modal dialog is launched from JavaScript

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • deploy
    • x86
    • windows_2000

      Note that this is the output of java -version, while the problem itself occurs
      from the plugin.

      java version "1.4.0-beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b77)
      Java HotSpot(TM) Client VM (build 1.4.0-beta-b77, mixed mode)


      Please take careful note that I have read all "related" bugs, such as
      http://developer.java.sun.com/developer/bugParade/bugs/4192193.html (Bug ID
      4192193). The problem itself has not been fixed and all suggestion workarounds
      that I have seen do not provide a correct solutions.

      The problem is that the browser and plug-in become locked-up after a modal
      dialog is shown when invoked via JavaScript. I have been able to reproduce
      this problem with Java Plug-in 1.3.0_0(1-5), 1.3.1, and 1.4.0. As the most
      simple scenario, imagine an HTML document with an Applet and a form with a
      button that has a JavaScript method that is called when the button is pressed.
      The onPressed event calls a JavaScript method that gets the Applet and then
      makes a call into a method that brings up a modal dialog. This modal dialog
      can be a Swing Dialog such as JOptionPane or a custom dialog. It does not
      matter.

        Suggested workarounds include creating a SwingWorker that performs the work on
      a new thread (not the EventDispatcherThread). This suggestion will allow us to
      have an Applet free of lock-ups. However, it does not fix the actual problem
      itself. It is important that the modality be maintained, for example, suppose
      we have a JavaScript method that brings up a modal dialog and then uses the
      result of that dialog. Spawning a new thread would cause the initial thread to
      immediately come back to the javascript method where it would try to use the
      result of the dialog that has not yet been set.

      Follow these steps to reproduce this bug:

      1. Create an HTML document as follows:

      <!-- saved from url=(0022)http://internet.e-mail -->
      <HTML>

      <HEAD>
      <TITLE>Freezer</TITLE>
      </HEAD>

      <SCRIPT>
      function showJOptionDialog()
      {
        var applet = document.applets["FreezerApplet"];
        applet.showJOptionDialog();
      }

      function showCustomDialog()
      {
        var applet = document.applets["FreezerApplet"];
        applet.showCustomDialog();
      }
      </SCRIPT>

      <BODY>
      <CENTER>
      <form>
      <table border="0" width="100%">
        <tr>
          <td>
            <!--"CONVERTED_APPLET"-->
      <!-- CONVERTER VERSION 1.3 -->
      <OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
      WIDTH = 320 HEIGHT = 200 id = "FreezerApplet"
      codebase="http://java.sun.com/products/plugin/1.3/jinstall-13-
      win32.cab#Version=1,3,0,0">
      <PARAM NAME = CODE VALUE
      = "DialogFreezingProblemWhenInvokedFromJavaScriptTestApplet" >
      <PARAM NAME = ARCHIVE VALUE = "DialogFreezer.jar" >
      <PARAM NAME = MAYSCRIPT VALUE = true >
      <PARAM NAME = SCRIPTABLE VALUE = true >
      <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
      <PARAM NAME="scriptable" VALUE="false">
      <COMMENT>
      <EMBED type="application/x-java-applet;version=1.3"
      CODE = "DialogFreezingProblemWhenInvokedFromJavaScriptTestApplet"
      ARCHIVE = "DialogFreezer.jar"
      WIDTH = 320 HEIGHT = 200
      MAYSCRIPT = true
      scriptable=true
      pluginspage="http://java.sun.com/products/plugin/1.3/plugin-install.html">
      <NOEMBED>
      </COMMENT>

      </NOEMBED></EMBED>
      </OBJECT>
      <!--"END_CONVERTED_APPLET"-->

          </td>
        </tr>
        <tr>
          <td>
      <input type="button" value="Bring up Swing Dialog" name="B1"
      onClick="showJOptionDialog()">
      <input type="button" value="Bring up Custom Dialog" name="B2"
      onClick="showCustomDialog()">
      </select>
          </td>
        </tr>
      </table>
      </form>

      </CENTER>

      </BODY>

      </HTML>

      -------------------------------------------------------------------------------

      2. Create DialogFreezingProblemWhenInvokedFromJavaScriptTestApplet.java as
      follows:


      import javax.swing.*;
      import java.awt.*;

      public class DialogFreezingProblemWhenInvokedFromJavaScriptTestApplet extends
      JApplet {

        public void start() {
          super.start();
        }

        public void stop() {
          super.stop();
        }

        public void init() {
          super.init();
        }

        public void showJOptionDialog() {
          System.out.println("showJOptionDialog() enter");

          JOptionPane.showMessageDialog(this, "Message", "Title",
      JOptionPane.INFORMATION_MESSAGE);

          System.out.println("showJOptionDialog() exit");
        }

        public void showCustomDialog() {
          System.out.println("showCustomDialog() enter");

          Frame f = (Frame)SwingUtilities.getRoot(this);
          JDialog d = new CustomJDialog(f, "Custom Dialog", true);
          d.show();

          System.out.println("showCustomDialog() exit");
        }
      }

      -------------------------------------------------------------------------------

      3. Create CustomJDialog.java as follows:


      import javax.swing.*;
      import java.awt.*;
      import java.awt.event.*;


      public class CustomJDialog extends JDialog {

          static Window getWindowForComponent(Component parentComponent) {
              if (parentComponent == null)
                  return JOptionPane.getRootFrame();
              if (parentComponent instanceof Frame || parentComponent instanceof
      Dialog)
                  return (Window)parentComponent;
              return getWindowForComponent(parentComponent.getParent());
          }

        public CustomJDialog (Frame parent, String title, boolean modal) {
          super(parent, title, modal);
          init();
          System.out.println("parent frame = " + parent);
        }

        public void init() {
          getContentPane().setLayout(new BorderLayout());

          JButton b = new JButton("OK");
          b.setAction(new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
              CustomJDialog.this.dispose();
            }
          });
          getContentPane().add(b, BorderLayout.CENTER);
          setSize(320,200);
          setLocation(200,200);
        }
      }

      -------------------------------------------------------------------------------

      4. Compile the two source files.
      5. Create a jar 'DialogFreezer.jar' with the class files from step 4.
      6. Put the HTML and jar where your browser can hit them.
      7. Hit them.
      8. Click either button on the form.
      9. Game over.

            Unassigned Unassigned
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: