United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: 6198547 File.createNewFile() on an existing directory incorrectly throws IOException (win)
6198547 : File.createNewFile() on an existing directory incorrectly throws IOException (win)

Details
Type:
Bug
Submit Date:
2004-11-22
Status:
Closed
Updated Date:
2010-04-02
Project Name:
JDK
Resolved Date:
2006-03-04
Component:
core-libs
OS:
windows_2000
Sub-Component:
java.io
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.2_08
Fixed Versions:
6

Related Reports
Relates:

Sub Tasks

Description
Simple test case:

public class AccessDenied {
  public static void main(String[] args) {
    try {
      java.io.File file = new java.io.File("hugo");
      boolean result = file.createNewFile();
      System.out.println(result);
    } catch (java.io.IOException ex) {
      System.out.println("Error: " + ex.getMessage());
    }
  }
}

When I run this on either Solaris or Windows and "hugo" does
not exist, I get the expected output "true".

When "hugo" exists and is a file, I get the expected output
"false" on either platform.

When "hugo" exists and is a directory, I get "false" on
Solaris and an "Access is Denied" exception is thrown
on Windows. 

This is a problem for SAP since their application depends on the
correct behaviour, i. e. the access denied exception as unexpected
behaviour is not acceptable since it introduces a platform 
dependency.

                                    

Comments
EVALUATION

It is probably best to fix this problem in the native code in order to preserve atomicity with the file creation.  We need to change the handling of the return value for CreateFileW in WinNTFileSystem_md.c.  Parallel changes may also be necessary in Win32FileSystem_md.c
                                     
2006-02-01



Hardware and Software, Engineered to Work Together