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

(fs) FileChannel.lock/tryLock() failure due to Long.MAX-VALUE (lnx)

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 1.4.0
    • core-libs
    • x86
    • linux



      Name: nt126004 Date: 03/21/2002


      FULL PRODUCT VERSION :
      java version "1.4.0"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-b92)
      Java HotSpot(TM) Client VM (build 1.4.0-b92, mixed mode)

      FULL OPERATING SYSTEM VERSION :Linux viper 2.4.2-2 #1 Sun
      Apr 8 20:41:30 EDT 2001 i686 unknown


      A DESCRIPTION OF THE PROBLEM :
      The lock and tryLock functions on Linux fail when called.
      This is because the length field passed as a parameter in
      the Java code is illegal in the native implementation. The
      value is Long.MAX-VALUE. The legal range apparently on Linux
      is 0x1F7FFFFFFF (135291469823L).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Write a program that calls lock or tryLock.

      2. An exception is thrown from the native code.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      The expected result is the file is locked.

      What really happens is the native code barfs on the
      parameter passed by the Channel method implementation. The
      file does not get locked.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.io.IOException: Invalid argument
      at sun.nio.ch.FileChannelImpl.lock0(Native Method)
      at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:490)
      at lock.main(lock.java:11)

      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.io.*;
      import java.nio.channels.*;

      public class lock
      {
      public static void main( String[] inArguments )
      throws Throwable
      {
      RandomAccessFile file = new RandomAccessFile( "test.txt", "rw" );

      // FileLock lock = file.getChannel().lock( 0, 135291469823L, false );
      FileLock lock = file.getChannel().lock();
      if ( lock == null )
      {
      System.out.println( "Unlocked" );
      }
      else
      {
      System.out.println( "Locked" );
      lock.release();
      }

      file.close();
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER WORKAROUND :
      Use your own value for the length and call one of the other
      methods that take values. The length value must be less than
      the value 1F7FFFFFFF.
      (Review ID: 144335)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            nthompsosunw Nathanael Thompson (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: