Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/rmi/registry/classPathCodebase/ClassPathCodebase.java
38828 views
1
/*
2
* Copyright (c) 1999, 2013, 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
* @build TestLibrary Dummy
34
* @run main/othervm/policy=security.policy
35
* -Djava.rmi.server.useCodebaseOnly=false ClassPathCodebase
36
*/
37
38
import java.io.*;
39
import java.net.*;
40
import java.rmi.*;
41
import java.rmi.server.*;
42
import java.rmi.registry.*;
43
import java.util.Arrays;
44
45
public class ClassPathCodebase {
46
47
/** wait 10 seconds for the registry process to be ready to call */
48
private final static long REGISTRY_WAIT = 15000;
49
50
private final static String dummyClassName = "Dummy";
51
52
private final static String dummyBinding = "DummyObject";
53
54
private final static String importCodebase = "codebase_IMPORT_";
55
private final static String exportCodebase = "codebase_EXPORT_";
56
57
public static void main(String[] args) {
58
59
System.err.println("\nRegression test for bug 4242317\n");
60
61
TestLibrary.suggestSecurityManager("java.lang.SecurityManager");
62
63
Process rmiregistry = null;
64
65
try {
66
/*
67
* Install a dummy class in two codebases: one that will be in
68
* the rmiregistry's CLASSPATH (the "import" codebase) and one
69
* that will be in the rmiregistry's "java.rmi.server.codebase"
70
* property (the "export" codebase).
71
*/
72
URL importCodebaseURL = TestLibrary.installClassInCodebase(
73
dummyClassName, importCodebase, false);
74
URL exportCodebaseURL = TestLibrary.installClassInCodebase(
75
dummyClassName, exportCodebase, true);
76
77
/*
78
* Spawn an rmiregistry in the "import" codebase directory.
79
*/
80
File rmiregistryDir =
81
new File(System.getProperty("user.dir", "."), importCodebase);
82
83
String rmiregistryCommand =
84
System.getProperty("java.home") + File.separator +
85
"bin" + File.separator + "rmiregistry";
86
87
int port = TestLibrary.getUnusedRandomPort();
88
String cmdarray[] = new String[] {
89
rmiregistryCommand,
90
"-J-Denv.class.path=.",
91
"-J-Djava.rmi.server.codebase=" + exportCodebaseURL,
92
Integer.toString(port) };
93
94
System.err.println("\nCommand used to spawn rmiregistry process:");
95
System.err.println("\t" + Arrays.asList(cmdarray).toString());
96
97
rmiregistry = Runtime.getRuntime().exec(cmdarray, null, rmiregistryDir);
98
99
// pipe rmiregistry output to our output, for debugging failures
100
StreamPipe.plugTogether(rmiregistry.getInputStream(), System.err);
101
StreamPipe.plugTogether(rmiregistry.getErrorStream(), System.err);
102
103
/*
104
* Wait for the registry to initialize and be ready to call.
105
*/
106
Thread.sleep(REGISTRY_WAIT);
107
System.err.println();
108
109
/*
110
* Create an instance of the dummy class, finding it from the
111
* "import" codebase.
112
*/
113
ClassLoader loader = URLClassLoader.newInstance(
114
new URL[] { importCodebaseURL });
115
Class dummyClass = Class.forName(dummyClassName, false, loader);
116
Remote dummyObject = (Remote) dummyClass.newInstance();
117
118
/*
119
* Find the registry that we created and bind the
120
* dummy object to it.
121
*/
122
Registry registry = LocateRegistry.getRegistry(
123
"localhost", port);
124
125
try {
126
registry.bind(dummyBinding, dummyObject);
127
System.err.println("Bound dummy object in registry");
128
} catch (java.rmi.ConnectException e) {
129
System.err.println("Error: rmiregistry not started in time");
130
throw e;
131
} catch (ServerException e) {
132
if (e.detail instanceof UnmarshalException &&
133
((UnmarshalException) e.detail).detail instanceof
134
ClassNotFoundException)
135
{
136
System.err.println(
137
"Error: another registry running on port " +
138
port + "?");
139
}
140
throw e;
141
}
142
143
/*
144
* Look up the dummy object from our registry and make sure
145
* that its class was annotated with the "export" codebase.
146
*/
147
Remote dummyLookup = registry.lookup(dummyBinding);
148
System.err.println(
149
"Looked up dummy object from registry: " + dummyLookup);
150
Class dummyLookupClass = dummyLookup.getClass();
151
String dummyLookupAnnotation =
152
RMIClassLoader.getClassAnnotation(dummyLookupClass);
153
System.err.println(
154
"Class annotation from registry: " + dummyLookupAnnotation);
155
156
System.err.println();
157
if (dummyLookupAnnotation.indexOf(exportCodebase) >= 0) {
158
System.err.println("TEST PASSED");
159
} else if (dummyLookupAnnotation.indexOf(importCodebase) >= 0) {
160
throw new RuntimeException(
161
"rmiregistry annotated with CLASSPATH element URL");
162
} else {
163
throw new RuntimeException(
164
"rmiregistry used unexpected annotation: \"" +
165
dummyLookupAnnotation + "\"");
166
}
167
168
} catch (Exception e) {
169
e.printStackTrace();
170
throw new RuntimeException("TEST FAILED: " + e.toString());
171
} finally {
172
if (rmiregistry != null) {
173
rmiregistry.destroy();
174
}
175
}
176
}
177
}
178
179