JDK-4854085 : API method FileChannel.lock() works wrong on Linux
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.2,5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS:
    linux,linux_redhat_9.0,linux_suse_sles_8,solaris_2.6 linux,linux_redhat_9.0,linux_suse_sles_8,solaris_2.6
  • CPU: x86,sparc
  • Submitted: 2003-04-25
  • Updated: 2003-11-06
  • Resolved: 2003-10-24
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.
Other
5.0 b26Fixed
Related Reports
Duplicate :  
Duplicate :  
Relates :  
Relates :  
Description

Name: apR10229			Date: 04/25/2003



The API method java.nio.channels.FileChannel.lock() works
wrong with Linux locking facilities. The following example
demonstrates that IOException is thrown when trying to
get exclusive lock for writable channel.

-------------------- test.java ----------------------
import java.io.*;
import java.nio.channels.*;
public class test {
    public static void main(String[] args) {
	FileLock fl = null;
	try {
	    FileOutputStream fos = new FileOutputStream("testFile.tmp");
	    fos.write(new byte[128]);
            FileChannel ch = fos.getChannel();
	    fl = ch.lock();
        } catch (IOException e) {
	    System.out.println("Unexpected exception: "+e);
            e.printStackTrace();
	    System.exit(0);
        }
        System.out.println("PASSED.");
    }
}
------------------- example output ------------------
<pav@libra(pts/8).276> uname -a
Linux libra 2.4.18 #10 Fri Jun 28 18:21:54 MSD 2002 i686 unknown
<pav@libra(pts/8).277> java -version
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b04)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b04, mixed mode)
<pav@libra(pts/8).278> javac -d . test.java
<pav@libra(pts/8).279> java -cp . test
Unexpected exception: java.io.IOException: No locks available
java.io.IOException: No locks available
        at sun.nio.ch.FileChannelImpl.lock0(Native Method)
        at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:738)
        at java.nio.channels.FileChannel.lock(FileChannel.java:865)
        at test.main(test.java:10)
<pav@libra(pts/8).280>


<pav@archer(pts/4).257> uname -a
SunOS archer 5.8 Generic_108528-20 sun4u sparc SUNW,Ultra-4
<pav@archer(pts/4).258> java -version
java version "1.5.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta-b04)
Java HotSpot(TM) Client VM (build 1.5.0-beta-b04, mixed mode)
<pav@archer(pts/4).259> javac -d . test.java
<pav@archer(pts/4).260> java -cp . test
PASSED.
<pav@archer(pts/4).261>

------------------------------------------------------------------

======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: tiger-beta FIXED IN: tiger-beta INTEGRATED IN: tiger-b26 tiger-beta VERIFIED IN: tiger-beta
14-06-2004

PUBLIC COMMENTS verified the fix in RH 9, RH AS 2.1, RH AS 3.0 using tiger b26. Used the testcase in the description. The problem is not fixed in SuSE SLES 8 & SuSE 8.2. Filed Bug# 4948095 to track it.
10-06-2004

EVALUATION Not for mantis. ###@###.### 2003-04-29 Fixed for tiger-beta. ###@###.### 2003-10-17
29-04-2003