JDK-6628575 : (fc) lock/tryLock methods do not work with NFS servers that limit lock range to max file size
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 6,6u5
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic,other,solaris_2.5.1
  • CPU: generic,x86,sparc
  • Submitted: 2007-11-12
  • Updated: 2011-05-18
  • Resolved: 2011-05-18
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b25Fixed
Related Reports
Duplicate :  
Description
The customers application does not boot when the
application tries to lock files hosted on an NFSv3 file system running on HP-UX 11.23 which checks the 'len' argument against the maximum file size and returns error.

The java.nio.channels.FileChannel.tryLock() implementation translates into the following system call:

fcntl64(17, F_SETLK64, {type=F_WRLCK, whence=SEEK_SET, start=0,
len=9223372036854775807}, 0xbfffd0e0)

where len argument is set to maximum of long type ( 2^63 - 1  ==
9223372036854775807 ).

This causes problem when using HP-UX 11.23 NFS server, which checks the 'len' argument against the maximum file size and returns error, which is correspondent with NFSv3 rfc document.

  To lock the whole file the 'len' argument should be set to 0.
eg. have an OS call translate into the following:

fcntl64(17, F_SETLK64, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0},0xbfffd0e0)

which is also documented in fcntl manual page.

Supposedly this is an incorrect implementation of locking the whole file in the SUN jdk and would like it to be fixed using zero length lock offset size.

Analysis shows that java.nio.channels.FileChannel.tryLock() is implemented
as:

    public final FileLock tryLock() throws IOException
    {    return tryLock(0L, 0x7fffffffffffffffL, false);     }

The customer would prefer:

    public final FileLock tryLock() throws IOException
    {    return tryLock(0L, 0x0L, false);

Comments
EVALUATION Where the position is 0 and the size is Long.MAX_VALUE then we should set l_len to 0. Will fix in jdk7. This issue can be worked around by the 3-arg tryLock method, eg: FileLock lock = fc.tryLock(0, fc.size(), false);
12-11-2007

WORK AROUND Not use NFS on HPUX for application files - this is difficult for the customer.
12-11-2007