Add IndexOutOfBoundsException error message (#10405)

Motivation:

We should provide details about why an IOOBE was thrown

Modification:

Add IndexOutOfBoundsException error information in io.netty.util.internal.AppendableCharSequence and io.netty.handler.codec.CodecOutputList class

Result:

Easier to debug
This commit is contained in:
skyguard1 2020-07-16 17:37:03 +08:00 committed by GitHub
parent cd0203b5c7
commit 9f89eb6429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -206,7 +206,8 @@ final class CodecOutputList extends AbstractList<Object> implements RandomAccess
private void checkIndex(int index) {
if (index >= size) {
throw new IndexOutOfBoundsException();
throw new IndexOutOfBoundsException("expected: index < ("
+ size + "),but actual is (" + size + ")");
}
}

View File

@ -98,7 +98,8 @@ public final class AppendableCharSequence implements CharSequence, Appendable {
@Override
public AppendableCharSequence append(CharSequence csq, int start, int end) {
if (csq.length() < end) {
throw new IndexOutOfBoundsException();
throw new IndexOutOfBoundsException("expected: csq.length() >= ("
+ end + "),but actual is (" + csq.length() + ")");
}
int length = end - start;
if (length > chars.length - pos) {
@ -138,7 +139,8 @@ public final class AppendableCharSequence implements CharSequence, Appendable {
public String substring(int start, int end) {
int length = end - start;
if (start > pos || length > pos) {
throw new IndexOutOfBoundsException();
throw new IndexOutOfBoundsException("expected: start and length <= ("
+ pos + ")");
}
return new String(chars, start, length);
}