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

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P5
    • 17
    • None
    • core-libs
    • None
    • b15

    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

              bpb Brian Burkhalter
              lancea Lance Andersen
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: