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

Plugin problems using legacy_lifecycle with Firefox 3 and JRE 6u10

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • None
    • 6u10
    • deploy
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      java version "1.6.0_10"
      Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
      Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Windows XP version 2.07


      A DESCRIPTION OF THE PROBLEM :
      One of the most basic functions of our applet relies on it being reloaded in the browser due to changes in the URL. As a result we are now dependent upon using the legacy_lifecycle option with the plugin because our applet no longer works when the applet destroy() method is called (due to the ThreadGroup being destroyed).

      However, we are running into the following problem when setting legacy_lifecycle param to true in the applet html, using JRE 6u10 and Firefox 3.0.0.4 (does not occur for IE). It does not matter whether the next-generation plugin is enabled or not. The same behavior occurs.

      What appears to happen is that after loading the applet the first time, if you click the browser refresh button, the applet is stopped and added to the lifecycle cache. So far correct. However, then another instance is created and init is called. We are expecting that that first cached instance would be retrieved from the lifecycle cache, but instead now are using a second instance. If you click the browser refresh button a second time, then the first cached instance is found and the second is added to the cache. Seems like there is a timing issue where the lifecycle cache lookup is occurring before the applet instance is added to the cache.

      We rely on there only being one instance of our applet being cached/retrieved, i.e. the behavior that occurs with IE.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Modify shipped Blink applet to keep track of instance creation in constructor and then add System.out statements in constructor, init(), start() and stop() methods to print out applet instance id.
      2. Add this line to Blink.html

       <param name="legacy_lifecycle" VALUE="TRUE">

      3. Load applet in Firefox 3. (Doesn't matter if next-generation plugin enabled or not - same results)
      4. Refresh page/applet once - observe that applet instance increments to 2, but should remain at 1.
      5. Refresh again - observe that the first applet instance is retrieved from cache and second one added

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Applet instance id remains at 1 throughout the refreshes. At stop() this first instance is added to the lifecycle cache and then the same instance is retrieved from the cache when applet is loaded/init'd again.
      ACTUAL -
      Here's the Java console output --

      basic: Referencing classloader: sun.plugin.ClassLoaderInfo@13dd208, refcount=1
      basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@886ad0
      basic: Loading applet ...
      basic: Initializing applet ...
      basic: Starting applet ...
      basic: completed perf rollup
      Blink() -- Applet instance id = 1
      init() -- Applet instance id = 1
      start() -- Applet instance id = 1

      <-- Refresh button hit -->

      basic: Stopping applet ...
      basic: Referencing classloader: sun.plugin.ClassLoaderInfo@13dd208, refcount=2
      basic: Applet supports legacy lifecycle model - add applet to lifecycle cache <-- first instance added to cache - ok
      stop() -- Applet instance id = 1
      basic: Added progress listener: sun.plugin.util.GrayBoxPainter$GrayBoxProgressListener@a50da4
      basic: Loading applet ...
      basic: Initializing applet ... <-- why wasn't the first instance retrieved from cache, a second one is now being created
      basic: Starting applet ...
      basic: completed perf rollup
      Blink() -- Applet instance id = 2 <--- now we're using a 2nd instance, not ok
      init() -- Applet instance id = 2
      start() -- Applet instance id = 2

      <-- Refresh hit again -->

      basic: Stopping applet ...
      stop() -- Applet instance id = 2
      basic: Found previous stopped applet from lifecycle cache <-- shouldn't the instance be added to cache before attempting to retrieve?
      basic: Applet supports legacy lifecycle model - add applet to lifecycle cache
      basic: Referencing classloader: sun.plugin.ClassLoaderInfo@13dd208, refcount=3
      basic: Starting applet ...
      basic: completed perf rollup
      start() -- Applet instance id = 1 <-- so now we run with the first instance, not second?


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Blink.java code ---

      import java.awt.*;
      import java.util.*;

      public class Blink extends java.applet.Applet {
          private Timer timer; // Schedules the blinking
          private String labelString; // The label for the window
          private int delay; // the delay time between blinks
          private int appletID;
          public static int appletConstructionCount = 0;

          public Blink() {
              appletConstructionCount++;
              appletID = appletConstructionCount;
              System.out.println("Blink() -- Applet instance id = " + appletID);
          }

          public void init() {
              System.out.println("init() -- Applet instance id = " + appletID);
              String blinkFrequency = getParameter("speed");
              delay = (blinkFrequency == null) ? 400 :
                  (1000 / Integer.parseInt(blinkFrequency));
              labelString = getParameter("lbl");
      labelString += labelString;
              if (labelString == null)
                  labelString = "Blink";
              Font font = new java.awt.Font("Serif", Font.BOLD, 24);
              setFont(font);
          }

          public void start() {
              System.out.println("start() -- Applet instance id = " + appletID);
              timer = new Timer(); //creates a new timer to schedule the blinking
              timer.schedule(new TimerTask() { //creates a timertask to schedule
                  // overrides the run method to provide functionality
                  public void run() {
                      repaint();
                  }
              }
                  , delay, delay);
          }

          public void paint(Graphics g) {
              int fontSize = g.getFont().getSize();
              int x = 0, y = fontSize, space;
              int red = (int) ( 50 * Math.random());
              int green = (int) ( 50 * Math.random());
              int blue = (int) (256 * Math.random());
              Dimension d = getSize();
              g.setColor(Color.black);
              FontMetrics fm = g.getFontMetrics();
              space = fm.stringWidth(" ");
              for (StringTokenizer t = new StringTokenizer(labelString);
                   t.hasMoreTokens();) {
                  String word = t.nextToken();
                  int w = fm.stringWidth(word) + space;
                  if (x + w > d.width) {
                      x = 0;
                      y += fontSize; //move word to next line if it doesn't fit
                  }
                  if (Math.random() < 0.5)
                      g.setColor(new java.awt.Color((red + y*30) % 256,
                                                    (green + x/3) % 256, blue));
                  else
                      g.setColor(getBackground());
                  g.drawString(word, x, y);
                  x += w; //shift to the right to draw the next word
              }
          }
          
          public void stop() {
              System.out.println("stop() -- Applet instance id = " + appletID);
              timer.cancel(); //stops the timer
          }

          public void destroy() {
              System.out.println("stop() -- Applet instance id = " + appletID);
              super.destroy();
          }

          public String getAppletInfo() {
              return "Title: Blinker\n"
                  + "Author: Arthur van Hoff\n"
                  + "Displays multicolored blinking text.";
          }
          
          public String[][] getParameterInfo() {
              String pinfo[][] = {
                  {"speed", "string", "The blink frequency"},
                  {"lbl", "string", "The text to blink."},
              };
              return pinfo;
          }

      }

      Blink.html ---

      <html>
        <head>
            <title>Blinking Text</title>
        </head>
        <body>
            <h1>Blinking Text</h1>
            <hr>
            <applet code="Blink.class" width=300 height=100>
              <param name="legacy_lifecycle" VALUE="TRUE">
              <param name=lbl value="This is the next best thing to sliced bread! Toas
      t, toast, toast, butter, jam, toast, marmite, toast.">
                <param name=speed value="4">
                  alt="Your browser understands the &lt;APPLET&gt; tag but isn't runni
      ng the applet, for some reason."
                  Your browser is completely ignoring the &lt;APPLET&gt; tag!
            </applet>
        </body>
      </html>

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Unfortunately we have found no workaround so far...

      - With Firefox 2.0.0.18, we run into another problem where the plugin processing seems to just pause for several seconds before reloading the applet. We see these msgs and then the pause for 5-7 seconds

      basic: Stopping applet ...
      basic: Applet supports legacy lifecycle model - add applet to lifecycle cache

      This does not happen upon every refresh but frequently enough that we cannot use this FF version.

      - With JRE 1.5.0_14, we ran into a similar (or perhaps the same) timing problem with the lifecycle cache and ended up with two instances.

            kbr Kenneth Russell (Inactive)
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: