United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4932924 : java.File.mkdirs() require "read" permission to outer dirs

Details
Type:
Bug
Submit Date:
2003-10-06
Status:
Closed
Updated Date:
2004-03-20
Project Name:
JDK
Resolved Date:
2003-11-23
Component:
core-libs
OS:
solaris_2.6
Sub-Component:
java.io
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
5.0
Fixed Versions:
5.0 (b30)

Related Reports

Sub Tasks

Description

Name: szR10253			Date: 10/06/2003


Filed By      : SPB JCK team (###@###.###)
JDK           : java full version "1.5.0-beta-b22"
JCK           : 1.5
Platform[s]   : Solaris
switch/Mode   : 
JCK test owner : http://javaweb.eng/jct/sqe/JCK-tck/usr/owners.jto
Failing Test [s] : N/A


Specification excerpt:
======================
--------- J2SE API spec v.1.5 ---------
...
    /**
     * Creates the directory named by this abstract pathname, including any
     * necessary but nonexistent parent directories.  Note that if this
     * operation fails it may have succeeded in creating some of the necessary
     * parent directories.
     *
     * @return  <code>true</code> if and only if the directory was created,
     *          along with all necessary parent directories; <code>false</code>
     *          otherwise
     *
     * @throws  SecurityException
     *          If a security manager exists and its <code>{@link
     *          java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
     *          method does not permit the named directory and all necessary
     *          parent directories and to be created
     */

...
---------- end-of-excerpt ---------------

Problem description
===================
a File which was created as File("") is represented current directory, a call to mkdirs() should create directory structure from the current directory only. This method should work if all permissions are granted to the current directory, but the method throws a SecurityException with a parent directory.
    
Minimized test:
===============
------- Test.java -------
public class Test {
    public static void main(String[] args) {
        System.setSecurityManager(new SM());
        new File("").mkdirs();
    }

    static class SM extends SecurityManager {
        public void checkPropertyAccess(String key) {
        }
        public void checkRead(String file) {
            File f = new File("");
            if (file.equals("") || file.equals(f.getPath()) || file.equals(f.getAbsolutePath())) {
                return;
            }
            super.checkRead(file);
        }
        public void checkWrite(String file) {
            File f = new File("");
            if (file.equals("") || file.equals(f.getPath()) || file.equals(f.getAbsolutePath())) {
                return;
            }
            super.checkWrite(file);
        }
    }
}

------- end-of-Test.java -------

Minimized test output:
======================
Exception in thread "main" java.security.AccessControlException: access denied (java.io.FilePermission /home read)
        at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264)
        at java.security.AccessController.checkPermission(AccessController.java:401)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
        at java.lang.SecurityManager.checkRead(SecurityManager.java:863)
        at Test$SM.checkRead(Test.java:189)
        at java.io.File.exists(File.java:692)
        at java.io.File.mkdirs(File.java:1133)
        at java.io.File.mkdirs(File.java:1146)
        at Test.main(Test.java:178)


JCK test source location:
==========================
/java/re/jck/1.5/promoted/latest/JCK-runtime-15/tests

======================================================================

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
tiger-beta

FIXED IN:
tiger-beta

INTEGRATED IN:
tiger-b30
tiger-beta

VERIFIED IN:
tiger-b41


                                     
2004-06-14
EVALUATION

We will change the spec to mention this as approved by CCC.
###@###.### 2003-11-17
                                     
2003-11-17



Hardware and Software, Engineered to Work Together