Pivot
  1. Pivot
  2. PIVOT-814

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

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: 2.0.1
    • Component/s: wtk
    • Labels:
      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>

        Activity

        Bill van Melle created issue -
        Sandro Martini made changes -
        Field Original Value New Value
        Assignee Noel Grandin [ grandinj ]
        Fix Version/s 2.0.1 [ 12315951 ]
        Affects Version/s 2.0 [ 12313780 ]
        Affects Version/s 2.0.1 [ 12315951 ]
        Noel Grandin made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Noel Grandin
            Reporter:
            Bill van Melle
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development