JDK-6709457 : (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2008-06-02
  • Updated: 2011-03-08
  • Resolved: 2011-03-08
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 7
7 b123Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0-ea"
Java(TM) SE Runtime Environment (build 1.7.0-ea-b27)
Java HotSpot(TM) Client VM (build 13.0-b01, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Verze 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

A DESCRIPTION OF THE PROBLEM :
Tried to run Eclipse 3.1.2-based app with JRE 7. That failed when it tried to lock a file. I tracked the problem down and reproduced it with attached test code. If I use RandomAccessFile instead of FileOutputStream (inspired by the change done in Eclipse 3.3.2) it works.

Disk volume where the lock file is created is normal filesystem,  not networked one.

Works with JRE 1.5 and 6.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run provided example.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No error.
ACTUAL -
Exception.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception in thread "main" java.io.IOException: Pstup byl odepen
	at sun.nio.ch.FileChannelImpl.lock0(Native Method)
	at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:903)
	at java.nio.channels.FileChannel.tryLock(FileChannel.java:978)
	at test.Test.main(Test.java:10)


REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package test;

import java.io.File;
import java.io.FileOutputStream;

public class Test {
   public static void main(String[] args) throws Exception {
        File lockFile = new File("C:\\temp\\lock");
        FileOutputStream fileStream = new FileOutputStream(lockFile, true);
        fileStream.getChannel().tryLock();
        fileStream.close();
    }
}

---------- END SOURCE ----------

Release Regression From : 6
The above release value was the last known release where this 
bug was not reproducible. Since then there has been a regression.

Comments
EVALUATION http://hg.openjdk.java.net/jdk7/build/jdk/rev/374cc848d797
25-12-2010

EVALUATION This is regression caused by the changes in 6631352 to use the ~FILE_WRITE_DATA mode. This is one of two side effects that have been observed - the other is that the truncate method doesn't work when appending. These changes will be backed out in an upcoming build.
02-06-2008