Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,8 @@ public ArchiveBuilder addArchive(String name) throws IOException {
* or the outer builder can be closed.
* <p>
* {@link ZipOption#ZIP64} applies to the outer entry (reserving ZIP64 space in the outer local
* file header). The inner builder inherits the same options as its defaults.
* file header). The inner builder inherits the same options as its defaults, with the exception of
* {@link ZipOption#ALLOW_DUPLICATE_ENTRIES}.
*
* @param name the entry name for the nested archive (must not be {@code null})
* @param options the options; may contain {@link ZipOption} values
Expand Down Expand Up @@ -1272,7 +1273,8 @@ public ArchiveBuilder addArchive(String name, FileAttribute<?>... attrs) throws
* or the outer builder can be closed.
* <p>
* {@link ZipOption#ZIP64} applies to the outer entry (reserving ZIP64 space in the outer local
* file header). The inner builder inherits the same options as its defaults.
* file header). The inner builder inherits the same options as its defaults, with the exception of
* {@link ZipOption#ALLOW_DUPLICATE_ENTRIES}.
* {@link ZipOption#DEFLATED} is permitted here (unlike {@code addBufferedEntry}) and sets
* the inner builder's default compression method; the outer entry is always STORED.
* <p>
Expand Down Expand Up @@ -1307,7 +1309,7 @@ public ArchiveBuilder addArchive(String name, Collection<? extends OpenOption> o
// which triggers the close action for CRC/LFH patching on the outer entry
return new ArchiveBuilder(nested, nested.filePosition(),
innerMethod == PARSED_NO_METHOD ? METHOD_DEFLATE : innerMethod, zip64,
(parsed & PARSED_ALLOW_DUPLICATE_ENTRIES) != 0 || allowDuplicateEntries);
(parsed & PARSED_ALLOW_DUPLICATE_ENTRIES) != 0);
}

// ── Raw data methods ────────────────────────────────────────────────
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2072,4 +2072,33 @@ public void testDuplicateNestedArchiveBlockedByDefault() throws Exception {
});
}
}

/**
* Test that {@link ZipOption#ALLOW_DUPLICATE_ENTRIES} is not inherited by a nested archive,
* but can be specified explicitly on the nested archive if desired.
*
* @throws Exception if an unexpected error occurs
*/
@Test
public void testDuplicateOptionNotInheritedByNestedArchive() throws Exception {
Path file = tempDir.resolve("duplicate-nested-not-inherited.zip");
// Outer archive has duplicates allowed
try (ArchiveBuilder builder = ArchiveBuilder.open(file, ZipOption.ALLOW_DUPLICATE_ENTRIES)) {
// Nested archive does NOT have duplicate options specified, so it should NOT allow duplicates
try (ArchiveBuilder inner = builder.addArchive("inner1.jar")) {
inner.addEntry("foo.txt", "foo".getBytes(StandardCharsets.UTF_8));
assertThrows(IllegalArgumentException.class, () -> {
inner.addEntry("foo.txt", "bar".getBytes(StandardCharsets.UTF_8));
});
}

// Nested archive explicitly has duplicate options specified, so it should allow duplicates
try (ArchiveBuilder inner = builder.addArchive("inner2.jar", ZipOption.ALLOW_DUPLICATE_ENTRIES)) {
inner.addEntry("foo.txt", "foo".getBytes(StandardCharsets.UTF_8));
assertDoesNotThrow(() -> {
inner.addEntry("foo.txt", "bar".getBytes(StandardCharsets.UTF_8));
});
}
}
}
}
Loading