Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/naming/InitialContext/AppletIsNotUsed.java
41149 views
1
/*
2
* Copyright (c) 2014, 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 javax.naming.Context;
25
import javax.naming.InitialContext;
26
import javax.naming.NamingException;
27
import javax.naming.NoInitialContextException;
28
import java.util.Hashtable;
29
30
/*
31
* @test
32
* @bug 8051422
33
* @summary Make sure java.applet.Applet is not used as a source of
34
* configuration parameters for an InitialContext
35
*/
36
public class AppletIsNotUsed {
37
38
@SuppressWarnings("deprecation")
39
public static void main(String[] args) throws NamingException {
40
41
testWith(Context.APPLET);
42
testWith("java.naming.applet");
43
44
}
45
46
private static void testWith(String appletProperty) throws NamingException {
47
Hashtable<Object, Object> env = new Hashtable<>();
48
// Deliberately put java.lang.Object rather than java.applet.Applet
49
// if an applet was used we would see a ClassCastException down there
50
env.put(appletProperty, new Object());
51
// It's ok to instantiate InitialContext with no parameters
52
// and be unaware of it right until you try to use it
53
Context ctx = new InitialContext(env);
54
boolean threw = true;
55
try {
56
ctx.lookup("whatever");
57
threw = false;
58
} catch (NoInitialContextException e) {
59
String m = e.getMessage();
60
if (m == null || m.contains("applet"))
61
throw new RuntimeException("The exception message is incorrect", e);
62
} catch (Throwable t) {
63
throw new RuntimeException(
64
"The test was supposed to catch NoInitialContextException" +
65
" here, but caught: " + t.getClass().getName(), t);
66
} finally {
67
ctx.close();
68
}
69
70
if (!threw)
71
throw new RuntimeException("The test was supposed to catch NoInitialContextException here");
72
}
73
}
74
75