Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/ResourceBundle/Control/PackagePrivateTest.java
41155 views
1
/*
2
* Copyright (c) 2007, 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 4175293 5102289
26
* @summary Test if package private ResourceBundles can be loaded.
27
* @build PackagePrivateRB
28
* @run main/timeout=300/othervm -esa PackagePrivateTest
29
*/
30
31
import java.io.*;
32
import java.util.*;
33
import static java.util.ResourceBundle.Control.*;
34
35
public class PackagePrivateTest {
36
public static void main(String[] args) {
37
ResourceBundle rb;
38
39
// Make sure that the default Control can't load the package
40
// private resource bundles.
41
try {
42
rb = ResourceBundle.getBundle("PackagePrivateRB");
43
throw new RuntimeException(
44
"doesn't throw MissingResourceException with the default Control");
45
} catch (MissingResourceException e) {
46
}
47
48
// Remove the dummy cache entry
49
ResourceBundle.clearCache();
50
51
rb = ResourceBundle.getBundle("PackagePrivateRB",
52
new ResourceBundle.Control() {
53
@Override
54
public List<String> getFormats(String baseName) {
55
return FORMAT_CLASS;
56
}
57
58
@Override
59
public ResourceBundle newBundle(String baseName,
60
Locale locale,
61
String format,
62
ClassLoader loader,
63
boolean reload)
64
throws IllegalAccessException,
65
InstantiationException, IOException {
66
String bn = toBundleName(baseName, locale);
67
if ("java.class".equals(format)) {
68
try {
69
Class<? extends ResourceBundle> cl =
70
(Class<? extends ResourceBundle>) loader.loadClass(bn);
71
return cl.newInstance();
72
} catch (ClassNotFoundException e) {
73
//System.out.println("ClassNotFoundException: " + e.getMessage());
74
}
75
return null;
76
}
77
throw new IllegalArgumentException("unknown format: " + format);
78
}
79
});
80
String s = rb.getString("type");
81
if (!s.equals("class (package1.PackagePrivateRB)")) {
82
throw new RuntimeException("wrong type: got " + s + ", expected '" +
83
"class (package1.PackagePrivateRB)'");
84
}
85
}
86
}
87
88