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

Parser used in HTMLEditorKit swallows last content

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6
    • client-libs

      FULL PRODUCT VERSION :
      java version "1.6.0"
      Java(TM) SE Runtime Environment (build 1.6.0-b105)
      Java HotSpot(TM) Client VM (build 1.6.0-b105, mixed mode, sharing)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows 2000 [Version 5.00.2195]

      A DESCRIPTION OF THE PROBLEM :
      After calling setText with result of getText on JEditorPane:
      jep.setText(jep.getText())

      The document/model has changed. It misses the last parts of the content.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the given code (in Java 1.4.2 / 5 / 6).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The "output after insertion A" should be the same as the "output after setting A".
      The "output after insertion B" should be the same as the "output after setting B".
      ACTUAL -
      In example A the table is missing.
      In example B the paragraph and a table cell is missing.

      REPRODUCIBILITY :
      This bug can be reproduced always.

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

      import javax.swing.JTextPane;
      import javax.swing.text.BadLocationException;
      import javax.swing.text.html.HTMLDocument;
      import javax.swing.text.html.HTMLEditorKit;

      public class TestHTMLParser {

      private static final String testHTML1 = "<TABLE BORDER=1><TR><TD></TD><TD></TD></TR></TABLE>";

      private static final String testHTML2 = "<TABLE BORDER=1><TR><TD></TD><TD></TD></TR></TABLE><P></P>";

      public static void main(String[] argv) throws BadLocationException, IOException {
      JTextPane jtp = new JTextPane();
      HTMLEditorKit edKit = new HTMLEditorKit();
      HTMLDocument htmlDoc;
      jtp.setEditorKit(edKit);

      htmlDoc = (HTMLDocument) edKit.createDefaultDocument();
      jtp.setDocument(htmlDoc);
      System.out.println("html output before insertion A");
      System.out.println(jtp.getText());
      System.out.println();
      edKit.insertHTML(htmlDoc, 0, testHTML1, 0, 0, null);
      System.out.println("html output after insertion A");
      System.out.println(jtp.getText());
      System.out.println();
      System.out.println("html output after setting A");
      jtp.setText(jtp.getText());
      System.out.println(jtp.getText());

      htmlDoc = (HTMLDocument) edKit.createDefaultDocument();
      jtp.setDocument(htmlDoc);
      System.out.println("html output before insertion B");
      System.out.println(jtp.getText());
      System.out.println();
      edKit.insertHTML(htmlDoc, 0, testHTML2, 0, 0, null);
      System.out.println("html output after insertion B");
      System.out.println(jtp.getText());
      System.out.println();
      System.out.println("html output after setting B");
      jtp.setText(jtp.getText());
      System.out.println(jtp.getText());
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      not known

            peterz Peter Zhelezniakov
            igor Igor Nekrestyanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: