Verifies that the given length looks like a reasonable array length. This method accepts 0 as a valid length. @param buf The buffer from which the length was read. @param length The length to validate. @throws IllegalArgumentException if the length is negative or suspiciously large.
(final ChannelBuffer buf, final long length)
| 1030 | * suspiciously large. |
| 1031 | */ |
| 1032 | static void checkArrayLength(final ChannelBuffer buf, final long length) { |
| 1033 | // 2 checks in 1. If any of the high bits are set, we know the value is |
| 1034 | // either too large, or is negative (if the most-significant bit is set). |
| 1035 | if ((length & MAX_BYTE_ARRAY_MASK) != 0) { |
| 1036 | if (length < 0) { |
| 1037 | throw new IllegalArgumentException("Read negative byte array length: " |
| 1038 | + length + " in buf=" + buf + '=' + Bytes.pretty(buf)); |
| 1039 | } else { |
| 1040 | throw new IllegalArgumentException("Read byte array length that's too" |
| 1041 | + " large: " + length + " > " + ~MAX_BYTE_ARRAY_MASK + " in buf=" |
| 1042 | + buf + '=' + Bytes.pretty(buf)); |
| 1043 | } |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | /** |
| 1048 | * Verifies that the given array looks like a reasonably big array. |
no test coverage detected