java.io.IOException: Access is denied

Atlassian JIRA | Richard Atkins [Atlassian] | 6 years ago
  1. Speed up your debug routine!

    Automated exception search integrated into your IDE

  2. 0

    OPERATING SYSTEM(S) Windows XP FULL JDK VERSION(S): java version "1.5.0_04" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_04-b05) Java HotSpot(TM) Client VM (build 1.5.0_04-b05, mixed mode) DESCRIPTION: When running the following testcase, the createTempFile call occassionally throws an IOException "Access is denied". import java.io.File; public class TestFile { public static void main(String[] args) throws Exception { for (int i = 0; i < 5; i++) { File tempFile = File.createTempFile("WSTMPCC", null, null); System.out.println("*** create = " + tempFile.getAbsolutePath() + " ***"); tempFile.delete(); System.out.println("*** delete = " + tempFile.getAbsolutePath() + " ***"); tempFile.mkdir(); System.out.println("*** mkdir = " + tempFile.getAbsolutePath() + " ***"); tempFile.mkdir(); } } } C:\dev\test>java TestFile Exception in thread "main" java.io.IOException: Access is denied at java.io.WinNTFileSystem.createFileExclusively(Native Method) at java.io.File.checkAndCreate(File.java:1345) at java.io.File.createTempFile(File.java:1434) at TestFile.main(TestFile.java:8) What appears to be happening is that createTempFile generates a temporary filename and then attempts to create a new empty file with that name using the CreateFileW OS call. If a directory already exists with that name, CreateFileW appears to be returning an error of ERROR_ACCESS_DENIED, which is being treated as an error. What should be happening is that the class libraries should be generating a new temporary filename and trying again. Looking at the MSDN documentation for CreateFileW, I'm not certain that ERROR_ACCESS_DENIED cannot be thrown in other circumstances, so I do not believe it is safe to simply ignore that error and retry as we currently do for ERROR_FILE_EXISTS. Instead a test could be made before CreateFileW is called to test if the generated filename already exists and if it does abort such that a new filename can be generated and the attempt to create a new empty file repeated. [This bug is being submitted as a courtesy, in order to maintain uniformity between Sun & IBM JDKs. It has been fixed in IBM JDKs. Please contact ###@###.### if you have questions.]

    JDK Bug System | 1 decade ago | Erik Larsen
    java.io.IOException: Access is denied

  1. davidvanlaatum 2 times, last 6 days ago
  2. Vladimir Dmie 1 times, last 4 months ago
  3. davidvanlaatum 5 times, last 6 months ago
21 unregistered visitors
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.io.IOException

    Access is denied

    at java.io.WinNTFileSystem.createFileExclusively()
  2. Java RT
    File.createTempFile
    1. java.io.WinNTFileSystem.createFileExclusively(Native Method)
    2. java.io.File.checkAndCreate(File.java:1345)
    3. java.io.File.createTempFile(File.java:1434)
    3 frames