src/java.base/share/classes/java/nio/X-Buffer.java.template
Print this page
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -328,12 +328,13 @@
*
* @throws IllegalArgumentException
* If the <tt>capacity</tt> is a negative integer
*/
public static $Type$Buffer allocate(int capacity) {
- if (capacity < 0)
- throw new IllegalArgumentException();
+ if (capacity < 0) {
+ throw negativeCapacityException(capacity);
+ }
return new Heap$Type$Buffer(capacity, capacity);
}
/**
* Wraps $a$ $type$ array into a buffer.
@@ -758,12 +759,11 @@
*
* @throws ReadOnlyBufferException
* If this buffer is read-only
*/
public $Type$Buffer put($Type$Buffer src) {
- if (src == this)
- throw new IllegalArgumentException();
+ checkSourceBufferNotThisBuffer(src);
if (isReadOnly())
throw new ReadOnlyBufferException();
int n = src.remaining();
if (n > remaining())
throw new BufferOverflowException();