[ https://issues.apache.org/jira/browse/COMPRESS-708?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18021217#comment-18021217 ]
赵钰玮 commented on COMPRESS-708: ------------------------------ The issue has been resolved. Thank you very much! *[~ggregory]* > ZstdCompressorInputStream closes the InputStream held by > ZipArchiveInputStream garbage collection > ------------------------------------------------------------------------------------------------- > > Key: COMPRESS-708 > URL: https://issues.apache.org/jira/browse/COMPRESS-708 > Project: Commons Compress > Issue Type: Bug > Reporter: 赵钰玮 > Priority: Major > Fix For: 1.29.0 > > Attachments: image-2025-09-03-22-46-38-243.png > > > {code:java} > @Test > void testZstdInputStreamErrorCloseWhenGc() throws Exception { > final File archive = getFile("COMPRESS-692/compress-692.zip"); > for (int i =0; i< 50;i++) { > try (FileInputStream fileInputStream = new FileInputStream(archive); > ZipArchiveInputStream zipArchiveInputStream = new > ZipArchiveInputStream(fileInputStream)){ > ArchiveEntry entry; > while ((entry = zipArchiveInputStream.getNextEntry()) != null) { > if (entry.isDirectory()) { > continue; > } > System.gc(); > IOUtils.toByteArray(zipArchiveInputStream); > } > } catch (IOException e) { > fail("testZstdInputStreamErrorCloseWhenGc error, test error at > batch " + (i+1), e); > } > } > } {code} > Here is the test method. Without the line {{{}System.gc();{}}}, it may take > multiple execution rounds to trigger the bug, but with this line added, the > bug is almost immediately triggered. Below is the error stack log. > !image-2025-09-03-22-46-38-243.png! > I found that this is caused by the following: The bug occurred because the > ZstdInputStream used in ZstdCompressorInputStream would close the underlying > InputStream during GC, which in turn caused errors like "stream closed" for > other wrapper streams (such as ZipArchiveInputStream) that depend on this > underlying stream. -- This message was sent by Atlassian Jira (v8.20.10#820010)