Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4532474

(fs) FileChannel.lock()/tryLock() methods unusable

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.1
    • 1.4.0, 1.4.0_02
    • core-libs
    • hopper
    • generic, x86
    • linux, linux_redhat_7.2, windows_98
    • Verified



      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)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: