Name: jl125535 Date: 11/28/2001
java version "1.4.0-beta3"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta3-b84)
Java HotSpot(TM) Client VM (build 1.4.0-beta3-b84, mixed mode)
1. While attempting to acquire a lock on a text file using the following code,
an unxexpected error message occurs:
import java.io.*;
import java.nio.*;
import java.nio.channels.*;
class FileLockTest {
public static void main(String args[]) throws Exception {
RandomAccessFile raf = new RandomAccessFile("FileCopy.java", "rw");
FileChannel channel = raf.getChannel();
// FileLock lock = channel.lock(); // also fails with same message
FileLock lock = channel.tryLock();
System.out.println("File locked. Press any key to continue...");
System.in.read();
lock.release();
channel.close();
}
}
3. The following error message is generated:
Exception in thread "main" java.io.IOException: The parameter is incorrect
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.tryLock(FileChannelImpl.java:515)
at java.nio.channels.FileChannel.tryLock(FileChannel.java:912)
at FileLockTest.main(FileLockTest.java:12)
4. This sample program works on Windows 2000 with both lock() and tryLock().
5. On Solaris 8, the sample program works with tryLock(), but lock() results
in the following error message:
Exception in thread "main" java.io.IOException: No record locks available
at sun.nio.ch.FileChannelImpl.lock0(Native Method)
at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:477)
at java.nio.channels.FileChannel.lock(FileChannel.java:812)
at FileLockTest.main(FileLockTest.java:11)
6. If the behaviors in (3) and (5) are expected (see the customer workaround),
perhaps more appropriate error messages or a site for common compatibility
issues would help. The current documentation
http://java.sun.com/j2se/1.4/docs/api/java/nio/channels/FileChannel.html#lock()
talks about platform dependencies. Specific information for common platforms
would be a nice addition.
(Review ID: 135868)
======================================================================
- duplicates
-
JDK-4719967 (fs) FileChannel.tryLock throws IOException on Linux
-
- Closed
-
-
JDK-4656314 (fs) FileChannel.lock/tryLock() failure due to Long.MAX-VALUE (lnx)
-
- Closed
-
- relates to
-
JDK-4854085 API method FileChannel.lock() works wrong on Linux
-
- Closed
-