test/jdk/java/net/SocketOption/UnsupportedOptionsTest.java
author aeubanks
Tue, 16 Apr 2019 13:06:23 -0700
changeset 54770 62b6e7587b1f
parent 49431 5812849b5027
child 54811 9db7c0f561a6
permissions -rw-r--r--
8220673: Add test library support for determining platform IP support Reviewed-by: dfuchs, chegar Contributed-by: aeubanks@google.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     1
/*
49431
5812849b5027 8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents: 48397
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     4
 *
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     7
 * published by the Free Software Foundation.
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     8
 *
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    13
 * accompanied this code).
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    14
 *
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    18
 *
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    21
 * questions.
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    22
 */
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    23
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    24
import java.io.IOException;
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    25
import java.lang.reflect.Field;
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    26
import java.net.*;
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    27
import java.util.ArrayList;
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    28
import java.util.List;
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    29
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 49431
diff changeset
    30
import jdk.test.lib.net.IPSupport;
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 49431
diff changeset
    31
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    32
/*
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    33
 * @test
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    34
 * @bug 8143554 8044773
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 49431
diff changeset
    35
 * @library /test/lib
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    36
 * @summary Test checks that UnsupportedOperationException for unsupported
49431
5812849b5027 8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents: 48397
diff changeset
    37
 *          SOCKET_OPTIONS is thrown by both getOption() and setOption() methods.
48397
ead47ddf5844 8191788: add jdk.internal.vm.compiler to --limit-modules if -Djvmci.Compiler=graal is in the command line
kvn
parents: 48051
diff changeset
    38
 * @requires !vm.graal.enabled
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    39
 * @run main UnsupportedOptionsTest
49431
5812849b5027 8198358: Align organization of TwoStacksPlainSocketImp with DualStackPlainSocketImpl [win]
igerasim
parents: 48397
diff changeset
    40
 * @run main/othervm -Djava.net.preferIPv4Stack=true UnsupportedOptionsTest
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38474
diff changeset
    41
 * @run main/othervm --limit-modules=java.base UnsupportedOptionsTest
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    42
 */
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    43
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    44
public class UnsupportedOptionsTest {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    45
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    46
    private static final List<SocketOption<?>> socketOptions = new ArrayList<>();
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    47
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    48
    static {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    49
        socketOptions.add(StandardSocketOptions.IP_MULTICAST_IF);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    50
        socketOptions.add(StandardSocketOptions.IP_MULTICAST_LOOP);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    51
        socketOptions.add(StandardSocketOptions.IP_MULTICAST_TTL);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    52
        socketOptions.add(StandardSocketOptions.IP_TOS);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    53
        socketOptions.add(StandardSocketOptions.SO_BROADCAST);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    54
        socketOptions.add(StandardSocketOptions.SO_KEEPALIVE);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    55
        socketOptions.add(StandardSocketOptions.SO_LINGER);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    56
        socketOptions.add(StandardSocketOptions.SO_RCVBUF);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    57
        socketOptions.add(StandardSocketOptions.SO_REUSEADDR);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    58
        socketOptions.add(StandardSocketOptions.SO_SNDBUF);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    59
        socketOptions.add(StandardSocketOptions.TCP_NODELAY);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    60
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    61
        try {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    62
            Class<?> c = Class.forName("jdk.net.ExtendedSocketOptions");
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    63
            Field field = c.getField("SO_FLOW_SLA");
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    64
            socketOptions.add((SocketOption<?>)field.get(null));
48051
0b42613e35bf 8190843: can not set/get extendedOptions to ServerSocket
vtewari
parents: 47216
diff changeset
    65
            field = c.getField("TCP_QUICKACK");
0b42613e35bf 8190843: can not set/get extendedOptions to ServerSocket
vtewari
parents: 47216
diff changeset
    66
            socketOptions.add((SocketOption<?>)field.get(null));
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    67
        } catch (ClassNotFoundException e) {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    68
            // ignore, jdk.net module not present
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    69
        } catch (ReflectiveOperationException e) {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    70
            throw new AssertionError(e);
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    71
        }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    72
    }
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    73
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    74
    public static void main(String[] args) throws IOException {
54770
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 49431
diff changeset
    75
        IPSupport.skipIfCurrentConfigurationIsInvalid();
62b6e7587b1f 8220673: Add test library support for determining platform IP support
aeubanks
parents: 49431
diff changeset
    76
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    77
        Socket s = new Socket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    78
        ServerSocket ss = new ServerSocket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    79
        DatagramSocket ds = new DatagramSocket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    80
        MulticastSocket ms = new MulticastSocket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    81
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    82
        for (SocketOption option : socketOptions) {
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    83
            if (!s.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    84
                testUnsupportedSocketOption(s, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    85
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    86
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    87
            if (!ss.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    88
                testUnsupportedSocketOption(ss, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    89
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    90
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    91
            if (!ms.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    92
                testUnsupportedSocketOption(ms, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    93
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    94
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    95
            if (!ds.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    96
                testUnsupportedSocketOption(ds, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    97
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    98
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    99
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   100
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   101
    /*
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   102
     * Check that UnsupportedOperationException for unsupported option is
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   103
     * thrown from both getOption() and setOption() methods.
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   104
     */
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   105
    private static void testUnsupportedSocketOption(Object socket,
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   106
                                                    SocketOption option) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   107
        testSet(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   108
        testGet(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   109
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   110
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   111
    private static void testSet(Object socket, SocketOption option) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   112
        try {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   113
            setOption(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   114
        } catch (UnsupportedOperationException e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   115
            System.out.println("UnsupportedOperationException was throw " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   116
                    "as expected. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   117
            return;
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   118
        } catch (Exception e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   119
            throw new RuntimeException("FAIL. Unexpected exception.", e);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   120
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   121
        throw new RuntimeException("FAIL. UnsupportedOperationException " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   122
                "hasn't been thrown. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   123
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   124
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   125
    private static void testGet(Object socket, SocketOption option) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   126
        try {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   127
            getOption(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   128
        } catch (UnsupportedOperationException e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   129
            System.out.println("UnsupportedOperationException was throw " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   130
                    "as expected. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   131
            return;
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   132
        } catch (Exception e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   133
            throw new RuntimeException("FAIL. Unexpected exception.", e);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   134
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   135
        throw new RuntimeException("FAIL. UnsupportedOperationException " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   136
                "hasn't been thrown. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   137
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   138
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   139
    private static void getOption(Object socket,
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   140
                                  SocketOption option) throws IOException {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   141
        if (socket instanceof Socket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   142
            ((Socket) socket).getOption(option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   143
        } else if (socket instanceof ServerSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   144
            ((ServerSocket) socket).getOption(option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   145
        } else if (socket instanceof DatagramSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   146
            ((DatagramSocket) socket).getOption(option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   147
        } else {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   148
            throw new RuntimeException("Unsupported socket type");
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   149
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   150
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   151
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   152
    private static void setOption(Object socket,
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   153
                                  SocketOption option) throws IOException {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   154
        if (socket instanceof Socket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   155
            ((Socket) socket).setOption(option, null);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   156
        } else if (socket instanceof ServerSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   157
            ((ServerSocket) socket).setOption(option, null);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   158
        } else if (socket instanceof DatagramSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   159
            ((DatagramSocket) socket).setOption(option, null);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   160
        } else {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   161
            throw new RuntimeException("Unsupported socket type");
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   162
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   163
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   164
}