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

BoxView's getResizeWeight() method throws NullPointerException

XMLWordPrintable

    • 1.2fcs
    • sparc
    • solaris_2.5
    • Verified



      Name: vsC58871 Date: 08/20/98


      com.sun.java.swing.text.BoxView's getResizeWeight() method
      throws NullPointerException.
      I believe that invocation of checkRequests() method at the
      beginning of getResizeWeight() body should fix this problem.

      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");
      BoxView bView = new BoxView(element, View.X_AXIS);
      try {
      bView.getResizeWeight(View.X_AXIS);
      } catch (Throwable e) {
      e.printStackTrace();
      }
          }
      }

      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_COMPILER=none java Test
      Warning: JIT compiler "none" not found. Will use interpreter.
      java.lang.NullPointerException
              at com.sun.java.swing.text.BoxView.getResizeWeight(BoxView.java:116)
              at Test.main(Test.java:10)
      ------------------------------

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

            tprinzing Tim Prinzing (Inactive)
            vsizikov Vladimir Sizikov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: