Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/rmi/invalidName/InvalidName.java
41152 views
1
/*
2
* Copyright (c) 1998, 2012, 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 4136563
26
* @summary Naming.lookup fails to throw exception for invalid hostname
27
*
28
* @bug 4208801
29
* @summary (1.x) java.rmi.Naming defaults to local hostname, not
30
* local IP address
31
*
32
* @author Laird Dornin
33
*
34
* @library ../testlibrary
35
* @modules java.rmi/sun.rmi.registry
36
* java.rmi/sun.rmi.server
37
* java.rmi/sun.rmi.transport
38
* java.rmi/sun.rmi.transport.tcp
39
* @build TestLibrary
40
* @run main/othervm InvalidName
41
*/
42
43
import java.net.URL;
44
import java.net.InetAddress;
45
import java.net.MalformedURLException;
46
import java.rmi.registry.Registry;
47
import java.rmi.Naming;
48
import java.rmi.Remote;
49
import java.rmi.server.RemoteObject;
50
import java.rmi.server.UnicastRemoteObject;
51
52
public class InvalidName {
53
public static void main(String[] args) {
54
55
String testName;
56
57
// ensure that an exception is thrown for Naming URL with '#'
58
try {
59
60
System.err.println("\nRegression test for bugs " +
61
"4136563 and 4208801\n");
62
63
testName = new String("rmi://#/MyRMI");
64
65
Naming.lookup(testName);
66
System.err.println("no exception thrown for URL: " + testName);
67
throw new RuntimeException("test failed");
68
69
} catch (MalformedURLException e) {
70
// should have received malformed URL exception
71
System.err.println("Correctly received instance of " +
72
"MalformedURLException:");
73
System.err.println(e.getMessage());
74
e.printStackTrace();
75
76
} catch (Exception e) {
77
TestLibrary.bomb(e);
78
}
79
80
// ensure a correct null pointer exception is thrown for null URL
81
// ensure that a registry stub with a default hostname and one with a
82
// the local host's ip address are .equals()
83
try {
84
String localAddress = InetAddress.getLocalHost().getHostAddress();
85
86
Registry registry = (Registry) Naming.lookup("rmi:///");
87
88
if (registry.toString().indexOf(localAddress) >= 0) {
89
System.err.println("verified registry endpoint contains ipaddress");
90
} else {
91
TestLibrary.bomb("registry endpoint does not contain ipaddress");
92
}
93
} catch (Exception e) {
94
TestLibrary.bomb(e);
95
}
96
97
System.err.println("test passed");
98
}
99
}
100
101