JDK-8164993 : (ch) ReadableByteChannel should note a possible IllegalArgumentException
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 8
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2016-08-29
  • Updated: 2019-12-03
  • Resolved: 2019-11-22
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 14
14 b25Fixed
Related Reports
CSR :  
Sub Tasks
JDK-8240909 :  
In the interface java.nio.channels.ReadableByteChannel, the read() method takes a ByteBuffer as an argument and writes the result of reading from the channel into the ByteBuffer. However, none of the error conditions noted in the documentation for this function consider the possibility that the ByteBuffer passed as an argument could be read-only, which would throw a ReadOnlyBufferException.

Documenting this possible error condition would make it clearer that a read-only ByteBuffer should not be passed to the function and could perhaps prompt programmers to check or be certain that ByteBuffers they pass for reading are not read-only.

Perhaps some wording in the comment alluding to the fact that the argument should not be a read-only ByteBuffer would probably be sufficient to serve this purpose.

URL: https://hg.openjdk.java.net/jdk/jdk/rev/46084917fde7 User: bpb Date: 2019-11-22 17:01:55 +0000

It's in fact an IllegalArgumentException which is thrown, not a ReadOnlyBufferException. The lack of a throws clause for this exists also for DatagramChannel.receive(), FileChannel positional read, and the ScatteringByteChannel read methods.