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

LabelView's createFragment() and breakNew() methods throw NPE

XMLWordPrintable

    • 1.2.2
    • sparc
    • solaris_2.5



      Name: vsC58871 Date: 08/20/98


      com.sun.java.swing.text.LabelView's createFragment() and breakNew()
      methods throw NullPointerException.

      Here is the example demonstrating the bug:
      ----------------Test.java---------------------
      import java.awt.*;
      import com.sun.java.swing.text.*;

      public class Test {
          public static void main(String[] args){
      Element element = new StubElement("StubElement");
      LabelView lView = new LabelView(element);
      try {
      lView.createFragment(0,1);
      } catch (Throwable e) {
      e.printStackTrace();
      System.out.println();
      }
          }
      }

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

          public StubElement(String context) {
            this.context = context;
            attr = new SimpleAttributeSet();
            StyleConstants.setComponent( attr, new Label());
            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; }
      }

      -- The output ----------------
      #>java version "1.2fcs"
      Classic VM (build JDK-1.2fcs-F, green threads, sunwjit)
      #>JAVA_COMPILER=none java Test
      Warning: JIT compiler "none" not found. Will use interpreter.
      java.lang.NullPointerException
              at com.sun.java.swing.text.LabelView.syncFragments(LabelView.java:109)
              at
      com.sun.java.swing.text.LabelView.createFragment(LabelView.java:484)
              at Test.main(Test.java:9)
      ------------------------------
      BTW, where is syncFragments method spec?
      I can't find it nor in javadoc neither in sources. (jdk12-fcsF)

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

            svioletsunw Scott Violet (Inactive)
            vsizikov Vladimir Sizikov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: