Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/net/SocketOption/SupportedOptionsSet.java
41149 views
1
/*
2
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
import java.io.IOException;
25
import java.net.ServerSocket;
26
import java.net.Socket;
27
import java.util.Set;
28
import static java.lang.System.out;
29
import jdk.test.lib.net.IPSupport;
30
31
/*
32
* @test
33
* @bug 8143923
34
* @library /test/lib
35
* @summary java.net socket supportedOptions set depends on call order
36
* @run main/othervm SupportedOptionsSet first
37
* @run main/othervm SupportedOptionsSet second
38
* @run main/othervm -Djava.net.preferIPv4Stack=true SupportedOptionsSet first
39
* @run main/othervm -Djava.net.preferIPv4Stack=true SupportedOptionsSet second
40
*/
41
42
// Run with othervm as the implementation of the supported options sets, once
43
// calculated, stores them in a private static fields.
44
45
public class SupportedOptionsSet {
46
47
public static void main(String[] args) throws IOException {
48
IPSupport.throwSkippedExceptionIfNonOperational();
49
50
if (args[0].equals("first"))
51
first();
52
else if (args[0].equals("second"))
53
second();
54
}
55
56
static void first() throws IOException {
57
try (Socket s = new Socket();
58
ServerSocket ss = new ServerSocket())
59
{
60
Set<?> first = s.supportedOptions();
61
Set<?> second = ss.supportedOptions();
62
assertNotEqual(first, second,
63
"Socket and ServerSocket should have different options.");
64
}
65
}
66
67
/** Tests with the order of access to supportedOptions reversed. */
68
static void second() throws IOException {
69
try (ServerSocket ss = new ServerSocket();
70
Socket s = new Socket())
71
{
72
Set<?> first = ss.supportedOptions();
73
Set<?> second = s.supportedOptions();
74
assertNotEqual(first, second,
75
"ServerSocket and Socket should have different options.");
76
}
77
}
78
79
static void assertNotEqual(Set<?> s1, Set<?> s2, String message) {
80
if (s1.equals(s2)) {
81
out.println("s1: " + s1);
82
out.println("s2: " + s2);
83
throw new RuntimeException(message);
84
}
85
}
86
}
87
88