Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-7816

ObservableList addAll method property change event index off by one

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.4.6
    • 2.4.7
    • groovy-jdk
    • None

    Description

      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)
      
      olist.add('one')
      assert listener.event.index == 0
      
      olist.add('two')
      assert listener.event.index == 1
      
      olist.add('three')
      assert listener.event.index == 2
      
      listener.event = null  //clear event to make sure one fires for addAll
      olist.addAll(['four','five'])
      assert olist == ['one','two','three','four','five']
      assert olist.get(3) == 'four'
      assert listener.event.index == 3  // fails == 2
      
      olist.remove('four')
      assert listener.event.index == 3  // passes
      

      Attachments

        Activity

          People

            jwagenleitner John Wagenleitner
            jwagenleitner John Wagenleitner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: