TextComponent.getSelectedText() throws StringIndexOutOfBoundsException

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P4
    • 17
    • Affects Version/s: 6
    • Component/s: client-libs
    • b05
    • x86
    • generic

      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.

            Assignee:
            Sergey Bylokhov
            Reporter:
            Dmitry Cherepanov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: