Uploaded image for project: 'Pivot'
  1. Pivot
  2. PIVOT-814

TextArea#getText throws IndexOutOfBoundsException when called from TextChanged method under setText

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.0
    • 2.0.1
    • wtk
    • None

    Description

      Within the textChanged listener on my TextArea, I (naturally) call getText. This works fine if textChanged was called as a result of typing into the TextArea. But if it was fired because of a call to setText elsewhere in my program, getText throws IndexOutOfBoundsException. The stack looks like this:

      ArrayList<T>.verifyIndexBounds(int, int, int) line: 577
      ArrayList<T>.get(int) line: 346
      TextArea.getParagraphAt(int) line: 853
      TextArea.getText(int, int) line: 632
      TextArea.getText() line: 606
      <mycode>$2.textChanged(TextArea) line: 122
      TextArea$TextAreaContentListenerList.textChanged(TextArea) line: 518
      TextArea$ParagraphSequence.remove(int, int) line: 421
      TextArea.setText(Reader) line: 722
      TextArea.setText(String) line: 667

      My workaround is to check for getCharacterCount() being positive before calling getText.

      Here's a test case:

      <Window title="Empty text area bug" maximized="true"
      xmlns:bxml="http://pivot.apache.org/bxml"
      xmlns="org.apache.pivot.wtk">
      <BoxPane orientation="vertical" styles="

      {fill:true}

      ">
      <PushButton buttonData="Set text">
      <buttonPressListeners>
      function buttonPressed(button)

      { textArea.setText("This is some text"); }

      </buttonPressListeners>
      </PushButton>
      <TextArea bxml:id="textArea">
      <textAreaContentListeners>
      function textChanged(textArea)

      { importPackage(org.apache.pivot.wtk); Alert.alert(MessageType.INFO, "Text is " + textArea.getText(), textArea.getWindow()); }

      </textAreaContentListeners>
      </TextArea>
      </BoxPane>
      </Window>

      Attachments

        Activity

          People

            grandinj Noel Grandin
            bvanmelle Bill van Melle
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: