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

TextComponent.getSelectedText() throws StringIndexOutOfBoundsException

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 17
    • 6
    • client-libs
    • b05
    • x86
    • generic

    Description

      The attached test throws the exception:

      java.lang.StringIndexOutOfBoundsException: String index out of range: 6
              at java.lang.String.substring(String.java:1777)
              at java.awt.TextComponent.getSelectedText(TextComponent.java:248)
              at Test.init(Test.java:15)
              at sun.applet.AppletPanel.run(AppletPanel.java:405)
              at java.lang.Thread.run(Thread.java:595)

      ---------------------SOURCE CODE---------------------

      import java.awt.*;

      public class Test
      {
          public static final void main(String args[]) {
              TextField tf = new TextField("text field");
              tf.setSelectionStart(6);
              tf.setText("text");
      String str = tf.getSelectedText();
          }
      }

      --------------------------------------------------------

      it's reproducible on all platforms using JDK7 b07.

      Attachments

        Issue Links

          Activity

            People

              serb Sergey Bylokhov
              dcherepanov Dmitry Cherepanov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: