Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/registry/reexport/Reexport.java
41153 views
1
/*
2
* Copyright (c) 1999, 2018, 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
/* @test
25
* @bug 4120329
26
* @summary RMI registry creation is impossible if first attempt fails.
27
* @library ../../testlibrary
28
* @modules java.rmi/sun.rmi.registry
29
* java.rmi/sun.rmi.server
30
* java.rmi/sun.rmi.transport
31
* java.rmi/sun.rmi.transport.tcp
32
* @build TestLibrary
33
* @run main/othervm Reexport
34
*/
35
36
/*
37
* If a VM could not create an RMI registry because the registry port
38
* was already occupied by this or other processes, the next
39
* time the VM tried to create a registry (after the other registry
40
* was brought down) the attempt would fail. The second try to create
41
* a registry would fail because the registry ObjID would still be in
42
* use when it should never have been allocated.
43
*
44
* The test creates this conflict starting a dummy tcp server and ensures
45
* that a registry can still be created after the conflict is resolved.
46
*/
47
48
import java.io.IOException;
49
import java.net.InetSocketAddress;
50
import java.nio.channels.ServerSocketChannel;
51
import java.rmi.registry.LocateRegistry;
52
import java.rmi.registry.Registry;
53
54
public class Reexport {
55
static public void main(String[] argv) throws IOException {
56
57
for (int loop = 0; loop < 10; loop++) {
58
System.err.println("\nat loop: " + loop);
59
int port = -1;
60
try (ServerSocketChannel server = ServerSocketChannel.open();) {
61
server.bind(null);
62
InetSocketAddress addr = (InetSocketAddress)server.getLocalAddress();
63
port = addr.getPort();
64
65
System.err.println("Creating duplicate registry, this should fail...");
66
createReg(port, true);
67
}
68
try {
69
if (createReg(port, false) == null) {
70
TestLibrary.bomb("Could not create registry on second try");
71
}
72
System.err.println("Test passed");
73
return;
74
} catch (Exception e) {
75
String err = e.getMessage();
76
if (err.contains("Address already in use")
77
|| err.contains("Port already in use")) {
78
continue;
79
}
80
TestLibrary.bomb(e);
81
}
82
}
83
TestLibrary.bomb("Test failed");
84
}
85
86
static Registry createReg(int port, boolean expectException) {
87
Registry reg = null;
88
89
try {
90
reg = LocateRegistry.createRegistry(port);
91
if (expectException) {
92
TestLibrary.bomb("Registry is up, an Exception is expected!");
93
}
94
} catch (Throwable e) {
95
if (expectException) {
96
System.err.println("EXPECTING PORT IN USE EXCEPTION:");
97
System.err.println(e.getMessage());
98
e.printStackTrace();
99
} else {
100
TestLibrary.bomb((Exception) e);
101
}
102
}
103
return reg;
104
}
105
}
106
107