Microsoft KB Archive/318175

From BetaArchive Wiki

Article ID: 318175

Article Last Modified on 10/20/2003



APPLIES TO

  • Microsoft virtual machine 38xx Series, when used with:
    • Microsoft Windows XP Professional



This article was previously published under Q318175

SYMPTOMS

If you call the dispose function on a Java FileDialog object in Windows XP, the browser may stop responding (hang) at random times. For example, suppose that you create a simple Java applet with a button that opens a File dialog box when you click it. If you repeatedly click the button to open the File dialog box and then click Cancel to close the File dialog box, your browser may hang.

CAUSE

This problem occurs if the current thread that starts the File dialog box is the event dispatch thread.

RESOLUTION

Create a new thread to display the File dialog box. Do not use the default event dispatch thread to display the File dialog box. Refer to the "Steps to Resolve the Problem" portion of the "More Information" section for implementation details.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create the java class AWTApplet.java as follows:

    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    
    public class AWTApplet extends Applet implements ActionListener
    {
        Button button   = new Button("Call FileDialog");
        
        public void init()
        {
            // a button panel
            Panel bpanel = new Panel();
            bpanel.add(button);
    
            GridLayout gridLayout = new GridLayout();
            this.setLayout(gridLayout);
            this.add(bpanel);
    
            // Add the ActionListener.
            button.addActionListener(this);
        }
        
        public void actionPerformed(ActionEvent ae)
        {
            FileDialog dlgFile;         
            dlgFile = new FileDialog((Frame)getParent(),"test");    
                        
            dlgFile.show();
            // The following call to the dispose function causes the browser to hang.
            dlgFile.dispose();
        }
    }
                            

    This code spawns a new thread to open the File dialog box.

  2. To compile the java class, type jvc awtapplet.java at the command line.
  3. You can run the preceding code if it originates from a trusted source. To access files from the File dialog box, Java comes out of the Java sandbox. (The Java sandbox is the security scheme for Java programs.) You can access files with Java if you put the class files in a signed .cab file, which is noted in the "References" section.

    The following command-line commands use tools from the Microsoft Software Development Kit (SDK) for Java to compile the Java source file and to generate a signed .cab file that uses the Microsoft Test Certificate:

    jvc awtapplet.java
    cabarc n myapplet.cab awtapplet.class setreg 1 true
    makecert -sk mytestkey -n "cn=mytestkey" mytestkey.cer
    cert2spc mytestkey.cer mytestkey.spc
    signcode -j javasign.dll -jp low -spc mytestkey.spc -k mytestkey
    myapplet.cab
    chkjava myapplet.cab

  4. Create a Hypertext Markup Language (HTML) file that appears as follows:

    <APPLET CODE = "AWTApplet.class" HEIGHT = 100 WIDTH  = 100>
      <PARAM NAME="cabbase" VALUE="MyApplet.cab">
    </APPLET>
                        
  5. Load the HTML page in a Web browser, click Call FileDialog, and then click Cancel in the File dialog box.
  6. Repeat step five until the browser hangs.

Steps to Resolve Problem

  1. Implement the AWTApplet class as follows:

    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    
    public class AWTApplet extends Applet implements ActionListener, Runnable
    {
        Button button   = new Button("Call FileDialog");
        
        public void init()
        {
            // a button panel
            Panel bpanel = new Panel();
            bpanel.add(button);
    
            GridLayout gridLayout = new GridLayout();
            this.setLayout(gridLayout);
            this.add(bpanel);
    
            // Add the ActionListener.
            button.addActionListener(this);
        }
        
        public void actionPerformed(ActionEvent ae)
        {
            new Thread(this).start();
        }
        
        public void run()
        {
            FileDialog dlgFile;         
            dlgFile = new FileDialog((Frame)getParent(),"test");    
                        
            dlgFile.show();
            dlgFile.dispose();
        }
    
    }

    This code spawns a new thread to open the File dialog box.

  2. Repeat steps 2 through 5 from the "Steps to Reproduce Behavior" section.


REFERENCES

For additional information, click the article numbers below to view the articles in the Microsoft Knowledge Base:

193877 HOWTO: Make Your Java Code Trusted in Internet Explorer


179543 HOWTO: How Do I Enable Test Certificates on a Client Machine?


Keywords: kbprb KB318175