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

javax.swing.text.NavigationFilter.getNextVisualPositionFrom() not always throws BadLocationException

XMLWordPrintable

      Method: javax.swing.text.NavigationFilter.getNextVisualPositionFrom(..) doesn't throw declared BadLocationException when unexisting location is passed in.

      Specification for BadLocationException states:
      "This exception is to report bad locations within a document model (that is, attempts to reference a location that doesn't exist)."

      The following code snippet expects BadLocationException for all valid SwingConstants, but it's not always being thrown.

      -----
      import javax.swing.*;
      import javax.swing.text.NavigationFilter;
      import javax.swing.text.Position;
      import javax.swing.text.BadLocationException;

      public class NF0006Snippet {

          public static void main(String[] args) throws BadLocationException, InterruptedException {

              JFormattedTextField jtf = new JFormattedTextField();
              NavigationFilter nf = new NavigationFilter();
              jtf.setText("A text message");

              JFrame jFrame = new JFrame();
              jFrame.getContentPane().add(jtf);
              jFrame.pack();
              jFrame.setVisible(true);

              Position.Bias[] biasRet = {Position.Bias.Forward};
              
              for (int swingConstant : new int[]{
                      SwingConstants.EAST,
                      SwingConstants.WEST,
                      // the following constants still will lead to "BadLocationException: Length must be positive"
                      // SwingConstants.SOUTH,
                      // SwingConstants.NORTH,
                      }) {
                  for (int position : new int[] {-100, Integer.MIN_VALUE} ) {
                      nf.getNextVisualPositionFrom(jtf, position, Position.Bias.Backward, swingConstant, biasRet);
                      nf.getNextVisualPositionFrom(jtf, position, Position.Bias.Forward, swingConstant, biasRet);
                  }
              }
              jFrame.dispose();
          }
      }

      -----


      JCK-runtime-7 b03
      JDK 7 b30
      Platform: Windows, Solaris

      The following JCK test fails due to this problem:

      api/javax_swing/text/NavigationFilter/index.html#Methods[NavigationFilter0006]

      http://moonblade.russia.sun.com/set/java/jck/qa-results/jck/7/ea/b03/results/qac/m002_b30_failed_c1/solaris-amd64-080723150835/execdata/jtwork/report/filtered/newFailedTestCases.html

            rupashka Pavel Porvatov (Inactive)
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: