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

swing.text.Utilities.getWord[Start|End]() throw unexpected NPE

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.6



      Name: asC58863 Date: 06/10/99


      swing.text.Utilities.getWordStart() and swing.text.Utilities.getWordEnd()
      throw NPE when invalid offset specified.

      (See JavaDoc comments)
      "public static final int getWordStart(JTextComponent c,
                                           int offs)
                                    throws BadLocationException
      [...]
           Parameters:
               c - the editor
               offs - the offset in the document >= 0
           Throws:
               BadLocationException - if the offset is out of range
      "

      So BadLocationException should be thrown instead of NPE if the offset
      is out of range.

      Here is the example demonstrating the bug:
      ------------------ Test.java -----------------
      import javax.swing.text.BadLocationException;
      import javax.swing.text.JTextComponent;
      import javax.swing.text.Utilities;
      import javax.swing.JTextArea;

      class Test {

          public static void main(String[] argv) {
              JTextComponent comp = new JTextArea( "Document text");

              try {
                  Utilities.getWordStart( comp, 120);
                  System.out.println(" NPE has not been thrown");
              } catch(BadLocationException ble) {
                  System.out.println(" Exception "+ble);
              } catch(NullPointerException npe) {
                  System.out.println(" Unexpected NPE has been thrown ");
                  npe.printStackTrace();
              }
              System.exit(0);
          }
      }
      -------------- Output from the test -----------------
      java full version "JDK-1.3-F"
       Unexpected NPE has been thrown
      java.lang.NullPointerException
              at javax.swing.text.Utilities.getWordStart(Utilities.java, Compiled
      Code)
              at Test.main(Test.java, Compiled
      Code)
      ------------------------------------------------------

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

            tprinzing Tim Prinzing (Inactive)
            anssunw Ans Ans (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: