Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/jdk/java/util/Locale/Bug8135061.java
58327 views
1
/*
2
* Copyright (c) 2016, 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
/*
25
* @test
26
* @bug 8135061
27
* @summary Checks that the Locale.lookup executes properly without throwing
28
* any exception for some specific language ranges
29
* @run main Bug8135061
30
*/
31
32
import java.util.Collection;
33
import java.util.Collections;
34
import java.util.List;
35
import java.util.Locale;
36
import java.util.Locale.LanguageRange;
37
38
public class Bug8135061 {
39
40
public static void main(String[] args) {
41
42
/* lookup should run without throwing any exception and
43
* return null as the language range does not match with the language
44
* tag
45
*/
46
List<LanguageRange> ranges = LanguageRange.parse("nv");
47
Collection<Locale> locales = Collections.singleton(Locale.ENGLISH);
48
49
try {
50
Locale match = Locale.lookup(ranges, locales);
51
if (match != null) {
52
throw new RuntimeException("Locale.lookup returned non-null: "
53
+ match);
54
}
55
} catch (Exception ex) {
56
throw new RuntimeException("[Locale.lookup failed on language"
57
+ " range: " + ranges + " and language tags "
58
+ locales + "]", ex);
59
}
60
61
/* lookup should run without throwing any exception and
62
* return "nv" as the matching tag
63
*/
64
ranges = LanguageRange.parse("i-navajo");
65
locales = Collections.singleton(new Locale("nv"));
66
67
try {
68
Locale match = Locale.lookup(ranges, locales);
69
if (!match.toLanguageTag().equals("nv")) {
70
throw new RuntimeException("Locale.lookup returned unexpected"
71
+ " result: " + match);
72
}
73
} catch (Exception ex) {
74
throw new RuntimeException("[Locale.lookup failed on language"
75
+ " range: " + ranges + " and language tags "
76
+ locales + "]", ex);
77
}
78
79
}
80
81
}
82
83