2
|
1 |
/*
|
10138
|
2 |
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
2
|
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 |
*
|
5506
|
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.
|
2
|
22 |
*/
|
|
23 |
/*
|
|
24 |
* @test
|
|
25 |
* @bug 6190861
|
|
26 |
* @summary Make sure to always load the default locale's bundle when
|
|
27 |
* there's no bundle for the requested locale.
|
|
28 |
*/
|
|
29 |
|
|
30 |
import java.util.*;
|
|
31 |
|
|
32 |
public class Bug6190861 {
|
|
33 |
|
|
34 |
static public void main(String[] args) {
|
10138
|
35 |
Locale reservedLocale = Locale.getDefault();
|
|
36 |
try {
|
|
37 |
Locale.setDefault(new Locale("en", "US"));
|
2
|
38 |
|
10138
|
39 |
List localeList = new ArrayList();
|
|
40 |
localeList.add(Locale.ENGLISH);
|
|
41 |
localeList.add(Locale.KOREA);
|
|
42 |
localeList.add(Locale.UK);
|
|
43 |
localeList.add(new Locale("en", "CA"));
|
|
44 |
localeList.add(Locale.ENGLISH);
|
2
|
45 |
|
10138
|
46 |
Iterator iter = localeList.iterator();
|
|
47 |
while (iter.hasNext()){
|
|
48 |
Locale currentLocale = (Locale) iter.next();
|
|
49 |
System.out.println("\ncurrentLocale = "
|
2
|
50 |
+ currentLocale.getDisplayName());
|
|
51 |
|
10138
|
52 |
ResourceBundle messages =
|
|
53 |
ResourceBundle.getBundle("Bug6190861Data",currentLocale);
|
2
|
54 |
|
10138
|
55 |
Locale messagesLocale = messages.getLocale();
|
|
56 |
System.out.println("messagesLocale = "
|
2
|
57 |
+ messagesLocale.getDisplayName());
|
10138
|
58 |
checkMessages(messages);
|
|
59 |
}
|
|
60 |
} finally {
|
|
61 |
// restore the reserved locale
|
|
62 |
Locale.setDefault(reservedLocale);
|
2
|
63 |
}
|
|
64 |
}
|
|
65 |
|
|
66 |
static void checkMessages(ResourceBundle messages) {
|
|
67 |
String greetings = messages.getString("greetings");
|
|
68 |
String inquiry = messages.getString("inquiry");
|
|
69 |
String farewell = messages.getString("farewell");
|
|
70 |
System.out.println(greetings);
|
|
71 |
System.out.println(inquiry);
|
|
72 |
System.out.println(farewell);
|
|
73 |
if (!greetings.equals("Hiya.")) {
|
|
74 |
throw new RuntimeException("got wrong resource bundle");
|
|
75 |
}
|
|
76 |
}
|
|
77 |
}
|