This is an automated email from the ASF dual-hosted git repository.
garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git
The following commit(s) were added to refs/heads/master by this push:
new d94944bc0 Fix premature ZIP closure in Zstandard tests
d94944bc0 is described below
commit d94944bc014963f280d94a5d5b4aea3a65ee4281
Author: Gary Gregory <[email protected]>
AuthorDate: Wed Dec 2 20:31:42 2026 +0000
Fix premature ZIP closure in Zstandard tests
Close the Zstandard compressor with try-with-resources and shield
the enclosing ZIP stream with CloseShieldOutputStream. This releases
compressor resources and prevents its finalizer from racing with ZIP
finalization and causing ClosedChannelException.
Replace the deprecated compressor constructor with the builder API.
---
.../compress/archivers/zip/ZipCompressMethodZstdTest.java | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipCompressMethodZstdTest.java
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipCompressMethodZstdTest.java
index 3c0d1eca1..5a9432acf 100644
---
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipCompressMethodZstdTest.java
+++
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipCompressMethodZstdTest.java
@@ -35,6 +35,7 @@
import
org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
import org.apache.commons.compress.compressors.zstandard.ZstdUtils;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.output.CloseShieldOutputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@@ -51,10 +52,14 @@ class ZipCompressMethodZstdTest extends AbstractTest {
* @throws IOException throws the exception which could be got from from
IOUtils.copyLarge() or ZstdCompressorOutputStream constructor
*/
private static void compress(final InputStream input, final OutputStream
output) throws IOException {
- @SuppressWarnings("resource")
- final ZstdCompressorOutputStream outputStream = new
ZstdCompressorOutputStream(output, DEFAULT_LEVEL, true);
- IOUtils.copyLarge(input, outputStream);
- outputStream.flush();
+ try (ZstdCompressorOutputStream outputStream =
ZstdCompressorOutputStream.builder()
+ .setOutputStream(CloseShieldOutputStream.wrap(output))
+ .setLevel(DEFAULT_LEVEL)
+ .setCloseFrameOnFlush(true)
+ .get()) {
+ IOUtils.copyLarge(input, outputStream);
+ outputStream.flush();
+ }
}
@Test