throw IAE when socket option not the expected type niosocketimpl-branch
authoralanb
Thu, 23 May 2019 12:10:48 +0100
branchniosocketimpl-branch
changeset 57368 82b83342bb31
parent 57367 276d3e540268
child 57370 8a9df09354a3
throw IAE when socket option not the expected type
src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java
--- a/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java	Thu May 23 11:07:37 2019 +0100
+++ b/src/java.base/share/classes/sun/nio/ch/NioSocketImpl.java	Thu May 23 12:10:48 2019 +0100
@@ -953,6 +953,8 @@
     protected <T> void setOption(SocketOption<T> opt, T value) throws IOException {
         if (!supportedOptions().contains(opt))
             throw new UnsupportedOperationException("'" + opt + "' not supported");
+        if (!opt.type().isInstance(value))
+            throw new IllegalArgumentException("Invalid value '" + value + "'");
         synchronized (stateLock) {
             ensureOpen();
             if (opt == StandardSocketOptions.IP_TOS) {