< prev index next >
src/java.base/share/classes/java/net/Socket.java
Print this page
@@ -31,10 +31,11 @@
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.nio.channels.SocketChannel;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.util.Objects;
import java.util.Set;
import java.util.Collections;
/**
* This class implements client sockets (also called just
@@ -1784,10 +1785,13 @@
* do not require any security permission.
*
* @since 9
*/
public <T> Socket setOption(SocketOption<T> name, T value) throws IOException {
+ Objects.requireNonNull(name);
+ if (isClosed())
+ throw new SocketException("Socket is closed");
getImpl().setOption(name, value);
return this;
}
/**
@@ -1813,10 +1817,13 @@
*
* @since 9
*/
@SuppressWarnings("unchecked")
public <T> T getOption(SocketOption<T> name) throws IOException {
+ Objects.requireNonNull(name);
+ if (isClosed())
+ throw new SocketException("Socket is closed");
return getImpl().getOption(name);
}
// cache of unmodifiable impl options. Possibly set racy, in impl we trust
private volatile Set<SocketOption<?>> options;
< prev index next >