tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 51704] New: Dubious use of mkdirs() return code in juli FileHandler
Date Mon, 22 Aug 2011 13:17:27 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=51704

             Bug #: 51704
           Summary: Dubious use of mkdirs() return code in juli
                    FileHandler
           Product: Tomcat 7
           Version: trunk
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
        AssignedTo: dev@tomcat.apache.org
        ReportedBy: sebb@apache.org
    Classification: Unclassified


File#mkdirs() only returns true if the method created the directory itself.

If mkdirs() returns false, it is still possible for the directory to exist.

Thus the code in FileHandler at [1], i.e.


364     // Create the directory if necessary
365     File dir = new File(directory);
366     if (!dir.exists() && !dir.mkdirs()) {
367         reportError("Unable to create [" + dir + "]", null,
368         ErrorManager.OPEN_FAILURE);
369         writer = null;
370         return;
371     }

can generate an error even though the directory now exists.

It would be safer to code the check as follows:

366     if (!dir.mkdirs() && !dir.exists()) {

There is no need to call dir.exists() before mkdirs() as mkdirs() does that
anyway.

There is similar code at [2] and possibly elsewhere in Tomcat, I did not check.

[1]
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/FileHandler.java?view=markup#l364

[1]
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/juli/FileHandler.java?view=markup#l379

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message