jdk/test/java/util/ResourceBundle/Bug6190861.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 10138 b7572da25d15
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
     2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @bug 6190861
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @summary Make sure to always load the default locale's bundle when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * there's no bundle for the requested locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class Bug6190861 {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 10138
diff changeset
    34
    public static void main(String[] args) {
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    35
        Locale reservedLocale = Locale.getDefault();
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    36
        try {
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    37
            Locale.setDefault(new Locale("en", "US"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    39
            List localeList = new ArrayList();
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    40
            localeList.add(Locale.ENGLISH);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    41
            localeList.add(Locale.KOREA);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    42
            localeList.add(Locale.UK);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    43
            localeList.add(new Locale("en", "CA"));
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    44
            localeList.add(Locale.ENGLISH);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    46
            Iterator iter = localeList.iterator();
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    47
            while (iter.hasNext()){
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    48
                Locale currentLocale = (Locale) iter.next();
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    49
                System.out.println("\ncurrentLocale = "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                               + currentLocale.getDisplayName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    52
                ResourceBundle messages =
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    53
                    ResourceBundle.getBundle("Bug6190861Data",currentLocale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    55
                Locale messagesLocale = messages.getLocale();
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    56
                System.out.println("messagesLocale = "
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                               + messagesLocale.getDisplayName());
10138
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    58
                checkMessages(messages);
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    59
            }
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    60
        } finally {
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    61
            // restore the reserved locale
b7572da25d15 7068662: Reserve and restore the default locale
xuelei
parents: 5506
diff changeset
    62
            Locale.setDefault(reservedLocale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    static void checkMessages(ResourceBundle messages) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        String greetings = messages.getString("greetings");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        String inquiry = messages.getString("inquiry");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        String farewell = messages.getString("farewell");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        System.out.println(greetings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        System.out.println(inquiry);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        System.out.println(farewell);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        if (!greetings.equals("Hiya.")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            throw new RuntimeException("got wrong resource bundle");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}