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

(fs spec) Files.newBufferedWriter doesn't specify SecurityException for DELETE_ON_CLOSE option

    XMLWordPrintable

Details

    • b64
    • Verified

    Backports

      Description

        j.n.f.Files.newBufferedWriter(Path, OpenOption...) throws SecurityException in case of StandardOpenOption.DELETE_ON_CLOSE usage. It seems like checkDelete is invoked and method throws an exception when delete is denied.

        The same situation is observed in case of j.n.f.Files.newBufferedWriter(Path, Charset, OpenOption...).

        Example:
        Files.newBufferedWriter(myFilePath, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE);

        We think that it will be good to add information about calling checkDelete by SecurityManager. Although it will looks strange because newBufferedWriter's spec doesn't contain information about optional ability of deleting files.

        Tested with JDK9b37.
        Failed JCK test is under development.

        Code sample:

         Path name = Paths.get("testfile");
                System.setSecurityManager(new SecurityManager(){
                    @Override
                    public void checkWrite(FileDescriptor fd) {
                        // don't restrict anything
                    }

                    @Override
                    public void checkDelete(String file) {
                        if(file.equals(name.toString())){
                            throw new SecurityException("Couldn't delete file");
                        }
                        super.checkDelete(file);
                    }
                });

                try(BufferedWriter writer = Files.newBufferedWriter(name, StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.DELETE_ON_CLOSE)){
                    writer.write("test");
                }

        Attachments

          Issue Links

            Activity

              People

                bpb Brian Burkhalter
                asolodkaya Anastasiya Solodkaya (Inactive)
                Votes:
                0 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: