test/jdk/java/net/SocketOption/UnsupportedOptionsTest.java
author kvn
Wed, 13 Dec 2017 11:59:55 -0800
changeset 48397 ead47ddf5844
parent 48051 0b42613e35bf
child 49431 5812849b5027
permissions -rw-r--r--
8191788: add jdk.internal.vm.compiler to --limit-modules if -Djvmci.Compiler=graal is in the command line Summary: skip tests which use --limit-modules when Graal is used as JIT compiler. Reviewed-by: alanb, mchung, dholmes, ccheung, dnsimon
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
/*
48051
0b42613e35bf 8190843: can not set/get extendedOptions to ServerSocket
vtewari
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2017, 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
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    30
/*
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    31
 * @test
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    32
 * @bug 8143554 8044773
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    33
 * @summary Test checks that UnsupportedOperationException for unsupported
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    34
 * 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
    35
 * @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
    36
 * @run main UnsupportedOptionsTest
40261
86a49ba76f52 8136930: Simplify use of module-system options by custom launchers
mchung
parents: 38474
diff changeset
    37
 * @run main/othervm --limit-modules=java.base UnsupportedOptionsTest
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    38
 */
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    39
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    40
public class UnsupportedOptionsTest {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    41
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    42
    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
    43
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    44
    static {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    45
        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
    46
        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
    47
        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
    48
        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
    49
        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
    50
        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
    51
        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
    52
        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
    53
        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
    54
        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
    55
        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
    56
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    57
        try {
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    58
            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
    59
            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
    60
            socketOptions.add((SocketOption<?>)field.get(null));
48051
0b42613e35bf 8190843: can not set/get extendedOptions to ServerSocket
vtewari
parents: 47216
diff changeset
    61
            field = c.getField("TCP_QUICKACK");
0b42613e35bf 8190843: can not set/get extendedOptions to ServerSocket
vtewari
parents: 47216
diff changeset
    62
            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
    63
        } 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
    64
            // 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
    65
        } 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
    66
            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
    67
        }
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    68
    }
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    69
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    70
    public static void main(String[] args) throws IOException {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    71
        Socket s = new Socket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    72
        ServerSocket ss = new ServerSocket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    73
        DatagramSocket ds = new DatagramSocket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    74
        MulticastSocket ms = new MulticastSocket();
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    75
37676
24ef455da1b0 8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents: 34968
diff changeset
    76
        for (SocketOption option : socketOptions) {
34968
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    77
            if (!s.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    78
                testUnsupportedSocketOption(s, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    79
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    80
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    81
            if (!ss.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    82
                testUnsupportedSocketOption(ss, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    83
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    84
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    85
            if (!ms.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    86
                testUnsupportedSocketOption(ms, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    87
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    88
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    89
            if (!ds.supportedOptions().contains(option)) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    90
                testUnsupportedSocketOption(ds, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    91
            }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    92
        }
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
    /*
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    96
     * Check that UnsupportedOperationException for unsupported option is
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
    97
     * thrown from both getOption() and setOption() methods.
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
    private static void testUnsupportedSocketOption(Object socket,
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   100
                                                    SocketOption option) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   101
        testSet(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   102
        testGet(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   103
    }
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 testSet(Object socket, SocketOption option) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   106
        try {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   107
            setOption(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   108
        } catch (UnsupportedOperationException e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   109
            System.out.println("UnsupportedOperationException was throw " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   110
                    "as expected. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   111
            return;
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   112
        } catch (Exception e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   113
            throw new RuntimeException("FAIL. Unexpected exception.", e);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   114
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   115
        throw new RuntimeException("FAIL. UnsupportedOperationException " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   116
                "hasn't been thrown. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   117
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   118
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   119
    private static void testGet(Object socket, SocketOption option) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   120
        try {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   121
            getOption(socket, option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   122
        } catch (UnsupportedOperationException e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   123
            System.out.println("UnsupportedOperationException was throw " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   124
                    "as expected. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   125
            return;
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   126
        } catch (Exception e) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   127
            throw new RuntimeException("FAIL. Unexpected exception.", e);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   128
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   129
        throw new RuntimeException("FAIL. UnsupportedOperationException " +
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   130
                "hasn't been thrown. Socket: " + socket + " Option: " + option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   131
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   132
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   133
    private static void getOption(Object socket,
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   134
                                  SocketOption option) throws IOException {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   135
        if (socket instanceof Socket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   136
            ((Socket) socket).getOption(option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   137
        } else if (socket instanceof ServerSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   138
            ((ServerSocket) socket).getOption(option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   139
        } else if (socket instanceof DatagramSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   140
            ((DatagramSocket) socket).getOption(option);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   141
        } else {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   142
            throw new RuntimeException("Unsupported socket type");
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   143
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   144
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   145
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   146
    private static void setOption(Object socket,
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   147
                                  SocketOption option) throws IOException {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   148
        if (socket instanceof Socket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   149
            ((Socket) socket).setOption(option, null);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   150
        } else if (socket instanceof ServerSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   151
            ((ServerSocket) socket).setOption(option, null);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   152
        } else if (socket instanceof DatagramSocket) {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   153
            ((DatagramSocket) socket).setOption(option, null);
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   154
        } else {
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   155
            throw new RuntimeException("Unsupported socket type");
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   156
        }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   157
    }
93b315c61ca3 8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff changeset
   158
}