8065556: (bf) Buffer.position and other methods should include detail in IAE
Summary: Add messages to IAEs which have none.
Reviewed-by: alanb
--- a/jdk/src/java.base/share/classes/java/nio/Buffer.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/src/java.base/share/classes/java/nio/Buffer.java Fri Jul 24 11:52:30 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -197,7 +197,7 @@
//
Buffer(int mark, int pos, int lim, int cap) { // package-private
if (cap < 0)
- throw new IllegalArgumentException("Negative capacity: " + cap);
+ throw createCapacityException(cap);
this.capacity = cap;
limit(lim);
position(pos);
@@ -210,6 +210,34 @@
}
/**
+ * Returns an {@code IllegalArgumentException} indicating that the source
+ * and target are the same {@code Buffer}. Intended for use in
+ * {@code put(src)} when the parameter is the {@code Buffer} on which the
+ * method is being invoked.
+ *
+ * @returns IllegalArgumentException
+ * With a message indicating equal source and target buffers
+ */
+ static IllegalArgumentException createSameBufferException() {
+ return new IllegalArgumentException("The source buffer is this buffer");
+ }
+
+ /**
+ * Verify that the capacity is nonnegative.
+ *
+ * @param capacity
+ * The new buffer's capacity, in $type$s
+ *
+ * @throws IllegalArgumentException
+ * If the <tt>capacity</tt> is a negative integer
+ */
+ static IllegalArgumentException createCapacityException(int capacity) {
+ assert capacity < 0 : "capacity expected to be negative";
+ return new IllegalArgumentException("capacity < 0: ("
+ + capacity + " < 0)");
+ }
+
+ /**
* Returns this buffer's capacity.
*
* @return The capacity of this buffer
@@ -241,14 +269,36 @@
* If the preconditions on <tt>newPosition</tt> do not hold
*/
public Buffer position(int newPosition) {
- if ((newPosition > limit) || (newPosition < 0))
- throw new IllegalArgumentException();
+ if (newPosition > limit | newPosition < 0)
+ throw createPositionException(newPosition);
position = newPosition;
if (mark > position) mark = -1;
return this;
}
/**
+ * Verify that {@code 0 < newPosition <= limit}
+ *
+ * @param newPosition
+ * The new position value
+ *
+ * @throws IllegalArgumentException
+ * If the specified position is out of bounds.
+ */
+ private IllegalArgumentException createPositionException(int newPosition) {
+ String msg = null;
+
+ if (newPosition > limit) {
+ msg = "newPosition > limit: (" + newPosition + " > " + limit + ")";
+ } else { // assume negative
+ assert newPosition < 0 : "newPosition expected to be negative";
+ msg = "newPosition < 0: (" + newPosition + " < 0)";
+ }
+
+ return new IllegalArgumentException(msg);
+ }
+
+ /**
* Returns this buffer's limit.
*
* @return The limit of this buffer
@@ -272,8 +322,8 @@
* If the preconditions on <tt>newLimit</tt> do not hold
*/
public Buffer limit(int newLimit) {
- if ((newLimit > capacity) || (newLimit < 0))
- throw new IllegalArgumentException();
+ if (newLimit > capacity | newLimit < 0)
+ throw createLimitException(newLimit);
limit = newLimit;
if (position > limit) position = limit;
if (mark > limit) mark = -1;
@@ -281,6 +331,28 @@
}
/**
+ * Verify that {@code 0 < newLimit <= capacity}
+ *
+ * @param newLimit
+ * The new limit value
+ *
+ * @throws IllegalArgumentException
+ * If the specified limit is out of bounds.
+ */
+ private IllegalArgumentException createLimitException(int newLimit) {
+ String msg = null;
+
+ if (newLimit > capacity) {
+ msg = "newLimit > capacity: (" + newLimit + " > " + capacity + ")";
+ } else { // assume negative
+ assert newLimit < 0 : "newLimit expected to be negative";
+ msg = "newLimit < 0: (" + newLimit + " < 0)";
+ }
+
+ return new IllegalArgumentException(msg);
+ }
+
+ /**
* Sets this buffer's mark at its position.
*
* @return This buffer
--- a/jdk/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/src/java.base/share/classes/java/nio/Direct-X-Buffer.java.template Fri Jul 24 11:52:30 2015 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -314,7 +314,7 @@
#if[rw]
if (src instanceof Direct$Type$Buffer$BO$) {
if (src == this)
- throw new IllegalArgumentException();
+ throw createSameBufferException();
Direct$Type$Buffer$RW$$BO$ sb = (Direct$Type$Buffer$RW$$BO$)src;
int spos = sb.position();
--- a/jdk/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/src/java.base/share/classes/java/nio/Heap-X-Buffer.java.template Fri Jul 24 11:52:30 2015 -0700
@@ -216,7 +216,7 @@
#if[rw]
if (src instanceof Heap$Type$Buffer) {
if (src == this)
- throw new IllegalArgumentException();
+ throw createSameBufferException();
Heap$Type$Buffer sb = (Heap$Type$Buffer)src;
int n = sb.remaining();
if (n > remaining())
--- a/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/src/java.base/share/classes/java/nio/X-Buffer.java.template Fri Jul 24 11:52:30 2015 -0700
@@ -339,7 +339,7 @@
*/
public static $Type$Buffer allocate(int capacity) {
if (capacity < 0)
- throw new IllegalArgumentException();
+ throw createCapacityException(capacity);
return new Heap$Type$Buffer(capacity, capacity);
}
@@ -797,7 +797,7 @@
*/
public $Type$Buffer put($Type$Buffer src) {
if (src == this)
- throw new IllegalArgumentException();
+ throw createSameBufferException();
if (isReadOnly())
throw new ReadOnlyBufferException();
int n = src.remaining();
--- a/jdk/test/java/nio/Buffer/Basic-X.java.template Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/Basic-X.java.template Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -502,7 +551,8 @@
ck(b, b.get(), -Float.MIN_VALUE);
ck(b, b.get(), Float.NEGATIVE_INFINITY);
ck(b, b.get(), Float.POSITIVE_INFINITY);
- if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
+ if (Float.floatToRawIntBits(v = b.get()) !=
+ Float.floatToRawIntBits(Float.NaN))
fail(b, (long)Float.NaN, (long)v);
ck(b, b.get(), 0.91697687f);
#end[float]
@@ -934,11 +984,27 @@
public void run() {
$Type$Buffer.allocate(-1);
}});
+ try {
+ $Type$Buffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
#if[byte]
tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
public void run() {
$Type$Buffer.allocateDirect(-1);
}});
+ try {
+ $Type$Buffer.allocateDirect(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity direct buffer");
+ }
+ }
#end[byte]
}
--- a/jdk/test/java/nio/Buffer/BasicByte.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/BasicByte.java Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -518,6 +567,7 @@
+
// Comparison
b.rewind();
ByteBuffer b2 = ByteBuffer.allocate(b.capacity());
@@ -934,11 +984,27 @@
public void run() {
ByteBuffer.allocate(-1);
}});
+ try {
+ ByteBuffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
tryCatch((Buffer) null, IllegalArgumentException.class, new Runnable() {
public void run() {
ByteBuffer.allocateDirect(-1);
}});
+ try {
+ ByteBuffer.allocateDirect(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity direct buffer");
+ }
+ }
}
--- a/jdk/test/java/nio/Buffer/BasicChar.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/BasicChar.java Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -518,6 +567,7 @@
+
// Comparison
b.rewind();
CharBuffer b2 = CharBuffer.allocate(b.capacity());
@@ -934,6 +984,22 @@
public void run() {
CharBuffer.allocate(-1);
}});
+ try {
+ CharBuffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
+
+
+
+
+
+
+
+
--- a/jdk/test/java/nio/Buffer/BasicDouble.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/BasicDouble.java Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -507,6 +556,7 @@
+
ck(b, b.get(), -Double.MAX_VALUE);
ck(b, b.get(), -Double.MIN_VALUE);
ck(b, b.get(), Double.NEGATIVE_INFINITY);
@@ -934,6 +984,22 @@
public void run() {
DoubleBuffer.allocate(-1);
}});
+ try {
+ DoubleBuffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
+
+
+
+
+
+
+
+
--- a/jdk/test/java/nio/Buffer/BasicFloat.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/BasicFloat.java Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -502,7 +551,8 @@
ck(b, b.get(), -Float.MIN_VALUE);
ck(b, b.get(), Float.NEGATIVE_INFINITY);
ck(b, b.get(), Float.POSITIVE_INFINITY);
- if (Float.floatToRawIntBits(v = b.get()) != Float.floatToRawIntBits(Float.NaN))
+ if (Float.floatToRawIntBits(v = b.get()) !=
+ Float.floatToRawIntBits(Float.NaN))
fail(b, (long)Float.NaN, (long)v);
ck(b, b.get(), 0.91697687f);
@@ -934,6 +984,22 @@
public void run() {
FloatBuffer.allocate(-1);
}});
+ try {
+ FloatBuffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
+
+
+
+
+
+
+
+
--- a/jdk/test/java/nio/Buffer/BasicInt.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/BasicInt.java Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -518,6 +567,7 @@
+
// Comparison
b.rewind();
IntBuffer b2 = IntBuffer.allocate(b.capacity());
@@ -934,6 +984,22 @@
public void run() {
IntBuffer.allocate(-1);
}});
+ try {
+ IntBuffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
+
+
+
+
+
+
+
+
--- a/jdk/test/java/nio/Buffer/BasicLong.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/BasicLong.java Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -518,6 +567,7 @@
+
// Comparison
b.rewind();
LongBuffer b2 = LongBuffer.allocate(b.capacity());
@@ -934,6 +984,22 @@
public void run() {
LongBuffer.allocate(-1);
}});
+ try {
+ LongBuffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
+
+
+
+
+
+
+
+
--- a/jdk/test/java/nio/Buffer/BasicShort.java Fri Jul 24 18:57:04 2015 +0200
+++ b/jdk/test/java/nio/Buffer/BasicShort.java Fri Jul 24 11:52:30 2015 -0700
@@ -128,6 +128,15 @@
c.position(7);
b.put(c);
b.flip();
+ try {
+ b.put(b);
+ fail("IllegalArgumentException expected for put into same buffer");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected from"
+ + " put into same buffer");
+ }
+ }
}
//6231529
@@ -464,6 +473,46 @@
b.reset();
}});
+ try {
+ b.position(b.limit() + 1);
+ fail("IllegalArgumentException expected for position beyond limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " position beyond limit");
+ }
+ }
+
+ try {
+ b.position(-1);
+ fail("IllegalArgumentException expected for negative position");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative position");
+ }
+ }
+
+ try {
+ b.limit(b.capacity() + 1);
+ fail("IllegalArgumentException expected for limit beyond capacity");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " limit beyond capacity");
+ }
+ }
+
+ try {
+ b.limit(-1);
+ fail("IllegalArgumentException expected for negative limit");
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " negative limit");
+ }
+ }
+
// Values
b.clear();
@@ -518,6 +567,7 @@
+
// Comparison
b.rewind();
ShortBuffer b2 = ShortBuffer.allocate(b.capacity());
@@ -934,6 +984,22 @@
public void run() {
ShortBuffer.allocate(-1);
}});
+ try {
+ ShortBuffer.allocate(-1);
+ } catch (IllegalArgumentException e) {
+ if (e.getMessage() == null) {
+ fail("Non-null IllegalArgumentException message expected for"
+ + " attempt to allocate negative capacity buffer");
+ }
+ }
+
+
+
+
+
+
+
+