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

                 Key: PIVOT-814
                 URL: https://issues.apache.org/jira/browse/PIVOT-814
             Project: Pivot
          Issue Type: Bug
          Components: wtk
    Affects Versions: 2.0.1
            Reporter: Bill van Melle
            Priority: Minor


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>


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to