JDK-4932924 : java.File.mkdirs() require "read" permission to outer dirs
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: solaris_2.6
  • CPU: sparc
  • Submitted: 2003-10-06
  • Updated: 2017-05-16
  • Resolved: 2003-11-23
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
5.0 b30Fixed

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())) {
        public void checkWrite(String file) {
            File f = new File("");
            if (file.equals("") || file.equals(f.getPath()) || file.equals(f.getAbsolutePath())) {

------- 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:


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

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