src/java.base/share/classes/java/nio/channels/FileLock.java
Print this page
rev 11318 : 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
*** 24,33 ****
--- 24,34 ----
*/
package java.nio.channels;
import java.io.IOException;
+ import java.util.Objects;
/**
* A token representing a lock on a region of a file.
*
* <p> A file-lock object is created each time a lock is acquired on a file via
*** 145,154 ****
--- 146,156 ----
* If the preconditions on the parameters do not hold
*/
protected FileLock(FileChannel channel,
long position, long size, boolean shared)
{
+ Objects.requireNonNull(channel, "Null channel");
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (size < 0)
throw new IllegalArgumentException("Negative size");
if (position + size < 0)
*** 183,192 ****
--- 185,195 ----
* @since 1.7
*/
protected FileLock(AsynchronousFileChannel channel,
long position, long size, boolean shared)
{
+ Objects.requireNonNull(channel, "Null channel");
if (position < 0)
throw new IllegalArgumentException("Negative position");
if (size < 0)
throw new IllegalArgumentException("Negative size");
if (position + size < 0)