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

BadLocationException is not thrown by javax.swing.text.View.getNextVisualPositionFrom() for invalid positions

    XMLWordPrintable

Details

    Backports

      Description

        This issue appeared after fixing JCK-7301914 (which itself appeared due to the spec update in JDK-7016396)

        The spec
        http://docs.oracle.com/javase/8/docs/api/javax/swing/text/View.html#getNextVisualPositionFrom-int-javax.swing.text.Position.Bias-java.awt.Shape-int-javax.swing.text.Position.Bias:A-
        says:

        "BadLocationException - the given position is not a valid position within the document"

        However for positions larger than the siaze of the document BLE is not thrown.

        Please consider the following code:

        --------------------------------------------------------------
        package temp;

        import javax.swing.*;
        import javax.swing.text.*;
        import java.awt.*;

        public class BLE {
            public static void main(String[] args) throws BadLocationException {
                SwingUtilities.invokeLater(() -> {
                    JFormattedTextField jtf = new JFormattedTextField();
                    NavigationFilter nf = new NavigationFilter();
                    jtf.setText("Test for Tests");
                    JFrame jf = new JFrame();
                    jf.getContentPane().add(jtf);
                    jf.pack();
                    jf.setVisible(true);
                    Graphics g = jf.getGraphics();
                    jf.paint(g);
                    Position.Bias[] biasRet = {Position.Bias.Forward};
                    try {
                        nf.getNextVisualPositionFrom(jtf, 500, Position.Bias.Backward, SwingConstants.EAST,biasRet);
                        nf.getNextVisualPositionFrom(jtf, Integer.MAX_VALUE, Position.Bias.Forward, SwingConstants.EAST,biasRet);
                    } catch (BadLocationException e) {
                        e.printStackTrace();
                    }
                });
            }
        }
        --------------------------------------------------------------

        No BadLocationException is thrown.

        In addition to this there is a problem with the spec for the following method
        http://docs.oracle.com/javase/8/docs/api/javax/swing/text/NavigationFilter.html#getNextVisualPositionFrom-javax.swing.text.JTextComponent-int-javax.swing.text.Position.Bias-int-javax.swing.text.Position.Bias:A-


        BadLocationException is present but not described.

        The following test fails due to this problem

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

        Attachments

          Issue Links

            Activity

              People

                alexsch Alexandr Scherbatiy
                dbessono Dmitry Bessonov
                Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: