ppkarwasz commented on code in PR #709:
URL: https://github.com/apache/commons-compress/pull/709#discussion_r2380273884
##########
src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java:
##########
@@ -240,7 +238,11 @@ private TarFile(final Builder builder) throws IOException {
this.recordBuffer = ByteBuffer.allocate(this.recordSize);
this.blockSize = builder.getBlockSize();
this.lenient = builder.isLenient();
- forEach(entries::add);
Review Comment:
Reverting to the old code here is deliberate.
When I dropped your custom `iterator()` implementation in favor of the
default from `ArchiveFile`, it introduced a loop:
* `forEach` in `IOIterable` calls `iterator()`.
* The default `iterator()` calls `entries()`:
https://github.com/apache/commons-compress/blob/f5dd39c8bcb1abb43270c75167008ba0330c6818/src/main/java/org/apache/commons/compress/archivers/ArchiveFile.java#L82-L86
* `entries()` calls `stream()`:
https://github.com/apache/commons-compress/blob/f5dd39c8bcb1abb43270c75167008ba0330c6818/src/main/java/org/apache/commons/compress/archivers/ArchiveFile.java#L54-L58
* `stream()` iterates over the `entries` collection, the very collection
we’re trying to populate:
https://github.com/apache/commons-compress/blob/f5dd39c8bcb1abb43270c75167008ba0330c6818/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java#L464-L467
So `forEach(entries::add)` ends up iterating an empty collection and adding
nothing, effectively a no-op. Restoring the original `iterator()` avoids this
self-referential loop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]