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

JLabel has classcast exception when given html text that contains a <script> tag

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 6
    • 1.4.2
    • client-libs
    • beta
    • x86
    • linux

      Name: gm110360 Date: 03/26/2004


      FULL PRODUCT VERSION :
      Linux:
                  java version "1.4.2"
                 Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.
                 Java HotSpot(TM) Client VM (build 1.4.2-b28, mixed mode)

      Mac OS X:
                  java version "1.3.1"
                 Java(TM) 2 Runtime Environment, Standard Edition (build
                 1.3.1-root_1.3.1_020714-12:46)
                 Java HotSpot(TM) Client VM (build 1.3.1_03-69, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux mushnik.library.arizona.edu 2.4.20-30.9 #1 Wed Feb 4 20:45:39 EST 2004 i686 athlon i386 GNU/Linux

      (have also seen this on Mac OS X)

      A DESCRIPTION OF THE PROBLEM :
      Whenever setText is called on a JLabel with html text that contains a <script> tag, a ClassCastException is thrown.



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a JLabel somewhere and pass it html text that contains a script tag.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Clearly I don't expect the renderer to interpret javascript, but not throwing an exception and simply ignoring the <scrtipt> tags would be nice!
      ACTUAL -
      Exception gets thrown, program flow is interrupted.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.lang.ClassCastException
              at javax.swing.text.html.EditableView.setParent(EditableView.java:88)
              at javax.swing.text.CompositeView.replace(CompositeView.java:200)
              at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
              at javax.swing.text.FlowView$LogicalView.loadChildren(FlowView.java:648)
              at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
              at javax.swing.text.FlowView.loadChildren(FlowView.java:120)
              at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
              at javax.swing.text.html.ParagraphView.setParent(ParagraphView.java:58)
              at javax.swing.text.CompositeView.replace(CompositeView.java:200)
              at javax.swing.text.BoxView.replace(BoxView.java:164)
              at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
              at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
              at javax.swing.text.html.BlockView.setParent(BlockView.java:55)
              at javax.swing.text.html.HTMLEditorKit$HTMLFactory$BodyBlockView.setParent(HTMLEditorKit.java:1266)
              at javax.swing.text.CompositeView.replace(CompositeView.java:200)
              at javax.swing.text.BoxView.replace(BoxView.java:164)
              at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
              at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
              at javax.swing.text.html.BlockView.setParent(BlockView.java:55)
              at javax.swing.plaf.basic.BasicHTML$Renderer.<init>(BasicHTML.java:283)
              at javax.swing.plaf.basic.BasicHTML.createHTMLView(BasicHTML.java:47)
              at javax.swing.plaf.basic.BasicHTML.updateRenderer(BasicHTML.java:80)
              at javax.swing.plaf.basic.BasicLabelUI.propertyChange(BasicLabelUI.java:384)
              at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:264)
              at javax.swing.event.SwingPropertyChangeSupport.firePropertyChange(SwingPropertyChangeSupport.java:232)
              at javax.swing.JComponent.firePropertyChange(JComponent.java:3822)
              at javax.swing.JLabel.setText(JLabel.java:303)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;
      /**
       *
       * @author dmandel
       */
      public class TestFrame extends JFrame {
          
          /** Creates a new instance of TestFrame */
          public TestFrame() {
              super();
              JLabel label = new JLabel("<html>this is a <script>");
              getContentPane().add(label);
              show();
              pack();
          }
          
          public static void main(String[] args) {
              TestFrame frame = new TestFrame();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Remove <script> tags from the html before calling setText() on the JLabel. Clearly not tooo terribly difficult, but an annoyance nonetheless.
      (Incident Review ID: 245142)
      ======================================================================
      ###@###.### 10/13/04 17:47 GMT

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

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: