Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8234536

(ch) ReadableByteChannel should note a possible IllegalArgumentException

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 14
    • core-libs
    • None
    • behavioral
    • minimal
    • Javadoc-only change with no behavioral change so no risk.
    • Java API
    • SE

      Summary

      Add missing IllegalArgumentException clauses for read-only buffer argumentss to certain java.nio channels read methods.

      Problem

      Some java.nio channels read methods will throw an IllegalArgumentException when passed a read-only buffer but this is not specified.

      Solution

      Add @throws IllegalArgumentException to the read methods where it is missing.

      Specification

      • DatagramChannel.receive - Throws: IllegalArgumentException - If the buffer is read-only

      • FileChannel.read(ByteBuffer,long) - Throws: IllegalArgumentException - If the position is negative or the buffer is read-only

      • ReadableByteChannel.read - Throws: IllegalArgumentException - If the buffer is read-only

      • ScatteringByteChannel.read methods - Throws: IllegalArgumentException - If any of the buffers is read-only

      --- old/src/java.base/share/classes/java/nio/channels/DatagramChannel.java  2019-11-20 08:54:20.000000000 -0800
      +++ new/src/java.base/share/classes/java/nio/channels/DatagramChannel.java  2019-11-20 08:54:20.000000000 -0800
      @@ -403,6 +403,9 @@
            *          or {@code null} if this channel is in non-blocking mode
            *          and no datagram was immediately available
            *
      +     * @throws  IllegalArgumentException
      +     *          If the buffer is read-only
      +     *
            * @throws  ClosedChannelException
            *          If this channel is closed
            *
      --- old/src/java.base/share/classes/java/nio/channels/FileChannel.java  2019-11-20 08:54:21.000000000 -0800
      +++ new/src/java.base/share/classes/java/nio/channels/FileChannel.java  2019-11-20 08:54:21.000000000 -0800
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -719,7 +719,7 @@
            *          size
            *
            * @throws  IllegalArgumentException
      -     *          If the position is negative
      +     *          If the position is negative or the buffer is read-only
            *
            * @throws  NonReadableChannelException
            *          If this channel was not opened for reading
      --- old/src/java.base/share/classes/java/nio/channels/ReadableByteChannel.java  2019-11-20 08:54:21.000000000 -0800
      +++ new/src/java.base/share/classes/java/nio/channels/ReadableByteChannel.java  2019-11-20 08:54:21.000000000 -0800
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -84,6 +84,9 @@
            * @return  The number of bytes read, possibly zero, or {@code -1} if the
            *          channel has reached end-of-stream
            *
      +     * @throws  IllegalArgumentException
      +     *          If the buffer is read-only
      +     *
            * @throws  NonReadableChannelException
            *          If this channel was not opened for reading
            *
      --- old/src/java.base/share/classes/java/nio/channels/ScatteringByteChannel.java    2019-11-20 08:54:22.000000000 -0800
      +++ new/src/java.base/share/classes/java/nio/channels/ScatteringByteChannel.java    2019-11-20 08:54:22.000000000 -0800
      @@ -1,5 +1,5 @@
       /*
      - * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
      + * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
        * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
        *
        * This code is free software; you can redistribute it and/or modify it
      @@ -101,6 +101,9 @@
            *          If the preconditions on the {@code offset} and {@code length}
            *          parameters do not hold
            *
      +     * @throws  IllegalArgumentException
      +     *          If any of the buffers is read-only
      +     *
            * @throws  NonReadableChannelException
            *          If this channel was not opened for reading
            *
      @@ -138,6 +141,9 @@
            * @return The number of bytes read, possibly zero,
            *         or {@code -1} if the channel has reached end-of-stream
            *
      +     * @throws  IllegalArgumentException
      +     *          If any of the buffers is read-only
      +     *
            * @throws  NonReadableChannelException
            *          If this channel was not opened for reading
            *

            bpb Brian Burkhalter
            webbuggrp Webbug Group
            Alan Bateman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: