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

File.createTempFile requires unnecessary "read" permission

XMLWordPrintable

    • b96
    • 8
    • b100
    • Verified

        This is the regression introduced with fix for JDK-8013827. The code now checks if file exists before creating new temp file as oppose to earlier where an attempt was made to create file.

        Code snippet:

        File f;
                try {
                    do {
                        f = TempDirectory.generateFile(prefix, suffix, tmpdir);
                    } while (f.exists());
                    if (!f.createNewFile())
                        throw new IOException("Unable to create temporary file");
                } catch (SecurityException se) {

        The call to f.exists now needs "read" permission to be provided for applications which only need to write temp file.

        Error:
        java.security.AccessControlException: access denied


        Exception stack trace:

        java.security.AccessControlException: access denied ("java.io.FilePermission" "/tmp/abcd#4910205138484207578.tmp" "read")
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:453)
        at java.security.AccessController.checkPermission(AccessController.java:820)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
        at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
        at java.io.File.exists(File.java:814)
        at java.io.File.createTempFile(File.java:2003)

              dxu Dan Xu (Inactive)
              rhalade Rajan Halade
              Votes:
              0 Vote for this issue
              Watchers:
              7 Start watching this issue

                Created:
                Updated:
                Resolved: