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

javax.swing.text.Highlighter.changeHighlight() doesn't throw BadLocationException when expected

XMLWordPrintable

      Spec for javax.swing.text.changeHighlight(Object, int , int ) says:
      "@exception BadLocationException for an invalid range specification"

      Exception is not always throw when expected.

      Platform: Windows, Solaris
      JCK: runtime 7 b03
      JDK: 6, 7

      The following test fails:
      api/javax_swing/text/Highlighter/index.html#Highlighter[Highlighter006]

      Please see code extract from the test:
      -----
      import javax.swing.*;
      import javax.swing.text.BadLocationException;
      import javax.swing.text.Highlighter;
      import javax.swing.text.JTextComponent;
      import java.awt.*;

      public class H006 {

          private static void runTest() {
              JFrame jFrame = new JFrame();
              JTextArea textArea = new JTextArea("Tested string");
              jFrame.getContentPane().add(textArea);
              jFrame.setVisible(true);
              Highlighter highlighter = textArea.getHighlighter();
              Highlighter.HighlightPainter myPainter = new Highlighter.HighlightPainter() {
                  public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {}
              };

              int negativeTestedData[][] = {{50, 0}, {-1, 1}, {-5, -4},
                                            {Integer.MAX_VALUE, Integer.MIN_VALUE},
                                            {Integer.MIN_VALUE, Integer.MAX_VALUE},
                                            {Integer.MIN_VALUE, Integer.MIN_VALUE}};
              String errorMessage4Negative = "";
              for (int i = 0; i < negativeTestedData.length; i++) {
                  try {
                      Object objRef = highlighter.addHighlight(0, 1, myPainter);
                      highlighter.changeHighlight(objRef, negativeTestedData[i][0], negativeTestedData[i][1]);
                  } catch (BadLocationException e) {
                      continue;
                  }
                  errorMessage4Negative += "(" + negativeTestedData[i][0] + ", " + negativeTestedData[i][1] + ") ";
              }

              System.out.println("Method addHighlight() does not throw BadLocationException for \n" + errorMessage4Negative + ".");
              jFrame.dispose();
          }

          public static void main(String[] args) throws Exception {
              SwingUtilities.invokeLater(new Runnable() {
                  public void run() {
                      runTest();
                  }
              });
          }
      }
      -----

            gsm Sergey Groznyh (Inactive)
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: