RFR  File.mkdirs() method doesn't behave well when given /../
ivan.gerasimov at oracle.com
Fri Aug 16 22:40:03 UTC 2013
Yes, the old version of the test somehow crept into the webrev. Sorry
Of course if was meant to include the check of os.name
The idea was to make the behavior of File.mkdirs() match that of
command-line mkdir -p command on Linux/Solaris/MacOS and leave it as it
is for Windows.
Files.createDirectories() behaves in exactly the same manner.
Your and Alan's idea of replacing the io implementation with calls to
its nio counterpart seems to me as the best approach.
So it may be better to defer this fix until this move is done.
On 17.08.2013 1:56, Dan Xu wrote:
> On 08/16/2013 03:40 AM, Alan Bateman wrote:
>> On 12/08/2013 17:02, Ivan Gerasimov wrote:
>>> Hello everybody!
>>> Would you please help review a small change to File.mkdirs() method?
>>> The current implementation of the method, when past an argument
>>> "dir1/../dir2" only tries to create dir2.
>>> mkdir -p 'dir1/../dir2' command on Linux creates both dir1 and dir2.
>>> java.nio.file.Files.createDirectories() also creates both dir1 and
>>> The proposed fix makes File.mkdirs() method to behave in the same
>>> way on all the platforms except for Windows.
>>> The problem with Windows is that it reports 'dir1/..' as existent
>>> even if dir1 does not exist.
>>> Because of that Files.createDirectories() doesn't work this way on
>>> Windows either.
>>> Proposed fix:
>>> - makes File.mkdirs() match the behavior of 'mkdir -p' on Linux,
>>> Solaris and MacOS, and
>>> - doesn't change its behavior on Windows.
>> This is old code so we have to be cautious about changing it (and
>> understanding why it used the canonical path in the first place).
>> What would you think about adding a few tests to cover more types of
>> file path, Windows drive-relative and directory-relative paths in
>> particular as these are cases where we would need to confident that
>> it doesn't break.
>> As an aside, Dan Xu and I were chatting recently about just replacing
>> most of the java.io.File implementation to just use java.nio.file.
>> This specific one is a case where it might be easier to just change
>> the method to Files.createDirectories(toPath()).
> Hi Ivan,
> As you mentioned, the code behaves differently on Windows platform, so
> you cannot use the same test for all platforms. Your proposed
> Mkdir.java will fail on windows. Thanks!
More information about the core-libs-dev