Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/registry/classPathCodebase/ClassPathCodebase.java
41155 views
1
/*
2
* Copyright (c) 1999, 2017, 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 4242317
26
* @summary When a class that can be found in the CLASSPATH of the rmiregistry
27
* tool is marshalled via RMI, it should be annotated with the value of the
28
* java.rmi.server.codebase property, not the list of "file:" URLs for the
29
* actual elements of the CLASSPATH.
30
* @author Peter Jones
31
*
32
* @library ../../testlibrary
33
* @modules java.rmi/sun.rmi.registry
34
* java.rmi/sun.rmi.server
35
* java.rmi/sun.rmi.transport
36
* java.rmi/sun.rmi.transport.tcp
37
* @build TestLibrary Dummy RegistryVM RMIRegistryRunner
38
* @run main/othervm/policy=security.policy
39
* -Djava.rmi.server.useCodebaseOnly=false ClassPathCodebase
40
*/
41
42
import java.io.*;
43
import java.net.*;
44
import java.rmi.*;
45
import java.rmi.server.*;
46
import java.rmi.registry.*;
47
import java.util.Arrays;
48
49
public class ClassPathCodebase {
50
51
/** wait dozens of seconds for the registry process to be ready to call */
52
private static final long REGISTRY_WAIT =
53
(long)(10000 * TestLibrary.getTimeoutFactor());
54
55
private final static String dummyClassName = "Dummy";
56
57
private final static String dummyBinding = "DummyObject";
58
59
private final static String importCodebase = "codebase_IMPORT_";
60
private final static String exportCodebase = "codebase_EXPORT_";
61
62
public static void main(String[] args) {
63
64
System.err.println("\nRegression test for bug 4242317\n");
65
66
TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
67
68
RegistryVM rmiregistry = null;
69
70
try {
71
/*
72
* Install a dummy class in two codebases: one that will be in
73
* the rmiregistry's CLASSPATH (the "import" codebase) and one
74
* that will be in the rmiregistry's "java.rmi.server.codebase"
75
* property (the "export" codebase).
76
*/
77
URL importCodebaseURL = TestLibrary.installClassInCodebase(
78
dummyClassName, importCodebase, false);
79
URL exportCodebaseURL = TestLibrary.installClassInCodebase(
80
dummyClassName, exportCodebase, true);
81
82
/*
83
* Spawn an rmiregistry in the "import" codebase directory.
84
*/
85
File rmiregistryDir =
86
new File(System.getProperty("user.dir", "."), importCodebase);
87
rmiregistry = RegistryVM.createRegistryVMWithRunner("RMIRegistryRunner",
88
" -Denv.class.path=. -Djava.security.manager=allow"
89
+ " -Djava.rmi.server.codebase=" + exportCodebaseURL
90
+ " -Duser.dir=" + rmiregistryDir.getAbsolutePath());
91
rmiregistry.start();
92
int port = rmiregistry.getPort();
93
94
/*
95
* Wait for the registry to initialize and be ready to call.
96
*/
97
Thread.sleep(REGISTRY_WAIT);
98
System.err.println();
99
100
/*
101
* Create an instance of the dummy class, finding it from the
102
* "import" codebase.
103
*/
104
ClassLoader loader = URLClassLoader.newInstance(
105
new URL[] { importCodebaseURL });
106
Class dummyClass = Class.forName(dummyClassName, false, loader);
107
Remote dummyObject = (Remote) dummyClass.newInstance();
108
109
/*
110
* Find the registry that we created and bind the
111
* dummy object to it.
112
*/
113
Registry registry = LocateRegistry.getRegistry(
114
"localhost", port);
115
116
try {
117
registry.bind(dummyBinding, dummyObject);
118
System.err.println("Bound dummy object in registry");
119
} catch (java.rmi.ConnectException e) {
120
System.err.println("Error: rmiregistry not started in time");
121
throw e;
122
} catch (ServerException e) {
123
if (e.detail instanceof UnmarshalException &&
124
((UnmarshalException) e.detail).detail instanceof
125
ClassNotFoundException)
126
{
127
System.err.println(
128
"Error: another registry running on port " +
129
port + "?");
130
}
131
throw e;
132
}
133
134
/*
135
* Look up the dummy object from our registry and make sure
136
* that its class was annotated with the "export" codebase.
137
*/
138
Remote dummyLookup = registry.lookup(dummyBinding);
139
System.err.println(
140
"Looked up dummy object from registry: " + dummyLookup);
141
Class dummyLookupClass = dummyLookup.getClass();
142
String dummyLookupAnnotation =
143
RMIClassLoader.getClassAnnotation(dummyLookupClass);
144
System.err.println(
145
"Class annotation from registry: " + dummyLookupAnnotation);
146
147
System.err.println();
148
if (dummyLookupAnnotation.indexOf(exportCodebase) >= 0) {
149
System.err.println("TEST PASSED");
150
} else if (dummyLookupAnnotation.indexOf(importCodebase) >= 0) {
151
throw new RuntimeException(
152
"rmiregistry annotated with CLASSPATH element URL");
153
} else {
154
throw new RuntimeException(
155
"rmiregistry used unexpected annotation: \"" +
156
dummyLookupAnnotation + "\"");
157
}
158
159
} catch (Exception e) {
160
e.printStackTrace();
161
throw new RuntimeException("TEST FAILED: " + e.toString());
162
} finally {
163
if (rmiregistry != null) {
164
rmiregistry.cleanup();
165
}
166
}
167
}
168
}
169
170