JDK-6198547 : File.createNewFile() on an existing directory incorrectly throws IOException (win)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 1.4.2_08
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_2000
  • CPU: x86
  • Submitted: 2004-11-22
  • Updated: 2010-04-02
  • Resolved: 2006-03-04
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 Availability Release.

To download the current JDK release, click here.
JDK 6
6 b75Fixed
Related Reports
Relates :  
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
01-02-2006