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

[macosx] HTMLDocument cannot insert line beginning with a /

    XMLWordPrintable

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 an HTMLDocument.
      I append lines, one after the other, into it.
      A line that starts with a "/" character is suppressed, up to the first tag.
      For example, the following:

      Test1.insertHTML( doc, "Line 1<br>" );
      Test1.insertHTML( doc, "Line 2/<br>" );
      Test1.insertHTML( doc, "/Line 3<br>" );
      Test1.insertHTML( doc, "Line/ 4<br>" );

      results in the following:

      Line1<br>Line2/<br><br>Line/ 4<br>

      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 Test1.java
      bash-3.2$ java Test1

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expect a Frame to pop up containing 4 lines with the specified text.
      ACTUAL -
      A Frame pops up with 4 lines, but the line that started with a / is blank.

      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 Test1
      {
      private static void insertHTML( final HTMLDocument doc, final String text )
              {
      Element contentElement = doc.getDefaultRootElement();
      while ( !contentElement.isLeaf() ) {
      contentElement = contentElement.getElement( contentElement.getElementCount() - 1 );
      }

      try
      {
      doc.insertAfterEnd( contentElement, text );
      }
      catch ( Exception e )
      {
      }
      }

      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( "Test1 HTML Frame" );
      frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );

      Container contents = frame.getContentPane();

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

      HTMLDocument doc = (HTMLDocument) pane.getDocument();
      Test1.insertHTML( doc, "Line 1<br>" );
      Test1.insertHTML( doc, "Line 2/<br>" );
      Test1.insertHTML( doc, "/Line 3<br>" );
      Test1.insertHTML( doc, "Line/ 4<br>" );
      // Test1.printHTML( doc );

      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 :
      I can wrap the text in <span></span>

      Attachments

        Activity

          People

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: