JDK-4719967 : (fs) FileChannel.tryLock throws IOException on Linux
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0_02
  • Priority: P2
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux_redhat_7.2
  • CPU: generic
  • Submitted: 2002-07-24
  • Updated: 2002-07-24
  • Resolved: 2002-07-24
Related Reports
Duplicate :  
Description
The java.nio.channels.FileChannel.tryLock(0L, Long.MAX_VALUE, false) throws
             IOException on Linux but works on Solaris.
Seen in JDK 1.4.0_02 (prerelease). Does not happen in 1.4.1 beta

Attaching a test case: LockTest.java


             import java.io.*;
             import java.nio.channels.*;

             public class LockTest {

                     public static final String LOCK_NAME = "domains.lck";
                     private static File STORE;

                     public static void main( String[] args ) throws FileNotFoundException {
                             boolean shared = false;
                             STORE = new File("/space/svbld", LOCK_NAME);
                             try {
                                     RandomAccessFile raf = new RandomAccessFile(STORE, 
             "rws");
                                     FileChannel channel = raf.getChannel();
                                     FileLock lock = channel.tryLock(0L, Long.MAX_VALUE, 
             shared);
                             }
                             catch ( IOException f ) {
                                     System.out.println("IOException caught");
                             }
                     }
             }

(Filing on behalf of Dipankar Roy and Rajesh Navaneetham)

Wed Jul 24 12:24:11 MDT 2002	tsteele@litehouse

Comments
SUGGESTED FIX See delta 1.27 (for 4532474) of src/solaris/native/sun/nio/ch/FileChannelImpl.c -- ###@###.### 2002/7/24
07-10-0190

WORK AROUND Give an explicit lock size that is no larger than 0x7fffffff. -- ###@###.### 2002/7/24
07-10-0190