src/java.base/share/classes/java/nio/channels/FileLock.java

Print this page
rev 11263 : 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
*** 125,135 **** /** * Initializes a new instance of this class. * * @param channel ! * The file channel upon whose file this lock is held * * @param position * The position within the file at which the locked region starts; * must be non-negative * --- 126,137 ---- /** * Initializes a new instance of this class. * * @param channel ! * 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,154 **** --- 147,157 ---- * 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)
*** 161,171 **** /** * Initializes a new instance of this class. * * @param channel ! * The channel upon whose file this lock is held * * @param position * The position within the file at which the locked region starts; * must be non-negative * --- 164,175 ---- /** * Initializes a new instance of this class. * * @param channel ! * 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,192 **** --- 187,197 ---- * @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)