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

(zipfs) Files.newByteChannel(zipfile, Set.of(CREATE_NEW, READ)) does not throw a FileAlreadyExistsException when the file exists

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P5 P5
    • tbd
    • 9
    • core-libs
    • None

      The following example will not throw a FileAlreadyExistsException:

          @Test
             public void zipFAETest(final Map<String, String> env,
                                      final int compression) throws Exception {
              Path zipFile = generatePath(HERE, "test", ".zip");
              Files.deleteIfExists(zipFile);
              Entry e0 = Entry.of("Entry-0", compression, THE_SLAMS);
              zip(zipFile, env, e0);

              // Validate that a FileAlreadyExistsException is thrown
              try (FileSystem zipfs = FileSystems.newFileSystem(zipFile, env)) {
                  assertThrows(FileAlreadyExistsException.class, () ->
                          Files.newByteChannel(zipfs.getPath(e0.name), Set.of(CREATE_NEW)));
              }
              Files.deleteIfExists(zipFile);
          }



      If you specify Set.of(CREATE_NEW, WRITE) you will get the expected Exception

            lancea Lance Andersen
            lancea Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: