title: What is the logic behind Arrays.copyOfRange(byte[], int, int) strange behavior?
body: <p>Can anyone explain me the logic behind strange behavior of <a href="https://docs.oracle.com/javase/8/docs/api/java/util/Arrays.html#copyOfRange-byte:A-int-int-" rel="nofollow noreferrer"> Arrays.copyOfRange(byte[], int, int))</a>? I can illustrate what I mean with simple example:</p>
  
  <pre><code>byte[] bytes = new byte[] {1, 1, 1};
  Arrays.copyOfRange(bytes, 3, 4); // Returns single element (0) array
  Arrays.copyOfRange(bytes, 4, 5); // Throws ArrayIndexOutOfBoundsException
  </code></pre>
  
  <p>In both cases I copy ranges <strong>outside of array boundaries</strong> (i.e. <code>start &gt;= array.length</code>), so the condition for error is at least strange for me (if <code>from &lt; 0</code> or <code>from &gt; original.length</code>). In my opinion it should be: if <code>from &lt; 0</code> or <code>from &gt;= original.length</code>. Maybe I'm missing something?</p>