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

text.TableView.TableRow.replace(int, int, View[]) does not check params

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.5.1



      Name: akC57697 Date: 05/17/99



      This bug was found by St.Petersburg Java SQE team (by Sergey Scherbakov).
       In JDK 1.2.2 method TableView.TableRow.replace(int, int, View[]) throws
      NullPointerException (does not check params).
      The example:
      --------------------------------------------------------------------------------------------------------------------------
      import javax.swing.text.TableView;

      import java.io.*;
      import javax.swing.text.Element;
      import javax.swing.text.LabelView;
      import javax.swing.text.View;
      import javax.swing.text.AttributeSet;
      import javax.swing.text.SimpleAttributeSet;
      import javax.swing.text.Document;
      import javax.swing.text.DefaultStyledDocument;
      import javax.swing.text.StyleConstants;
      import javax.swing.ImageIcon;
      import javax.swing.text.BadLocationException;

      public class Test {

          public static void main(String argv[]) {

              TableView.TableRow c2 =
                      new StubTableView(new StubElement("text")).
                      new TableRow(new StubElement("text"));

              View[] views = { new LabelView(new StubElement("text 1")),
                  new LabelView(new StubElement("text 2")),
                  new LabelView(new StubElement("text 3")),
                  new LabelView(new StubElement("text 4"))
              };

              View[] rviews = { new LabelView(new StubElement("text 5")),
                  new LabelView(new StubElement("text 6")),
                  new LabelView(new StubElement("text 7")),
                  new LabelView(new StubElement("text 8"))
              };

              for (int i = 0; i < views.length; i++) {
                  c2.append(views[i]);
              }

              c2.replace(c2.getViewCount()-2, rviews.length, rviews);
          }
      }

      class StubElement implements Element {
          Document document = new DefaultStyledDocument();
          SimpleAttributeSet attr;
          String context;

          public StubElement(String context) {
              this.context = context;
              attr = new SimpleAttributeSet();
              StyleConstants.setIcon( attr, new ImageIcon());
              document = new DefaultStyledDocument();
              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 attr;
          }
          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 StubTableView extends TableView {
          public StubTableView(Element elem) {
              super( elem);
          }
      }
      --------------------------------------------------------------------------------------------------------------------------
      Output :
      Exception in thread "main" java.lang.NullPointerException

              at javax.swing.text.CompositeView.replace(CompositeView.java, Compiled
      Code)
              at javax.swing.text.BoxView.replace(BoxView.java, Compiled Code)
              at javax.swing.text.TableView$TableRow.replace(TableView.java, Compiled
      Code)
              at Test.main(Test.java, Compiled Code)
      ======================================================================

            tprinzing Tim Prinzing
            akuzminorcl Alexander Kuzmin (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: