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

API method FileChannel.lock() works wrong on Linux

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 5.0
    • 1.4.2, 5.0
    • core-libs
    • b26
    • x86, sparc
    • linux, linux_redhat_9.0, linux_suse_sles_8, solaris_2.6
    • Verified



      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>

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

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

            mmcclosksunw Michael Mccloskey (Inactive)
            pavsunw Pav Pav (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: