Repository: netty/netty
Issue: Docs of method 'io.netty.util.internal.MathUtil#isOutOfBounds' needs to be modified

### Expected behavior
the docs about the 'retun value' of the method `io.netty.util.internal.MathUtil#isOutOfBounds`is not correct.
It shoud be:
>      * @return {@code false} if the requested {@code index} and {@code length} will fit within {@code capacity}.
>      * {@code true} if this would result in an index out of bounds exception.
### Actual behavior
Actually it is the opposite:
>      * @return {@code true} if the requested {@code index} and {@code length} will fit within {@code capacity}.
>      * {@code false} if this would result in an index out of bounds exception.
The original doc and code as following:
> /**
>      * Determine if the requested {@code index} and {@code length} will fit within {@code capacity}.
>      * @param index The starting index.
>      * @param length The length which will be utilized (starting from {@code index}).
>      * @param capacity The capacity that {@code index + length} is allowed to be within.
>      * @return {@code true} if the requested {@code index} and {@code length} will fit within {@code capacity}.
>      * {@code false} if this would result in an index out of bounds exception.
>      */
>     public static boolean isOutOfBounds(int index, int length, int capacity) {
>         return (index | length | (index + length) | (capacity - (index + length))) < 0;
>     }

### Steps to reproduce
see above.
### Minimal yet complete reproducer code (or URL to code)
see above.
### Netty version
4.1.
### JVM version (e.g. `java -version`)
does not matter.
### OS version (e.g. `uname -a`)
does not matter.

Issue comments:

Pull request review comments:

Patch that resolved the issue:
diff --git a/common/src/main/java/io/netty/util/internal/MathUtil.java b/common/src/main/java/io/netty/util/internal/MathUtil.java
index 68777e6d8e2..fd8e165eccf 100644
--- a/common/src/main/java/io/netty/util/internal/MathUtil.java
+++ b/common/src/main/java/io/netty/util/internal/MathUtil.java
@@ -57,11 +57,11 @@ public static int safeFindNextPositivePowerOfTwo(final int value) {
      * @param index The starting index.
      * @param length The length which will be utilized (starting from {@code index}).
      * @param capacity The capacity that {@code index + length} is allowed to be within.
-     * @return {@code true} if the requested {@code index} and {@code length} will fit within {@code capacity}.
-     * {@code false} if this would result in an index out of bounds exception.
+     * @return {@code false} if the requested {@code index} and {@code length} will fit within {@code capacity}.
+     * {@code true} if this would result in an index out of bounds exception.
      */
     public static boolean isOutOfBounds(int index, int length, int capacity) {
-        return (index | length | (index + length) | (capacity - (index + length))) < 0;
+        return (index | length | capacity | (index + length) | (capacity - (index + length))) < 0;
     }
 
     /**


Test patch:
diff --git a/common/src/test/java/io/netty/util/internal/MathUtilTest.java b/common/src/test/java/io/netty/util/internal/MathUtilTest.java
index 32628114dd9..2fd44ced4bc 100644
--- a/common/src/test/java/io/netty/util/internal/MathUtilTest.java
+++ b/common/src/test/java/io/netty/util/internal/MathUtilTest.java
@@ -68,6 +68,9 @@ public void testIsOutOfBounds() {
         assertTrue(isOutOfBounds(Integer.MAX_VALUE - 1, 1, Integer.MAX_VALUE - 1));
         assertTrue(isOutOfBounds(Integer.MAX_VALUE - 1, 2, Integer.MAX_VALUE));
         assertTrue(isOutOfBounds(1, Integer.MAX_VALUE, Integer.MAX_VALUE));
+        assertTrue(isOutOfBounds(0, 1, Integer.MIN_VALUE));
+        assertTrue(isOutOfBounds(0, 1, -1));
+        assertTrue(isOutOfBounds(0, Integer.MAX_VALUE, 0));
     }
 
     @Test