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

Element offsets need improved specification

XMLWordPrintable

    • beta
    • generic, sparc
    • generic, solaris_2.6



      Name: dsR10051 Date: 07/05/2000


      The method
      protected void loadChildren(ViewFactory f)
      of the javax.swing.text.ZoneView class
      throws unexpected ArrayIndexOutOfBoundsException
      if ZoneView is created by Element that has zero difference
      between getStartOffset() and getEndOffset().

      Here is a minimized test:
      import javax.swing.text.*;

      public class ZoneViewTest05 {
          public static void main (String[] args) {

              Element elem = new StubElement("");
              int axis = View.X_AXIS;
              StubZoneView zone = new StubZoneView(elem, axis);
              zone.loadChildren((ViewFactory) null);
          }
      }

      class StubElement implements Element {
          Document document = new DefaultStyledDocument();

          public StubElement(String context) {
              super();
              try {
                  document.insertString(0, context, new SimpleAttributeSet());
              } catch (BadLocationException e) {}
          }

          public Document getDocument() { return document; }
          public Element getParentElement() { return null; }
          public String getName() { return "StubElement"; }
          public AttributeSet getAttributes() { return new SimpleAttributeSet(); }
          public int getStartOffset() { return 0; }
          public int getEndOffset() { return document.getLength(); }
          public int getElementIndex(int offset) { return 0; }
          public int getElementCount() { return 1; }
          public Element getElement(int index) { return this; }
          public boolean isLeaf() { return true; }
      }

      class StubZoneView extends ZoneView {
        public StubZoneView (Element elem, int axis) {
          super (elem, axis);
        }
        public void loadChildren(ViewFactory f) {
          super.loadChildren(f);
        }
      }

      --- Output ---

      %/usr/local/java/jdk1.4/solaris/bin/java -version
      java version "1.4.0beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0beta-b21)
      Java HotSpot(TM) Client VM (build 1.3.0rc3-Z, interpreted mode)

      %/usr/local/java/jdk1.4/solaris/bin/java ZoneViewTest05
      Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
              at javax.swing.text.CompositeView.getView(CompositeView.java:146)
              at javax.swing.text.ZoneView.handleInsert(ZoneView.java:248)
              at javax.swing.text.ZoneView.loadChildren(ZoneView.java:218)
              at StubZoneView.loadChildren(ZoneViewTest05.java:40)
              at ZoneViewTest05.main(ZoneViewTest05.java:9)
      %


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

            tprinzing Tim Prinzing (Inactive)
            sdasunw Sda Sda (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: