JDK-4510562 : (fs spec) FileChannel.lock/tryLock spec should describe channel preconditions
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 1.4.0,5.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Duplicate
  • OS: generic,windows_xp
  • CPU: generic,x86
  • Submitted: 2001-10-03
  • Updated: 2022-01-25
  • Resolved: 2022-01-25
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.
Other
tbdResolved
Related Reports
Relates :  
Relates :  
Description
The spec should be revised to say that an exclusive lock requires a channel that
is open for both reading and writing, and that a NonReadableChannelException or
a NonWritableChannelException will be thrown, as appropriate, if this condition
does not hold.
 
The spec should be revised to say that a shared lock requires a channel that is
open for reading (and possibly writing), and that a NonReadableChannelException
will be thrown if this condition does not hold.
 
-- mr@eng 2001/8/10

Comments
Resolving as duplicate of JDK-8279946.
25-01-2022

EVALUATION This bug is solely a specification issue and the tryLock methods needs to be updated with the channel pre-conditions. A number of JDC comments on this bug seem to be confused as to how to obtain a shared lock on a channel that was open only for reading. This is done by invoking fc.tryLock(position, size, true). The zero-argument tryLock() method attempts to acquire an exclusive lock and correctly throws NonWritableChannelException if the channel was not opened for writing.
24-10-2007