Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8316882

(zipfs) ZipFileSystem closed by interrupt is unexpected

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Macos 10.15.7, java 21 2023-09-19 LTS

      A DESCRIPTION OF THE PROBLEM :
      When a Thread trying to create a byte channel for a jdk.zipfs/jdk.nio.zipfs.ZipFileSystem is interrupted, a ClosedByInterruptException is thrown. This Exception is thrown by the internal channel hold by the ZipFileSystem. The channel is closed, and other calls to create byte channels fail with java.nio.channels.ClosedChannelException.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Execute "java -ea ZipfsBug.java" in a shell with File Contents listed below


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The second call to newByteChannel should succeed and the program should exit gracefully
      ACTUAL -
      The second call to newByteChannel throws java.nio.channels.ClosedChannelException

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.net.URI;
      import java.nio.channels.ClosedByInterruptException;
      import java.nio.file.*;
      import java.util.Map;
      import java.util.zip.*;

      class ZipfsBug {
      public static void main(String... args) throws IOException {
      var path = Path.of("test.zip");
      try (var zout = new ZipOutputStream(Files.newOutputStream(path))) {
      zout.putNextEntry(new ZipEntry("entry"));
      zout.write("HEHE".getBytes(), 0, 4);
      zout.closeEntry();
      }
      URI uri = URI.create("jar:file:" + path.toAbsolutePath());
      var zipfs = FileSystems.newFileSystem(uri, Map.of());
      var zippath = zipfs.getPath("entry");
      Thread.currentThread().interrupt();
      try {
      Files.newByteChannel(zippath);
      assert false;
      } catch (IOException e) {
      assert e instanceof ClosedByInterruptException : e;
      }

      // Throws ClosedChannelException
      Files.newByteChannel(zippath);
      }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Do not interrupt threads that are doing io-operations

      FREQUENCY : always


            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated: