Repository: netty/netty
File: buffer/src/main/java/io/netty5/buffer/api/DefaultCompositeBuffer.java (Java)

Code before:
                        buf.close();
                    }
                }
            }
            return array.length == index? array : Arrays.copyOf(array, index);
        }
    }

    private static final class ConcatIterable<T> implements Iterable<T> {
        private final Iterable<T> first;
        private final Iterable<T> second;

        ConcatIterable(Iterable<T> first, Iterable<T> second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public Iterator<T> iterator() {
            return new ConcatIterator(first.iterator(), second.iterator());
        }
    }

    private static final class ConcatIterator<T> implements Iterator<T> {
        Iterator<T> current;
        Iterator<T> next;

        ConcatIterator(Iterator<T> first, Iterator<T> second) {
            current = first;
            next = second;
        }

        @Override
        public boolean hasNext() {
            return current != null && current.hasNext() || next != null && next.hasNext();
        }

        @Override
        public T next() {
            while (current != null) {
                if (current.hasNext()) {
                    return current.next();
                }
                current = next;
                next = null;
            }
            throw new NoSuchElementException();
        }
    }

    private DefaultCompositeBuffer(BufferAllocator allocator, Buffer[] bufs, Drop<DefaultCompositeBuffer> drop) {

Review comment (suggestion):
```suggestion
        private Iterator<T> current;
        private Iterator<T> next;
```

Code after:
                for (int i = 0; i < lastReadable; i++) {
                    Buffer buf = array[i];
                    if (buf.writableBytes() > 0) {
                        array[i] = buf.split();
                        buf.close();
                    }
                }
            }
            return array.length == index? array : Arrays.copyOf(array, index);
        }
    }

    private static final class ConcatIterable<T> implements Iterable<T> {
        private final Iterable<T> first;
        private final Iterable<T> second;

        ConcatIterable(Iterable<T> first, Iterable<T> second) {
            this.first = first;
            this.second = second;
        }

        @Override
        public Iterator<T> iterator() {
            return new ConcatIterator(first.iterator(), second.iterator());
        }
    }

    private static final class ConcatIterator<T> implements Iterator<T> {
        private Iterator<T> current;
        private Iterator<T> next;

        ConcatIterator(Iterator<T> first, Iterator<T> second) {
            current = first;
            next = second;
        }

        @Override
        public boolean hasNext() {
            return current != null && current.hasNext() || next != null && next.hasNext();
        }

        @Override
        public T next() {
            while (current != null) {
                if (current.hasNext()) {
                    return current.next();
                }
                current = next;
                next = null;
            }
            throw new NoSuchElementException();