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

[macosx] HTMLDocument containing a table renders incorrectly.

    Details

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_65"
      Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Darwin cthulhu.local 13.3.0 Darwin Kernel Version 13.3.0: Tue Jun 3 21:27:35 PDT 2014; root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64

      A DESCRIPTION OF THE PROBLEM :
      I have a program which creates an HTMLDocument containing a table.

      With java version 1.7.0_55, the table renders correctly.
      With java version 1.7.0_60 or later - including the current released 1.7.0_65 and 1.8 - the table is duplicated and rendered incorrectly.

      REGRESSION. Last worked in version 7u55

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_65"
      Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      bash-3.2$ setjdk 1.7.0_65
      bash-3.2$ java -version
      java version "1.7.0_65"
      Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
      Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
      bash-3.2$ javac Test.java
      bash-3.2$ java Test

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      A frame will pop up titled "Test HTML Frame"

      In 1.7.0_55, there is an HTML table in it with three columns and three rows: one header row and two data rows.
      ACTUAL -
      A frame will pop up titled "Test HTML Frame"

      In 1.7.0_65, the aforementioned table is shown.
      It is followed by a duplicate of the same table and an additional table where each cell contains the cell data twice on separate lines.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.StringWriter;

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import javax.swing.text.Element;
      import javax.swing.text.html.HTMLDocument;
      import javax.swing.text.html.HTMLEditorKit;

      public abstract class Test
      {
      public static void generateRow( final StringBuilder buffer, final String tag, final String [] elts )
      {
      String open = "<" + tag + ">";
      String close = "</" + tag + ">";
      buffer.append( "<tr>" );
      for ( String elt : elts ) {
      buffer.append( open );
      buffer.append( elt );
      buffer.append( close );
      }
      buffer.append( "</tr>" );
      }

      public static void generateTable( final StringBuilder buffer )
      {
      buffer.append( "<table border=1>" );
      Test.generateRow( buffer, "th", new String[] { "Column 1", "Column 2", "Column 3" } );
      Test.generateRow( buffer, "td", new String[] { "abc", "def", "ghi" } );
      Test.generateRow( buffer, "td", new String[] { "123", "456", "789" } );
      buffer.append( "</table>" );
      }

      public static String generateHTML()
      {
      StringBuilder buffer = new StringBuilder();
      Test.generateTable( buffer );
      return buffer.toString();
      }

      private static void printHTML( final HTMLDocument doc )
              {
      HTMLEditorKit kit = new HTMLEditorKit();
      StringWriter writer = new StringWriter();
      try
      {
      kit.write(writer, doc, 0, doc.getLength());
      }
      catch ( Exception e )
      {
      }
      String s = writer.toString();
      System.out.println( "New HTML = \"" + s + "\"" );
      }

      private static void createAndShowGUI()
              {
      // Create and set up the window.

      JFrame frame = new JFrame();
      frame.setTitle( "Test HTML Frame" );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

      Container contents = frame.getContentPane();

      JEditorPane pane = new JEditorPane();
      pane.setContentType( "text/html" );
      pane.setEditable( false );

      HTMLDocument currentHTML = (HTMLDocument) pane.getDocument();

      // Test.printHTML( currentHTML );

      Element contentElement = currentHTML.getDefaultRootElement();
      while ( !contentElement.isLeaf() ) {
      contentElement = contentElement.getElement( contentElement.getElementCount() - 1 );
      }

      String text = Test.generateHTML();
      try
      {
      currentHTML.insertAfterEnd( contentElement, text );
      }
      catch ( Exception e )
      {
      }

      // Test.printHTML( currentHTML );

      contents.add( pane, BorderLayout.CENTER );

      //Display the window.
      frame.pack();
      frame.setVisible(true);
      }

      /**
      * The main method.
      */

      public static final void main( final String[] args )
      {
      javax.swing.SwingUtilities.invokeLater(
      new Runnable() {
      public void run() {
      createAndShowGUI();
      }
      } );

      while (true ) {
      try
      {
      Thread.sleep( 1000 );
      }
      catch ( InterruptedException e )
      {
      break;
      }
      }
      }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      None found.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmarkov Dmitry Markov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: