Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-727

A potential misleading comment

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.4
    • 4.5.0-M1
    • Iterator

    Description

      I was wondering whether there's something wrong in the @throws IndexOutOfBoundsException condition for the `setIterator(final int index, final Iterator<? extends E> iterator)` method in the class `org.apache.commons.collections4.iterators.CollatingIterator<E>`.

      The method and its Javadoc comment are shown as follows.

      /**

      • Sets the iterator at the given index.
        *
      • @param index index of the Iterator to replace
      • @param iterator Iterator to place at the given index
      • @throws IndexOutOfBoundsException if index < 0 or index > size()
      • @throws IllegalStateException if iteration has started
      • @throws NullPointerException if the iterator is null
        */
        public void setIterator(final int index, final Iterator<? extends E> iterator) {
        checkNotStarted();
        if (iterator == null) { throw new NullPointerException("Iterator must not be null"); }

        iterators.set(index, iterator);
        }

      The boundary of the parameter index is marked as `index < 0 or index > size()`
      in the comment.
      Nevertheless, the `set(index, iterator)` method would throw an IndexOutOfBoundsException when the index is equal to `size()`.
      So it would be better if we could change the boundary in the comment to `index < 0 or index >= size()`.

      Attachments

        Activity

          People

            Unassigned Unassigned
            xz-x XiangzheXu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified