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

text.html.ParagraphView.getPreferredSpan() throws unexpected NPE

XMLWordPrintable



      Name: aaC67449 Date: 02/07/2000



      In Kestrel text.html.ParagraphView.getPreferredSpan() throws unexpected NPE.
      The methods getPreferredSpan(), getMinimumSpan(), getMaximumSpan() are using a
      method isVisible(),
      and the method isVisible() throws NullPointerException.


      The example:
      -------------------------------------------------------------------------------------

      import javax.swing.text.html.HTMLEditorKit;
      import javax.swing.text.html.HTMLDocument;
      import javax.swing.text.html.ParagraphView;
      import javax.swing.text.View;
      import javax.swing.text.Element;
      import java.io.StringReader;

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

          String test="<HTML><TITLE>test</TITLE><BODY><P>test</P></BODY></HTML>";

          HTMLEditorKit c = new HTMLEditorKit();
          HTMLDocument doc = null;

          try {
              doc = new HTMLDocument();
              c.read(new StringReader(test),doc,0);
          } catch(Exception e) {
          }

          Element elem = doc.getDefaultRootElement().getElement(1).getElement(0);
          ParagraphView bv = new ParagraphView(elem);

          System.out.println(elem);
          System.out.println("----------------------------");

          if (bv.getPreferredSpan(View.X_AXIS)!=0) {
              System.out.println("OK");
          }

          }
      }

      --------------------------------------------------------------------------------------------------------------------------

      Output :
      BranchElement(p) 3,8

      ----------------------------
      Exception in thread "main" java.lang.NullPointerException
              at
      javax.swing.text.ParagraphView.getLayoutViewCount(ParagraphView.java:112)
              at javax.swing.text.html.ParagraphView.isVisible(ParagraphView.java:160)

              at
      javax.swing.text.html.ParagraphView.getPreferredSpan(ParagraphView.java:222)
              at Test.main(Test.java:28)

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

            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: