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

HTMLDocument.insertBeforeEnd doesn't work when passed a body element

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P5 P5
    • 5.0
    • 1.3.1
    • client-libs
    • tiger
    • x86
    • linux



      Name: boT120536 Date: 08/27/2001


      java version "1.3.1"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.1-b24)
      Java HotSpot(TM) Client VM (build 1.3.1-b24, mixed mode)


      javax.swing.text.html.HTMLDocument.insertAfterStart works when passed a body
      element, but javax.swing.text.html.HTMLDocument.insertBeforeEnd does not.

      Here is code to demonstrate the problem:

      class InsertTest {
          public static void main(String[] args) {
              javax.swing.text.html.HTMLDocument doc = new
      javax.swing.text.html.HTMLDocument();
              javax.swing.text.Element html = doc.getRootElements()[0];
              javax.swing.text.Element body = html.getElement(0);
              doc.setParser(new javax.swing.text.html.parser.ParserDelegator());

              System.out.println("html name: " + html.getName());
              System.out.println("body name: " + body.getName());


              try {
                  doc.insertAfterStart(body, "<h2>foo</h2>");
              } catch (Exception e) {
                  System.err.println("error in insertAfterStart");
                  e.printStackTrace(System.err);
             }

              try {
                  doc.insertBeforeEnd(body, "<h2>bar</h2>");
              } catch (Exception e) {
                  System.err.println("error in insertBeforeEnd");
                  e.printStackTrace(System.err);
              }
          }
      }

      Steps to reporoduce:

      [mskinner@isera SQLEdit]$ javac InsertTest.java
      [mskinner@isera SQLEdit]$ java InsertTest
      html name: html
      body name: body
      error in insertBeforeEnd
      javax.swing.text.BadLocationException: Invalid insert
      at javax.swing.text.GapContent.insertString(GapContent.java:112)
      at javax.swing.text.DefaultStyledDocument.insert(DefaultStyledDocument.java:187)
      at javax.swing.text.html.HTMLDocument.insert(HTMLDocument.java:212)
      at javax.swing.text.html.HTMLDocument$HTMLReader.flushBuffer(HTMLDocument.java:3014)
      at javax.swing.text.html.HTMLDocument$HTMLReader.flush(HTMLDocument.java:1921)
      at javax.swing.text.html.HTMLDocument.insertHTML(HTMLDocument.java:1027) at javax.swing.text.html.HTMLDocument.insertBeforeEnd(HTMLDocument.java:841)
      at InsertTest.main(InsertTest.java:20)
      (Review ID: 130688)
      ======================================================================

            peterz Peter Zhelezniakov
            bonealsunw Bret O'neal (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: