JDK-4419491 : Using browser 'back' & 'forward' buttons can result in multiple copies of applet
  • Type: Bug
  • Component: deploy
  • Sub-Component: plugin
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2001-02-27
  • Updated: 2001-05-21
  • Resolved: 2001-05-21
Related Reports
Relates :  
Description

Name: md23716			Date: 02/27/2001

Problem is observed with Plugin version 1.3.0-C.  Use the programs below to reproduce.  
Start a browser, load the applet, wait for the applet to start.  

Now using the browser back button go back to
the previous applet, whilst it is loading, using the browser forward button
go forward to the other applet.  Keep on flicking back and forward
(sometimes takes about 20 tries) and you will eventually end up with
multiple copies of the applets running at once.  You sometimes have to be
quite specific about the amount of time between hitting forward and hitting
back, usually works if you press as soon as one button becomes un-greyed.

The customer has larger applets across a slower link whilst waiting for the
applet to download into the browser users have believed the browser to not
be responding and so have pressed the back button to get to the previous
web page.  When that has not worked either they have used a combination of
back and forward until they get multiple applets, as with the testcase.


SwingAppletFrame.java:

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

/**
 * A very simple applet.
 *
 * ATTENTION:
 * This example has been modified for test purposes:
 * The example can be executed as an application or an applet.
 * It starts its own frame, also when executed as an applet.
 *
 */
public class SwingAppletFrame extends JApplet {

  private static boolean cvIsApplet = true;

  public void init() {
    new SwingAppletImpl().show();
  }

  public static void main(String[] args) {
    cvIsApplet = false;
    new SwingAppletFrame().init();
  }

  class SwingAppletImpl extends JFrame {

    JButton button;

    public SwingAppletImpl() {

      // Force SwingApplet to come up in the System L&F
      String laf = UIManager.getSystemLookAndFeelClassName();
      try {
          UIManager.setLookAndFeel(laf);
          // If you want the Cross Platform L&F instead, comment out the above line and
          // uncomment the following:
          // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
      } catch (UnsupportedLookAndFeelException exc) {
          System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
      } catch (Exception exc) {
          System.err.println("Error loading " + laf + ": " + exc);
      }

      getContentPane().setLayout(new FlowLayout());
      button = new JButton("Hello, I'm a Swing Button!");
      getContentPane().add(button);
      setTitle("SwingApplet-Test");
      setSize(new Dimension(200,200));

      addWindowListener( new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
          if (cvIsApplet)
            dispose();
          else
            System.exit(0);
        }
      });
    }
  }
}


The second applet is the same, but has a wait on startup:

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

/**
 * A very simple applet.
 *
 * ATTENTION:
 * This example has been modified for test purposes:
 * The example can be executed as an application or an applet.
 * It starts its own frame, also when executed as an applet.
 *
 */
public class SwingAppletFrame extends JApplet {

  private static boolean cvIsApplet = true;

  public void init() {
    new SwingAppletImpl().show();
  }

  public static void main(String[] args) {
    cvIsApplet = false;
    new SwingAppletFrame().init();
  }

  class SwingAppletImpl extends JFrame {

    JButton button;

    public SwingAppletImpl() {

      // Force SwingApplet to come up in the System L&F
      String laf = UIManager.getSystemLookAndFeelClassName();
      try {
          UIManager.setLookAndFeel(laf);
          // If you want the Cross Platform L&F instead, comment out the above line and
          // uncomment the following:
          // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
      } catch (UnsupportedLookAndFeelException exc) {
          System.err.println("Warning: UnsupportedLookAndFeel: " + laf);
      } catch (Exception exc) {
          System.err.println("Error loading " + laf + ": " + exc);
      }


      getContentPane().setLayout(new FlowLayout());
      button = new JButton("Hello, I'm a Swing Button!");
      getContentPane().add(button);
      setTitle("SwingApplet-Test");
      setSize(new Dimension(200,200));
      try {
        Thread.sleep(5000);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }

      addWindowListener( new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
          if (cvIsApplet)
            dispose();
          else
            System.exit(0);
        }
      });
    }
  }
}


======================================================================

Comments
EVALUATION The problem is reproducable on Winnt4 and win2000 with Netscape4, Netscape6 and IE5. Changing plugins from the original 1.3.0-C to 1.3.0_02, 1.3.1 and 1.4 doesn't help. Added 2 zip files I used for testing, see <Attachments>. alex.sultanov@Ireland 2001-04-11 The applet is calling Thread.sleep() in init(), which blocks receiving the applets to receive the stop() and destroy() call. When JPI shutdowns the applets, we basically interrupts every single threads in the applets, but JPI returns without waiting for applets to be completely destroyed to avoid potential browser lockup by the applets. Eventually, the applet thread will be interrupted and returned, and all the applet threads and applet instances will be destroyed. As long as there is no applet threads running around after all the applet threads are interrupted, this is not a problem. The issue is a side-effect of how we shutdown applet threads, and it will not be fixed. stanley.ho@Eng 2001-05-21
21-05-2001