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

HTML renderer fails on empty cellpadding value and chars before title tag

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 5.0
    • 1.4.1
    • client-libs
    • tiger
    • x86
    • linux



      Name: jk109818 Date: 04/08/2003


      FULL PRODUCT VERSION :
      java version "1.4.1_02"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_02-b06)
      Java HotSpot(TM) Client VM (build 1.4.1_02-b06, mixed mode)

      Also tested with 1.4.1_01

      FULL OS VERSION :
      Linux balin 2.4.18-k7 #1 Sun Apr 14 13:19:11 EST 2002 i686 unknown unknown GNU/Linux (Debian 3.0 (Woody))
      Microsoft Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      If the following html is parsed a NullPointerException will be thrown!

      <table border="0" cellpadding="" cellspacing="0">
        <tr>
          <td>Hello World</td>
        </tr>
      </table>

      This is because the cellpadding attribute has an empty value. The cellspacing and border attributes can have an empty value without any problems.

      Another html string that fails:

      <head>
      a<title>Hello World</title>
      </head>

      This causes the renderer to throw a ClassCastException. Any letters before the title tag will cause this.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Parse any html with either of the examples mentioned in the description!

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      A parsed html string.
      Fails with an exception.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      First exception:

      Exception in thread "main" java.lang.NullPointerException
              at java.util.Hashtable.put(Hashtable.java:389)
              at javax.swing.text.SimpleAttributeSet.addAttribute(SimpleAttributeSet.java:176)
              at javax.swing.text.html.CSS.translateHTMLToCSS(CSS.java:687)
              at javax.swing.text.html.StyleSheet.translateHTMLToCSS(StyleSheet.java:494)
              at javax.swing.text.html.StyleSheet$ViewAttributeSet.<init>(StyleSheet.java:2479)
              at javax.swing.text.html.StyleSheet.getViewAttributes(StyleSheet.java:312)
              at javax.swing.text.html.BlockView.getAttributes(BlockView.java:275)
              at javax.swing.text.html.StyleSheet$ViewAttributeSet.getResolveParent(StyleSheet.java:2612)
              at javax.swing.text.html.StyleSheet$ViewAttributeSet.doGetAttribute(StyleSheet.java:2592)
              at javax.swing.text.html.StyleSheet$ViewAttributeSet.getAttribute(StyleSheet.java:2572)
              at javax.swing.text.StyleConstants.getAlignment(StyleConstants.java:709)
              at javax.swing.text.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:104)
              at javax.swing.text.html.ParagraphView.setPropertiesFromAttributes(ParagraphView.java:87)
              at javax.swing.text.html.ParagraphView.setParent(ParagraphView.java:60)
              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.CompositeView.replace(CompositeView.java:200)
              at javax.swing.text.BoxView.replace(BoxView.java:164)
              at javax.swing.text.html.TableView$RowView.replace(TableView.java:1369)
              at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
              at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
              at javax.swing.text.CompositeView.replace(CompositeView.java:200)
              at javax.swing.text.BoxView.replace(BoxView.java:164)
              at javax.swing.text.html.TableView.replace(TableView.java:845)
              at javax.swing.text.CompositeView.loadChildren(CompositeView.java:97)
              at javax.swing.text.CompositeView.setParent(CompositeView.java:122)
              at javax.swing.text.html.TableView.setParent(TableView.java:749)
              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:1261)
              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 htmlbug.<init>(htmlbug.java:11)
              at htmlbug.main(htmlbug.java:21)


      Second exception:

      Exception in thread "main" 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:607)
              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:1261)
              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 htmlbug.<init>(htmlbug.java:11)
              at htmlbug.main(htmlbug.java:21)

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;

      public class htmltest {

          public htmltest() {
      JLabel dummyComponent = new JLabel("dummy");
      //String text = "a<title>Hello World</title>"; // ClassCastException
      //String text = "<title>Hello World</title>"; // Works
      //String text = "<table border='' cellpadding='0' cellspacing=''><tr><td>Hello World</td></tr></table>"; // Works
      //String text = "<table border='0' cellpadding='' cellspacing='0'><tr><td>Hello World</td></tr></table>"; // NullPointerException
      String text = "<table border='0' cellpadding= cellspacing='0'><tr><td>Hello World</td></tr></table>"; // NullPointerException
      javax.swing.text.Document doc = ((javax.swing.text.View)javax.swing.plaf.basic.BasicHTML.createHTMLView(dummyComponent, text)).getDocument();
      try {
      text = doc.getText(0,doc.getLength());
      } catch (Exception ex) {
      System.out.println(ex);
      }
      System.out.println("Text: "+text);
          }

          public static void main(String[] args) throws Exception {
              new htmltest();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None, except removing the problematic tags / attributes from the html.
      (Review ID: 183345)
      ======================================================================

            peterz Peter Zhelezniakov
            jkimsunw Jeffrey Kim (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: