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

AbstractDocument.AbstractElement c-tor throws StateInvariantError

XMLWordPrintable

    • sparc
    • solaris_2.5.1



      Name: akC57697 Date: 12/21/98



       The AbstractDocument.AbstractElement c-tor AbstractElement(Element parent, AttributeSet a)
       throws StateInvariantError when invoke addAttributes(a)

      The javadoc says:

      Implements the abstract part of an element. By default elements
      support attributes by having a field that
      represents the immutable part of the current attribute
      set for the element. The element itself implements
      MutableAttributeSet which can be used to modify the
      set by fetching a new immutable set. The immutable sets
      are provided by the AttributeContext associated with the
      document.

      The JCK12-a tests passed under JDK1.2fcsV but fail under JDK1.2.2A


      1365a1366,1367
      > attributes = (a != null) ? a.copyAttributes() :
      > getAttributeContext().getEmptySet();
      1367,1369d1368
      < attributes = getAttributeContext().getEmptySet();
      < if (a != null) {
      < addAttributes(a);


      The short example:
      --------------------------------8-<----------------------------------------
      import javax.swing.text.*;
      public class Test {
          public static void main(String[] argv) {
              try {
                  DefaultStyledDocument doc = new DefaultStyledDocument();
                  doc.insertString(0, "The test text.", null);
                  // Consists of one paragraph
                  // Create Element object with some attribute
                  Element elem = doc.getCharacterElement(1);
                  AttributeSet orig_attr = elem.getAttributes();
                  // Create parent Element for clone
                  Element parent = doc.getCharacterElement(2);
                  DefaultStyledDocument.ElementBuffer eb = doc.new
                          ElementBuffer(elem);
                  Element result = eb.clone(parent, elem);
                  System.out.println("OKAY");
              } catch (Throwable e) {
                  e.printStackTrace();
              }
          }
      }
      --------------------------------8-<----------------------------------------

      Output:
      (###@###.###): java Test
      javax.swing.text.StateInvariantError: Illegal cast to MutableAttributeSet
      at javax.swing.text.AbstractDocument$AbstractElement.checkForIllegalCast(Compiled Code)
      at javax.swing.text.AbstractDocument$AbstractElement.addAttributes(Compiled Code)
      at javax.swing.text.AbstractDocument$AbstractElement.<init>(Compiled Code)
      at javax.swing.text.AbstractDocument$LeafElement.<init>(Compiled Code)
      at javax.swing.text.AbstractDocument.createLeafElement(Compiled Code)
      at javax.swing.text.DefaultStyledDocument$ElementBuffer.clone(Compiled Code)
      at Test.main(Compiled Code)
      (###@###.###): jdk1.2
      (###@###.###): java Test
      OKAY


      ======================================================================

            svioletsunw Scott Violet (Inactive)
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: