Change exception priority for ByteBuffer.put(null)
Commit 7e02765b7ada4e85f941f0a6b0fc60a8a76301f3
made ByteBuffer.put(null) throw a NullPointerException
if the ByteBuffer was read only. Previously it would
throw a ReadOnlyBufferException. The priority
of exceptions is unclear, but this returns the behavior
to what it was before and fixes 3 CTS tests:
ReadOnlyWrappedByteBufferTest.testPutByteBuffer
ReadOnlyHeapByteBufferTest.testPutByteBuffer
ReadOnlyDirectByteBufferTest.testPutByteBuffer
Change-Id: I90dd4b6969a4f31a26651d7b35758f899cc020b4
diff --git a/luni/src/main/java/java/nio/ByteBuffer.java b/luni/src/main/java/java/nio/ByteBuffer.java
index 4c0f4a6..31bf481 100644
--- a/luni/src/main/java/java/nio/ByteBuffer.java
+++ b/luni/src/main/java/java/nio/ByteBuffer.java
@@ -766,16 +766,15 @@
* if no changes may be made to the contents of this buffer.
*/
public ByteBuffer put(ByteBuffer src) {
- if (!src.isAccessible() || !isAccessible()) {
- throw new IllegalStateException("buffer is inaccessible");
- }
-
if (isReadOnly()) {
throw new ReadOnlyBufferException();
}
if (src == this) {
throw new IllegalArgumentException("src == this");
}
+ if (!src.isAccessible() || !isAccessible()) {
+ throw new IllegalStateException("buffer is inaccessible");
+ }
int srcByteCount = src.remaining();
if (srcByteCount > remaining()) {
throw new BufferOverflowException();