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>
------------------------------------------------------------------
======================================================================
- duplicates
-
JDK-4883029 java/nio/channels/FileChannel/Lock.java failed (rh 7.3 & rhas 2.1, i586)
- Closed
-
JDK-4883030 java/nio/channels/FileChannel/Release.java failed (rh 7.3 & rhas 2.1, i586)
- Closed
- relates to
-
JDK-4948095 API method FileChannel.lock() works wrong in SuSE SLES 8
- Closed
-
JDK-4532474 (fs) FileChannel.lock()/tryLock() methods unusable
- Closed