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

OutputStream.write() IndexOutOfBoundsException condition could be simplified

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 7
    • core-libs
    • x86
    • windows_xp

      A DESCRIPTION OF THE REQUEST :
      OutputStream.write(byte b[], int off, int len) does some unnecessary checks in order to detect out of bounds condition. The code could be simplified. Here is proposed patch:

      --- OutputStream.java.prev Wed Dec 05 17:52:44 2007
      +++ OutputStream.java Wed Jan 02 14:28:21 2008
      @@ -107,8 +107,7 @@
           public void write(byte b[], int off, int len) throws IOException {
        if (b == null) {
        throw new NullPointerException();
      - } else if ((off < 0) || (off > b.length) || (len < 0) ||
      - ((off + len) > b.length) || ((off + len) < 0)) {
      + } else if (off < 0 || len < 0 || len > b.length - off) {
        throw new IndexOutOfBoundsException();
        } else if (len == 0) {
        return;


      JUSTIFICATION :
      it makes code cleaner

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: