groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Wagenleitner (JIRA)" <>
Subject [jira] [Created] (GROOVY-7816) ObservableList addAll method property change event index off by one
Date Fri, 15 Apr 2016 16:33:25 GMT
John Wagenleitner created GROOVY-7816:

             Summary: ObservableList addAll method property change event index off by one
                 Key: GROOVY-7816
             Project: Groovy
          Issue Type: Bug
          Components: groovy-jdk
    Affects Versions: 2.4.6
            Reporter: John Wagenleitner
            Priority: Minor

The {{ObservableList#addAll()}} method incorrectly calculates the index of the added elements.
 The elements are correctly appended to the list, but the property change event index value
does not point to the start of the appended elements but to the element just prior.

import java.beans.*

class MyListener implements PropertyChangeListener {
    PropertyChangeEvent event
    public void propertyChange(PropertyChangeEvent evt) {
        event = evt

ObservableList olist = new ObservableList()
def listener = new MyListener()
olist.addPropertyChangeListener(ObservableList.CONTENT_PROPERTY, listener)

assert listener.event.index == 0

assert listener.event.index == 1

assert listener.event.index == 2

listener.event = null  //clear event to make sure one fires for addAll
assert olist == ['one','two','three','four','five']
assert olist.get(3) == 'four'
assert listener.event.index == 3  // fails == 2

assert listener.event.index == 3  // passes

This message was sent by Atlassian JIRA

View raw message