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 Norman Maurer
parent c78c3bead0
commit 72758f7587
2 changed files with 6 additions and 3 deletions

View File

@ -203,7 +203,8 @@ final class CodecOutputList extends AbstractList<Object> implements RandomAccess
private void checkIndex(int index) { private void checkIndex(int index) {
if (index >= size) { 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 @Override
public AppendableCharSequence append(CharSequence csq, int start, int end) { public AppendableCharSequence append(CharSequence csq, int start, int end) {
if (csq.length() < end) { if (csq.length() < end) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException("expected: csq.length() >= ("
+ end + "),but actual is (" + csq.length() + ")");
} }
int length = end - start; int length = end - start;
if (length > chars.length - pos) { if (length > chars.length - pos) {
@ -138,7 +139,8 @@ public final class AppendableCharSequence implements CharSequence, Appendable {
public String substring(int start, int end) { public String substring(int start, int end) {
int length = end - start; int length = end - start;
if (start > pos || length > pos) { if (start > pos || length > pos) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException("expected: start and length <= ("
+ pos + ")");
} }
return new String(chars, start, length); return new String(chars, start, length);
} }