author | chegar |
Wed, 27 Apr 2016 20:36:02 +0100 | |
changeset 37676 | 24ef455da1b0 |
parent 34968 | 93b315c61ca3 |
child 38474 | db344a94eb44 |
permissions | -rw-r--r-- |
34968
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
1 |
/* |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
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. |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
35 |
* @run main UnsupportedOptionsTest |
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/othervm -Djdk.launcher.limitmods=java.base UnsupportedOptionsTest |
34968
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
37 |
*/ |
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
38 |
|
34968
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
39 |
public class UnsupportedOptionsTest { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
40 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
41 |
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
|
42 |
|
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
43 |
static { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
44 |
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
|
45 |
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
|
46 |
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
|
47 |
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
|
48 |
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
|
49 |
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
|
50 |
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
|
51 |
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
|
52 |
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
|
53 |
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
|
54 |
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
|
55 |
|
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
56 |
try { |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
57 |
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
|
58 |
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
|
59 |
socketOptions.add((SocketOption<?>)field.get(null)); |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
60 |
} 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
|
61 |
// 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
|
62 |
} 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
|
63 |
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
|
64 |
} |
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
65 |
} |
34968
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
66 |
|
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
67 |
public static void main(String[] args) throws IOException { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
68 |
Socket s = new Socket(); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
69 |
ServerSocket ss = new ServerSocket(); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
70 |
DatagramSocket ds = new DatagramSocket(); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
71 |
MulticastSocket ms = new MulticastSocket(); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
72 |
|
37676
24ef455da1b0
8044773: Refactor jdk.net API so that it can be moved out of the base module
chegar
parents:
34968
diff
changeset
|
73 |
for (SocketOption option : socketOptions) { |
34968
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
74 |
if (!s.supportedOptions().contains(option)) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
75 |
testUnsupportedSocketOption(s, option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
76 |
} |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
77 |
|
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
78 |
if (!ss.supportedOptions().contains(option)) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
79 |
testUnsupportedSocketOption(ss, option); |
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 |
|
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
82 |
if (!ms.supportedOptions().contains(option)) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
83 |
testUnsupportedSocketOption(ms, option); |
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 |
|
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
86 |
if (!ds.supportedOptions().contains(option)) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
87 |
testUnsupportedSocketOption(ds, option); |
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 |
} |
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 |
|
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 |
* Check that UnsupportedOperationException for unsupported option is |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
94 |
* thrown from both getOption() and setOption() methods. |
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 |
private static void testUnsupportedSocketOption(Object socket, |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
97 |
SocketOption option) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
98 |
testSet(socket, option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
99 |
testGet(socket, option); |
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 |
private static void testSet(Object socket, SocketOption option) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
103 |
try { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
104 |
setOption(socket, option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
105 |
} catch (UnsupportedOperationException e) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
106 |
System.out.println("UnsupportedOperationException was throw " + |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
107 |
"as expected. Socket: " + socket + " Option: " + option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
108 |
return; |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
109 |
} catch (Exception e) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
110 |
throw new RuntimeException("FAIL. Unexpected exception.", e); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
111 |
} |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
112 |
throw new RuntimeException("FAIL. UnsupportedOperationException " + |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
113 |
"hasn't been thrown. Socket: " + socket + " Option: " + option); |
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 |
|
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
116 |
private static void testGet(Object socket, SocketOption option) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
117 |
try { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
118 |
getOption(socket, option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
119 |
} catch (UnsupportedOperationException e) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
120 |
System.out.println("UnsupportedOperationException was throw " + |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
121 |
"as expected. Socket: " + socket + " Option: " + option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
122 |
return; |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
123 |
} catch (Exception e) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
124 |
throw new RuntimeException("FAIL. Unexpected exception.", e); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
125 |
} |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
126 |
throw new RuntimeException("FAIL. UnsupportedOperationException " + |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
127 |
"hasn't been thrown. Socket: " + socket + " Option: " + option); |
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 |
|
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
130 |
private static void getOption(Object socket, |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
131 |
SocketOption option) throws IOException { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
132 |
if (socket instanceof Socket) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
133 |
((Socket) socket).getOption(option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
134 |
} else if (socket instanceof ServerSocket) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
135 |
((ServerSocket) socket).getOption(option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
136 |
} else if (socket instanceof DatagramSocket) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
137 |
((DatagramSocket) socket).getOption(option); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
138 |
} else { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
139 |
throw new RuntimeException("Unsupported socket type"); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
140 |
} |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
141 |
} |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
142 |
|
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
143 |
private static void setOption(Object socket, |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
144 |
SocketOption option) throws IOException { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
145 |
if (socket instanceof Socket) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
146 |
((Socket) socket).setOption(option, null); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
147 |
} else if (socket instanceof ServerSocket) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
148 |
((ServerSocket) socket).setOption(option, null); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
149 |
} else if (socket instanceof DatagramSocket) { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
150 |
((DatagramSocket) socket).setOption(option, null); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
151 |
} else { |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
152 |
throw new RuntimeException("Unsupported socket type"); |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
153 |
} |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
154 |
} |
93b315c61ca3
8143554: UnsupportedOperationException is not thrown for unsupported options
kshefov
parents:
diff
changeset
|
155 |
} |