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

REGRESSION:JLabel will not render HTML when reloading applet

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 6u22
    • Fix Version/s: 7
    • Component/s: deploy
    • Subcomponent:
    • CPU:
      x86
    • OS:
      linux_ubuntu, windows_xp

      Description

      FULL PRODUCT VERSION :
      java version "1.6.0_22"
      Java(TM) SE Runtime Environment (build 1.6.0_22-b04)
      Java HotSpot(TM) Server VM (build 17.1-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux **** 2.6.32-25-generic #45-Ubuntu SMP Sat Oct 16 19:48:22 UTC 2010 i686 GNU/Linux

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Webrowser is Firefox 3.6.11

      A DESCRIPTION OF THE PROBLEM :
      If multiple Swing-Applications run in a single JVM, like its very common in applet-environments, JLabels, that contain HTML texts will stop rendering, if AppContext changes (see more detailed description below).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a simple applet that renders HTML:

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

      public class Test extends JApplet {
      public void init() {
      getContentPane().setLayout(new FlowLayout());
      getContentPane().add(new JLabel("<html>A HTML label</html>"));
      getContentPane().add(new JLabel("and a plain label"));
      }
      }
      --

      Embed applet in a simple web page like this one:

      --
      <html>
      <body>
      <applet code="Test.class" width="250" height="30">
      <param name="classloader_cache" value="false" />
      </applet>
      </body>
      </html>
      --

      Open this page in a browser. A label will be rendered that says "A HTML label and a plain label". Now reload the page. The applet will restart (Important: caching is disabled) and the HTML label will not render anymore. The applet now says "and a plain label".

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      An applet saying "A HTML label and a plain label".
      ACTUAL -
      An applet saying "and a plain label".

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      /* Run as applet. See "Steps to reproduce" */

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

      public class Test extends JApplet {
      public void init() {
      getContentPane().setLayout(new FlowLayout());
      getContentPane().add(new JLabel("<html>A HTML label</html>"));
      getContentPane().add(new JLabel("and a plain label"));
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call the constructor from javax.swing.text.html.parser.ParserDelegator (see below)

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

      public class Test extends JApplet {
      public void init() {
      new javax.swing.text.html.parser.ParserDelegator(); // Workaround for BUG
      getContentPane().setLayout(new FlowLayout());
      getContentPane().add(new JLabel("<html>A HTML label</html>"));
      getContentPane().add(new JLabel("and a plain label"));
      }
      }

        Description:
      ----------------
      The second time the applet is started, it gets a new default AppContext assigned. Now the HTML parser, that actually parses the HTML from the JLabel.text relies on a property DTD_KEY, which must be set to the default DTD in the current AppContext. Since we have a new uninitialized AppContext by restarting the applet in the same JVM, the property is missing in AppContext.

      The parser fails with a NullPointerException thrown in javax.swing.text.html.Parser (line: 2039) which is swallowed in javax.swing.plaf.basic.BasicHTML (line: 46f) => catch (Throwable e) {}

      Calling the constructor from javax.swing.text.html.parser.ParserDelegator initializes the current AppContext with the needed default DTD.

      Please note that earlier releases did not suffer from this problem.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              ngthomas Thomas Ng (Inactive)
              Reporter:
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: