JDK-4780504 : (fs) Forcing a read-only file channel should throw more specific exception
Type:Bug
Component:core-libs
Sub-Component:java.nio
Affected Version:1.4.0,1.4.2
Priority:P4
Status:Closed
Resolution:Cannot Reproduce
OS:generic,solaris_7
CPU:generic,sparc
Submitted:2002-11-18
Updated:2024-10-07
Resolved:2022-01-13
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.
The problem is not observable. Fixing the missing @throws clauses is moved to JDK-8279946.
13-01-2022
Using the current development repositories, calling force() on a read-only FileChannel does not result in an exception on Linux, macOS, or Windows, and neither does it update the last access time on any of these platforms.
13-01-2022
It would be useful to update this bug with a survey of long standing behavior on each platform to see if the method fails and whether it updates the last access time or not.
The write methods are specified to throw NonWritableChannelException, I think the issue is just that it's specified in WriteableByteChannel and the `@throws` isn't inherited into FileChannel (as it's an unchecked exception). We should fix that.
The lock method are correctly specified to throw NonWritableChannelException but it seems the `@throws` are missing from the tryLock methods. We should fix that.
09-02-2018
Whether force() should throw an exception for a read-only file channel is cast in doubt by the specification of the method which allows for the read-only case:
"Invoking this method may cause an I/O operation to occur even if the channel was only opened for reading. Some operating systems, for example, maintain a last-access time as part of a file's metadata, and this time is updated whenever the file is read. Whether or not this is actually done is system-dependent and is therefore unspecified."
Changing force() to throw a NonWritableChannelException for a read-only channel would seem to imply a specification change.
Also, neither tryLock() method nor several write() methods are specified in FileChannel to throw NonWritableChannelException.
08-02-2018
EVALUATION
The submitter is correct. -- ###@###.### 2002/12/3