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

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

    Details

    • Type: Bug
    • Status: Open
    • Priority: P5
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
      None

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                bpb Brian Burkhalter
                Reporter:
                lancea Lance Andersen
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: