Groovy
  1. Groovy
  2. GROOVY-7816

ObservableList addAll method property change event index off by one

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.6
    • Fix Version/s: 2.4.7
    • Component/s: groovy-jdk
    • Labels:
      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
      

        Activity

        Hide
        ASF GitHub Bot added a comment -

        GitHub user jwagenleitner opened a pull request:

        https://github.com/apache/groovy/pull/313

        GROOVY-7816 - ObservableList addAll method property change event index off by one

        You can merge this pull request into a Git repository by running:

        $ git pull https://github.com/jwagenleitner/groovy GROOVY-7816

        Alternatively you can review and apply these changes as the patch at:

        https://github.com/apache/groovy/pull/313.patch

        To close this pull request, make a commit to your master/trunk branch
        with (at least) the following in the commit message:

        This closes #313


        commit 94fcc0249b700462b4efeae813b839c5be0bfffe
        Author: John Wagenleitner <jwagenleitner@apache.org>
        Date: 2016-04-17T17:38:31Z

        GROOVY-7816 - ObservableList addAll method property change event index off by one

        commit 35342f4ccbbb32d1f81764ae8fc6fc8d8d65bfbd
        Author: John Wagenleitner <jwagenleitner@apache.org>
        Date: 2016-04-17T18:11:22Z

        removed redundant null checks and some minor refactoring


        Show
        ASF GitHub Bot added a comment - GitHub user jwagenleitner opened a pull request: https://github.com/apache/groovy/pull/313 GROOVY-7816 - ObservableList addAll method property change event index off by one You can merge this pull request into a Git repository by running: $ git pull https://github.com/jwagenleitner/groovy GROOVY-7816 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/groovy/pull/313.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #313 commit 94fcc0249b700462b4efeae813b839c5be0bfffe Author: John Wagenleitner <jwagenleitner@apache.org> Date: 2016-04-17T17:38:31Z GROOVY-7816 - ObservableList addAll method property change event index off by one commit 35342f4ccbbb32d1f81764ae8fc6fc8d8d65bfbd Author: John Wagenleitner <jwagenleitner@apache.org> Date: 2016-04-17T18:11:22Z removed redundant null checks and some minor refactoring
        Hide
        ASF GitHub Bot added a comment -

        Github user asfgit closed the pull request at:

        https://github.com/apache/groovy/pull/313

        Show
        ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/groovy/pull/313

          People

          • Assignee:
            John Wagenleitner
            Reporter:
            John Wagenleitner
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development