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

swing.text.ZoneView.loadChildren() method throws unexpected NPE

XMLWordPrintable



      Name: aaR10142 Date: 09/04/2000


      swing.text.ZoneView.loadChildren() method throws unexpected NullPointerException

      All works correctly in jdk1.3
      See example

      ------------------------- example ----------------
      import javax.swing.text.*;

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

              Element elem = new StubElement("");
              Element elem2 = new StubElement("");
              int axis = View.X_AXIS;
              ZoneView zone = new ZoneView(elem, axis);

              // setParent() calls the loadChildren() method
              zone.setParent(new ZoneView(elem2, axis));

              System.out.println("Ok");
          }
      }

      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; }
      }

      ------------------------- jdk1.4 output ----------------
      Exception in thread "main" java.lang.NullPointerException
              at javax.swing.text.ZoneView$Zone.loadChildren(ZoneView.java:428)
              at javax.swing.text.AsyncBoxView.setParent(AsyncBoxView.java:459)
              at javax.swing.text.CompositeView.replace(CompositeView.java:197)
              at javax.swing.text.BoxView.replace(BoxView.java:150)
              at javax.swing.text.View.append(View.java:417)
              at javax.swing.text.ZoneView.loadChildren(ZoneView.java:217)
              at javax.swing.text.CompositeView.setParent(CompositeView.java:125)
              at Test.main(Test.java:12)
      ------------------------- jdk1.3 output ----------------
      Ok

      See JCK tests
      api/javax_swing/text/ZoneView/index.html#misc
      for more failures

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

            svioletsunw Scott Violet (Inactive)
            alisunw Ali Ali (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: