src/java.base/share/classes/java/nio/channels/FileLock.java
Print this page
rev 11253 : 6880737: (fs) FileLock constructors don't throw NPE if the channel argument is null
Summary: Throw IllegalArgumentException if the channel parameter is null
Reviewed-by: TBD
@@ -125,11 +125,12 @@
/**
* Initializes a new instance of this class.
*
* @param channel
- * The file channel upon whose file this lock is held
+ * The file channel upon whose file this lock is held; must be
+ * non-{@code null}
*
* @param position
* The position within the file at which the locked region starts;
* must be non-negative
*
@@ -145,10 +146,12 @@
* If the preconditions on the parameters do not hold
*/
protected FileLock(FileChannel channel,
long position, long size, boolean shared)
{
+ if (channel == null)
+ throw new IllegalArgumentException("Null channel");
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (size < 0)
throw new IllegalArgumentException("Negative size");
if (position + size < 0)
@@ -161,11 +164,12 @@
/**
* Initializes a new instance of this class.
*
* @param channel
- * The channel upon whose file this lock is held
+ * The channel upon whose file this lock is held; must be
+ * non-{@code null}
*
* @param position
* The position within the file at which the locked region starts;
* must be non-negative
*
@@ -183,10 +187,12 @@
* @since 1.7
*/
protected FileLock(AsynchronousFileChannel channel,
long position, long size, boolean shared)
{
+ if (channel == null)
+ throw new IllegalArgumentException("Null channel");
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (size < 0)
throw new IllegalArgumentException("Negative size");
if (position + size < 0)