8219876: (bf) Improve IndexOutOfBoundsException messages in $Type$Buffer classes
Reviewed-by: alanb, rriggs
This commit is contained in:
parent
5c5089b0a2
commit
7211761cab
@ -731,11 +731,6 @@ public abstract class Buffer {
|
||||
mark = -1;
|
||||
}
|
||||
|
||||
static void checkBounds(int off, int len, int size) { // package-private
|
||||
if ((off | len | (off + len) | (size - (off + len))) < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
}
|
||||
|
||||
static {
|
||||
// setup access to this package in SharedSecrets
|
||||
SharedSecrets.setJavaNioAccess(
|
||||
|
@ -206,8 +206,7 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
||||
#if[char]
|
||||
|
||||
public String toString(int start, int end) {
|
||||
if ((end > limit()) || (start > end))
|
||||
throw new IndexOutOfBoundsException();
|
||||
Objects.checkFromToIndex(start, end, limit());
|
||||
try {
|
||||
int len = end - start;
|
||||
char[] ca = new char[len];
|
||||
@ -232,8 +231,7 @@ class ByteBufferAs$Type$Buffer$RW$$BO$ // package-private
|
||||
pos = (pos <= lim ? pos : lim);
|
||||
int len = lim - pos;
|
||||
|
||||
if ((start < 0) || (end > len) || (start > end))
|
||||
throw new IndexOutOfBoundsException();
|
||||
Objects.checkFromToIndex(start, end, len);
|
||||
return new ByteBufferAsCharBuffer$RW$$BO$(bb,
|
||||
-1,
|
||||
pos + start,
|
||||
|
@ -290,7 +290,7 @@ class Direct$Type$Buffer$RW$$BO$
|
||||
public $Type$Buffer get($type$[] dst, int offset, int length) {
|
||||
#if[rw]
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_TO_ARRAY_THRESHOLD) {
|
||||
checkBounds(offset, length, dst.length);
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
int pos = position();
|
||||
int lim = limit();
|
||||
assert (pos <= lim);
|
||||
@ -439,7 +439,7 @@ class Direct$Type$Buffer$RW$$BO$
|
||||
public $Type$Buffer put($type$[] src, int offset, int length) {
|
||||
#if[rw]
|
||||
if (((long)length << $LG_BYTES_PER_VALUE$) > Bits.JNI_COPY_FROM_ARRAY_THRESHOLD) {
|
||||
checkBounds(offset, length, src.length);
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
int pos = position();
|
||||
int lim = limit();
|
||||
assert (pos <= lim);
|
||||
@ -545,8 +545,7 @@ class Direct$Type$Buffer$RW$$BO$
|
||||
#if[char]
|
||||
|
||||
public String toString(int start, int end) {
|
||||
if ((end > limit()) || (start > end))
|
||||
throw new IndexOutOfBoundsException();
|
||||
Objects.checkFromToIndex(start, end, limit());
|
||||
try {
|
||||
int len = end - start;
|
||||
char[] ca = new char[len];
|
||||
@ -571,8 +570,7 @@ class Direct$Type$Buffer$RW$$BO$
|
||||
pos = (pos <= lim ? pos : lim);
|
||||
int len = lim - pos;
|
||||
|
||||
if ((start < 0) || (end > len) || (start > end))
|
||||
throw new IndexOutOfBoundsException();
|
||||
Objects.checkFromToIndex(start, end, len);
|
||||
return new DirectCharBuffer$RW$$BO$(this,
|
||||
-1,
|
||||
pos + start,
|
||||
|
@ -173,7 +173,7 @@ class Heap$Type$Buffer$RW$
|
||||
#end[streamableType]
|
||||
|
||||
public $Type$Buffer get($type$[] dst, int offset, int length) {
|
||||
checkBounds(offset, length, dst.length);
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
int pos = position();
|
||||
if (length > limit() - pos)
|
||||
throw new BufferUnderflowException();
|
||||
@ -219,7 +219,7 @@ class Heap$Type$Buffer$RW$
|
||||
|
||||
public $Type$Buffer put($type$[] src, int offset, int length) {
|
||||
#if[rw]
|
||||
checkBounds(offset, length, src.length);
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
int pos = position();
|
||||
if (length > limit() - pos)
|
||||
throw new BufferOverflowException();
|
||||
@ -277,7 +277,7 @@ class Heap$Type$Buffer$RW$
|
||||
|
||||
public $Type$Buffer put(String src, int start, int end) {
|
||||
int length = end - start;
|
||||
checkBounds(start, length, src.length());
|
||||
Objects.checkFromIndexSize(start, length, src.length());
|
||||
if (isReadOnly())
|
||||
throw new ReadOnlyBufferException();
|
||||
int pos = position();
|
||||
@ -659,11 +659,8 @@ class Heap$Type$Buffer$RW$
|
||||
// --- Methods to support CharSequence ---
|
||||
|
||||
public CharBuffer subSequence(int start, int end) {
|
||||
if ((start < 0)
|
||||
|| (end > length())
|
||||
|| (start > end))
|
||||
throw new IndexOutOfBoundsException();
|
||||
int pos = position();
|
||||
Objects.checkFromToIndex(start, end, limit() - pos);
|
||||
return new HeapCharBuffer$RW$(hb,
|
||||
-1,
|
||||
pos + start,
|
||||
|
@ -37,8 +37,7 @@ class StringCharBuffer // package-private
|
||||
StringCharBuffer(CharSequence s, int start, int end) { // package-private
|
||||
super(-1, start, end, s.length());
|
||||
int n = s.length();
|
||||
if ((start < 0) || (start > n) || (end < start) || (end > n))
|
||||
throw new IndexOutOfBoundsException();
|
||||
Objects.checkFromToIndex(start, end, n);
|
||||
str = s;
|
||||
this.isReadOnly = true;
|
||||
}
|
||||
|
@ -772,7 +772,7 @@ public abstract class $Type$Buffer
|
||||
* parameters do not hold
|
||||
*/
|
||||
public $Type$Buffer get($type$[] dst, int offset, int length) {
|
||||
checkBounds(offset, length, dst.length);
|
||||
Objects.checkFromIndexSize(offset, length, dst.length);
|
||||
if (length > remaining())
|
||||
throw new BufferUnderflowException();
|
||||
int end = offset + length;
|
||||
@ -996,7 +996,7 @@ public abstract class $Type$Buffer
|
||||
* If this buffer is read-only
|
||||
*/
|
||||
public $Type$Buffer put($type$[] src, int offset, int length) {
|
||||
checkBounds(offset, length, src.length);
|
||||
Objects.checkFromIndexSize(offset, length, src.length);
|
||||
if (length > remaining())
|
||||
throw new BufferOverflowException();
|
||||
int end = offset + length;
|
||||
@ -1176,7 +1176,7 @@ public abstract class $Type$Buffer
|
||||
* If this buffer is read-only
|
||||
*/
|
||||
public $Type$Buffer put(String src, int start, int end) {
|
||||
checkBounds(start, end - start, src.length());
|
||||
Objects.checkFromIndexSize(start, end - start, src.length());
|
||||
if (isReadOnly())
|
||||
throw new ReadOnlyBufferException();
|
||||
if (end - start > remaining())
|
||||
|
Loading…
x
Reference in New Issue
Block a user