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

XMLWordPrintable

    • Type: Bug
    • Resolution: Fixed
    • Priority: P5
    • 17
    • Affects Version/s: None
    • Component/s: core-libs
    • None
    • b15

      The following example will not throw a FileAlreadyExistsException:

          @Test
          public void testit() throws Exception {
              Path osFile = Path.of("Hello.txt");
              Files.deleteIfExists(osFile);
              Files.writeString(osFile, "Hello World");

              try (SeekableByteChannel srcCh = Files.newByteChannel(osFile, Set.of(CREATE_NEW))) {
                  System.out.println("oops");
              }

              try (SeekableByteChannel srcCh = Files.newByteChannel(osFile, Set.of(CREATE_NEW, READ))) {
                  System.out.println("oops");
              }
          }



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

            Assignee:
            Brian Burkhalter
            Reporter:
            Lance Andersen
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: