jdk/test/java/util/ResourceBundle/Bug4168625Test.java
author mchung
Tue, 15 Jun 2010 20:34:49 -0700
changeset 5797 c2641f6791be
parent 5506 202f599c92aa
child 5801 8008ed6e4a37
permissions -rw-r--r--
6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode Summary: Set the proper parent class loader of Loader and SimpleLoader Reviewed-by: naoto
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2007, 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
    @summary test Resource Bundle for bug 4168625
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
    @build Bug4168625Class Bug4168625Getter Bug4168625Resource Bug4168625Resource3 Bug4168625Resource3_en Bug4168625Resource3_en_CA Bug4168625Resource3_en_IE Bug4168625Resource3_en_US Bug4168625Resource2_en_US Bug4168625Resource2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
    @run main/timeout=600 Bug4168625Test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
    @bug 4168625
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * (C) Copyright IBM Corp. 1999 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Portions Copyright 2007 by Sun Microsystems, Inc.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * All rights reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This software is the confidential and proprietary information
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * of Sun Microsystems, Inc. ("Confidential Information").  You
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * shall not disclose such Confidential Information and shall use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * it only in accordance with the terms of the license agreement
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * you entered into with Sun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The original version of this source code and documentation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * copyrighted and owned by IBM. These materials are provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * under terms of a License Agreement between IBM and Sun.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * patents. This notice and attribution to IBM may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *  This test tries to correct three efficiency problems with the caching
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *  mechanism of ResourceBundle.  All tests assume that none of the bundles
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *  have been previously loaded and cached.  It also allows concurrent loads
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *  of resource bundles to be performed if the bundles are unrelated (ex. a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *  load of a local system resource by one thread while another thread is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *  doing a slow load over a network).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
public class Bug4168625Test extends RBTestFmwk {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        new Bug4168625Test().run(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Verify that getBundle will do something reasonable when part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * resource hierarchy is missing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    public void testMissingParent() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        final Locale oldDefault = Locale.getDefault();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        Locale.setDefault(new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            final Locale loc = new Locale("jf", "jf");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            ResourceBundle bundle = ResourceBundle.getBundle("Bug4168625Resource2", loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            final String s1 = bundle.getString("name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            if (!s1.equals("Bug4168625Resource2_en_US")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
                errln("getBundle did not find leaf bundle: "+bundle.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            final String s2 = bundle.getString("baseName");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            if (!s2.equals("Bug4168625Resource2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                errln("getBundle did not set up proper inheritance chain");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
            Locale.setDefault(oldDefault);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *  Previous versions of ResourceBundle have had the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *  caching behavior.  Assume the classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *  Bug4168625Resource_fr_FR, Bug4168625Resource_fr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *  Bug4168625Resource_en_US, and Bug4168625Resource_en don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *  exist.  The class Bug4168625Resource does.  Assume the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *  locale is en_US.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *  getBundle("Bug4168625Resource", new Locale("fr", "FR"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *      -->try to load Bug4168625Resource_fr_FR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *      -->try to load Bug4168625Resource_fr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *      -->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *      -->try to load Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *      -->load Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *      -->cache Bug4168625Resource as Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *      -->cache Bug4168625Resource as Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *      -->cache Bug4168625Resource as Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *      -->return Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *  getBundle("Bug4168625Resource", new Locale("fr", "FR"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     *      -->try to load Bug4168625Resource_fr_FR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *      -->try to load Bug4168625Resource_fr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     *      -->find cached Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *      -->return Bug4168625Resource_en_US (which is realy Bug4168625Resource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *  The second call causes two loads for Bug4168625Resource_fr_FR and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *  Bug4168625Resource_en which have already been tried and failed.  These
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *  two loads should have been cached as Bug4168625Resource by the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *  call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     *  The following, more efficient behavior is desired:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *  getBundle("Bug4168625Resource", new Locale("fr", "FR"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     *      -->try to load Bug4168625Resource_fr_FR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *      -->try to load Bug4168625Resource_fr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     *      -->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *      -->try to load Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     *      -->load Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     *      -->cache Bug4168625Resource as Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *      -->cache Bug4168625Resource as Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     *      -->cache Bug4168625Resource as Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *      -->cache Bug4168625Resource as Bug4168625Resource_fr
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *      -->cache Bug4168625Resource as Bug4168625Resource_fr_FR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *      -->return Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *  getBundle("Bug4168625Resource", new Locale("fr", "FR"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *      -->find cached Bug4168625Resource_fr_FR
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *      -->return Bug4168625Resource_en_US (which is realy Bug4168625Resource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public void testCacheFailures() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        checkResourceLoading("Bug4168625Resource", new Locale("fr", "FR"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *  Previous versions of ResourceBundle have had the following
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *  caching behavior.  Assume the current locale is locale is en_US.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *  The classes Bug4168625Resource_en_US, and Bug4168625Resource_en don't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *  exist.  The class Bug4168625Resource does.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *  getBundle("Bug4168625Resource", new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *      -->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *      -->try to load Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *      -->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *      -->try to load Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *      -->load Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *      -->cache Bug4168625Resource as Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *      -->cache Bug4168625Resource as Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *      -->cache Bug4168625Resource as Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *      -->return Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *  The redundant loads of Bug4168625Resource_en_US and Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *  should not occur.  The desired behavior is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *  getBundle("Bug4168625Resource", new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *      -->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *      -->try to load Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *      -->load Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *      -->cache Bug4168625Resource as Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *      -->cache Bug4168625Resource as Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *      -->cache Bug4168625Resource as Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *      -->return Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public void testRedundantLoads() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        checkResourceLoading("Bug4168625Resource", Locale.getDefault());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * Ensure that resources are only loaded once and are cached correctly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private void checkResourceLoading(String resName, Locale l) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        final Loader loader = new Loader( new String[] { "Bug4168625Class" }, new String[] { "Bug4168625Resource3_en_US", "Bug4168625Resource3_en_CA" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        final Class c = loader.loadClass("Bug4168625Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        Bug4168625Getter test = (Bug4168625Getter)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        final String resClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        if (l.toString().length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            resClassName = resName+"_"+l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            resClassName = resName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        Object bundle = test.getResourceBundle(resName, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        loader.logClasses("Initial lookup of "+resClassName+" generated the following loads:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        final Vector lastLoad = new Vector(loader.loadedClasses.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        boolean dups = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        for (int i = loader.loadedClasses.size() - 1; i >= 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            final Object item = loader.loadedClasses.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            loader.loadedClasses.removeElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            if (loader.loadedClasses.contains(item)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
                logln("Resource loaded more than once: "+item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                dups = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                lastLoad.addElement(item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (dups) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            errln("ResourceBundle loaded some classes multiple times");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        loader.loadedClasses.removeAllElements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        bundle = test.getResourceBundle(resName, l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        loader.logClasses("Second lookup of "+resClassName+" generated the following loads:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        dups = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        for (int i = 0; i < loader.loadedClasses.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            Object item = loader.loadedClasses.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            if (lastLoad.contains(item)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                logln("ResourceBundle did not cache "+item+" correctly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                dups = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (dups) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            errln("Resource bundle not caching some classes properly");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *  Previous versions of ResourceBundle exhibited the following caching behavior.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *  Assume the class Bug4168625Resource_en exists. Bug4168625Resource_en_US does
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *  not.  Two threads, ThreadA and ThreadB both try to get the same bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *  ThreadA.getBundle("Bug4168625Resource", new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *      A-->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *  ThreadB.getBundle("Bug4168625Resource", new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *      B-->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *      B-->load Bug4168625Resource_en (#1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *      A-->load Bug4168625Resource_en (#2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *      A-->cache Bug4168625Resource_en (#2) as Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     *      A-->cache Bug4168625Resource_en (#2) as Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     *      A-->return Bug4168625Resource_en (#2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *      B-->cache Bug4168625Resource_en (#1) as Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *      B-->cache Bug4168625Resource_en (#1) as Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *      B-->return Bug4168625Resource_en (#1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *  Both threads try and fail to load Bug4168625Resource_en_US.  Both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *  threads load Bug4168625Resource_en.  Both threads get their own copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *  of the Bug4168625Resource_en resource.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     *  The desired behavior is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     *  ThreadA.getBundle("Bug4168625Resource", new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *      A-->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *  ThreadB.getBundle("Bug4168625Resource", new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *      B-->try to load Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     *      B-->load Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *      A-->load Bug4168625Resource_en (block in ResourceBundle.getBundle)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *      B-->cache Bug4168625Resource_en as Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     *      B-->cache Bug4168625Resource_en as Bug4168625Resource_en_US
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *      A-->return Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *      B-->return Bug4168625Resource_en
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *  Note that both threads return the same bundle object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    public void testConcurrentLoading1() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        final Loader loader = new Loader( new String[] { "Bug4168625Class" }, new String[] { "Bug4168625Resource3_en_US", "Bug4168625Resource3_en_CA" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        final Class c = loader.loadClass("Bug4168625Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        final Bug4168625Getter test = (Bug4168625Getter)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            //both threads want the same resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        ConcurrentLoadingThread thread1 = new ConcurrentLoadingThread(loader, test, new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        ConcurrentLoadingThread thread2 = new ConcurrentLoadingThread(loader, test, new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        thread1.start();            //start thread 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        loader.waitForNotify(1);    //wait for thread1 to do getBundle & block in loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        thread2.start();            //start second thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        loader.waitForNotify(2, 1000);  //wait until thread2 blocks somewhere in getBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        thread1.ping();             //continue both threads
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        thread2.ping();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        thread1.join();             //wait unitl both threads complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        thread2.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            //Now, examine the class loads that were done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        loader.logClasses("Classes loaded after completion of both threads:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        boolean dups = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        for (int i = loader.loadedClasses.size() - 1; i >= 0 ; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            final Object item = loader.loadedClasses.elementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            loader.loadedClasses.removeElementAt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            if (loader.loadedClasses.contains(item)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                logln("Resource loaded more than once: "+item);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                dups = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if (dups) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            errln("ResourceBundle loaded some classes multiple times");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    private class ConcurrentLoadingThread extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        private Loader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        public Object bundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        private Bug4168625Getter test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        private Locale locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        private String resourceName = "Bug4168625Resource3";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        public ConcurrentLoadingThread(Loader loader, Bug4168625Getter test, Locale l, String resourceName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            this.loader = loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            this.test = test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            this.locale = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            this.resourceName = resourceName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        public ConcurrentLoadingThread(Loader loader, Bug4168625Getter test, Locale l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            this.loader = loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            this.test = test;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            this.locale = l;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
                logln(">>"+threadName()+">run");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
                bundle = test.getResourceBundle(resourceName, locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                errln("TEST CAUGHT UNEXPECTED EXCEPTION: "+e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                logln("<<"+threadName()+"<run");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        public synchronized void waitUntilPinged() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            logln(">>"+threadName()+">waitUntilPinged");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            loader.notifyEveryone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                wait(30000);    //wait 30 seconds max.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
                logln("Test deadlocked.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            logln("<<"+threadName()+"<waitUntilPinged");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        public synchronized void ping() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            logln(">>"+threadName()+">ping "+threadName(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            logln("<<"+threadName()+"<ping "+threadName(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * This test ensures that multiple resources can be loading at the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * time as long as they don't depend on each other in some way.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    public void testConcurrentLoading2() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        final Loader loader = new Loader( new String[] { "Bug4168625Class" }, new String[] { "Bug4168625Resource3_en_US", "Bug4168625Resource3_en_CA" });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        final Class c = loader.loadClass("Bug4168625Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        final Bug4168625Getter test = (Bug4168625Getter)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        ConcurrentLoadingThread thread1 = new ConcurrentLoadingThread(loader, test, new Locale("en", "CA"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        ConcurrentLoadingThread thread2 = new ConcurrentLoadingThread(loader, test, new Locale("en", "IE"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        thread1.start();            //start thread 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        loader.waitForNotify(1);    //wait for thread1 to do getBundle & block in loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
        thread2.start();            //start second thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        thread2.join(1000);         //wait until thread2 blocks somewhere in getBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            //Thread1 should be blocked inside getBundle at the class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            //Thread2 should have completed its getBundle call and terminated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        if (!thread1.isAlive() || thread2.isAlive()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            errln("ResourceBundle.getBundle not allowing legal concurrent loads");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        thread1.ping();             //continue thread1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        thread1.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        thread2.join();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * This test ensures that a resource loads correctly (with all its parents)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * when memory is very low (ex. the cache gets purged during a load).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public void testLowMemoryLoad() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        final String[] classToLoad = { "Bug4168625Class" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        final String[] classToWait = { "Bug4168625Resource3_en_US","Bug4168625Resource3_en","Bug4168625Resource3" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        final Loader loader = new Loader(classToLoad, classToWait);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        final Class c = loader.loadClass("Bug4168625Class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        final Bug4168625Getter test = (Bug4168625Getter)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        causeResourceBundleCacheFlush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        ConcurrentLoadingThread thread1 = new ConcurrentLoadingThread(loader, test, new Locale("en", "US"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        thread1.start();            //start thread 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        loader.waitForNotify(1);    //wait for thread1 to do getBundle(en_US) & block in loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        causeResourceBundleCacheFlush();    //cause a cache flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        thread1.ping();             //kick thread 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        loader.waitForNotify(2);    //wait for thread1 to do getBundle(en) & block in loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        causeResourceBundleCacheFlush();    //cause a cache flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        thread1.ping();             //kick thread 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        loader.waitForNotify(3);    //wait for thread1 to do getBundle(en) & block in loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        causeResourceBundleCacheFlush();    //cause a cache flush
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        thread1.ping();             //kick thread 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        thread1.ping();             //kick thread 1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        thread1.join(1000);         //wait until thread2 blocks somewhere in getBundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        ResourceBundle bundle = (ResourceBundle)thread1.bundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        String s1 = bundle.getString("Bug4168625Resource3_en_US");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        String s2 = bundle.getString("Bug4168625Resource3_en");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        String s3 = bundle.getString("Bug4168625Resource3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        if ((s1 == null) || (s2 == null) || (s3 == null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            errln("Bundle not constructed correctly.  The parent chain is incorrect.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * A simple class loader that loads classes from the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * working directory.  The loader will block the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * of execution before it returns when it tries to load
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * the class "Bug4168625Resource3_en_US".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    private static final String CLASS_PREFIX = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    private static final String CLASS_SUFFIX = ".class";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    private static final class SimpleLoader extends ClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        private boolean network = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        public SimpleLoader() {
5797
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   434
            super(SimpleLoader.class.getClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            this.network = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        public SimpleLoader(boolean simulateNetworkLoad) {
5797
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   438
            super(SimpleLoader.class.getClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
            this.network = simulateNetworkLoad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        public Class loadClass(final String className, final boolean resolveIt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            Class result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                result = findLoadedClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    if (network) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                             Thread.sleep(100);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                        } catch (java.lang.InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
                    }
5797
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   453
                    result = getParent().loadClass(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                    if ((result != null) && resolveIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
                        resolveClass(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    private final class Loader extends ClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        public final Vector loadedClasses = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        private String[] classesToLoad;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        private String[] classesToWaitFor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        public Loader() {
5797
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   469
            super(Loader.class.getClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            classesToLoad = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            classesToWaitFor = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        public Loader(final String[] classesToLoadIn, final String[] classesToWaitForIn) {
5797
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   475
            super(Loader.class.getClassLoader());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            classesToLoad = classesToLoadIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            classesToWaitFor = classesToWaitForIn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         * Load a class.  Files we can load take preference over ones the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         * can load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        private byte[] getClassData(final String className) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            boolean shouldLoad = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            for (int i = classesToLoad.length-1; i >= 0; --i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                if (className.equals(classesToLoad[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                    shouldLoad = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            if (shouldLoad) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                final String name = CLASS_PREFIX+className+CLASS_SUFFIX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                    final InputStream fi = this.getClass().getClassLoader().getResourceAsStream(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                    final byte[] result = new byte[fi.available()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    fi.read(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                    return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    logln("Error loading test class: "+name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    logln(e.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
         * Load a class.  Files we can load take preference over ones the system
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
         * can load.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        public Class loadClass(final String className, final boolean resolveIt)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                throws ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            Class result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            synchronized (this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                logln(">>"+threadName()+">load "+className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                loadedClasses.addElement(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                result = findLoadedClass(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    final byte[] classData = getClassData(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    if (classData == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        //we don't have a local copy of this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        logln("Loading system class: "+className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                        result = loadFromSystem(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                        result = defineClass(classData, 0, classData.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                        if (result == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                            //there was an error defining the class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                            result = loadFromSystem(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    if ((result != null) && resolveIt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        resolveClass(result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            for (int i = classesToWaitFor.length-1; i >= 0; --i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                if (className.equals(classesToWaitFor[i])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    rendezvous();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            logln("<<"+threadName()+"<load "+className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        /**
5797
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   551
         * Delegate loading to its parent class loader that loads the test classes.
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   552
         * In othervm mode, the parent class loader is the system class loader;
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   553
         * in samevm mode, the parent class loader is the jtreg URLClassLoader.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        private Class loadFromSystem(String className) throws ClassNotFoundException {
5797
c2641f6791be 6961506: TEST_BUG: ResourceBundle/Bug4168625Test.java and TestBug4179766.java fails in samevm mode
mchung
parents: 5506
diff changeset
   556
            return getParent().loadClass(className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        public void logClasses(String title) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            logln(title);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
            for (int i = 0; i < loadedClasses.size(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
                logln("    "+loadedClasses.elementAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
            logln("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        public int notifyCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        public int waitForNotify(int count) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
            return waitForNotify(count, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        public synchronized int waitForNotify(int count, long time) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            logln(">>"+threadName()+">waitForNotify");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            if (count > notifyCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    wait(time);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                } catch (InterruptedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                logln("  count("+count+") > notifyCount("+notifyCount+")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            logln("<<"+threadName()+"<waitForNotify");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            return notifyCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        private synchronized void notifyEveryone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            logln(">>"+threadName()+">notifyEveryone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            notifyCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            logln("<<"+threadName()+"<notifyEveryone");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
        private void rendezvous() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            final Thread current = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            if (current instanceof ConcurrentLoadingThread) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                ((ConcurrentLoadingThread)current).waitUntilPinged();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    private static String threadName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        return threadName(Thread.currentThread());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    private static String threadName(Thread t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        String temp = t.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        int ndx = temp.indexOf("Thread[");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        temp = temp.substring(ndx + "Thread[".length());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        ndx = temp.indexOf(',');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
        temp = temp.substring(0, ndx);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        return temp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
    /** Fill memory to force all SoftReferences to be GCed */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    private void causeResourceBundleCacheFlush() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        logln("Filling memory...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        int allocationSize = 1024;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        Vector memoryHog = new Vector();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                memoryHog.addElement(new byte[allocationSize]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                allocationSize *= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        } catch (Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            logln("Caught "+e+" filling memory");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
        } finally{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            memoryHog = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            System.gc();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
        logln("last allocation size: " + allocationSize);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     *  NOTE: this problem is not externally testable and can only be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     *  verified through code inspection unless special code to force
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *  a task switch is inserted into ResourceBundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     *  The class Bug4168625Resource_sp exists.  It's parent bundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *  (Bug4168625Resource) contains a resource string with the tag
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     *  "language" but Bug4168625Resource_sp does not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     *  Assume two threads are executing, ThreadA and ThreadB and they both
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
     *  load a resource Bug4168625Resource with from sp locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
     *  ResourceBundle.getBundle adds a bundle to the bundle cache (in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
     *  findBundle) before it sets the bundle's parent (in getBundle after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
     *  returning from findBundle).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     *  <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     *  ThreadA.getBundle("Bug4168625Resource", new Locale("sp"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     *      A-->load Bug4168625Resource_sp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     *      A-->find cached Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
     *      A-->cache Bug4168625Resource_sp as Bug4168625Resource_sp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
     *  ThreadB.getBundle("Bug4168625Resource", new Locale("sp"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
     *      B-->find cached Bug4168625Resource_sp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
     *      B-->return Bug4168625Resource_sp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     *  ThreadB.bundle.getString("language");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     *      B-->try to find "language" in Bug4168625Resource_sp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     *      B-->Bug4168625Resource_sp does not have a parent, so return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     *  ThreadB.System.out.println("Some unknown country");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     *      A-->set parent of Bug4168625Resource_sp to Bug4168625Resource
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     *      A-->return Bug4168625Resource_sp (the same bundle ThreadB got)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     *  ThreadA.bundle.getString("language");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     *      A-->try to find "language" in Bug4168625Resource_sp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     *      A-->try to find "language" in Bug4168625Resource (parent of Bug4168625Resource_sp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     *      A-->return the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
     *  ThreadA.System.out.println("Langauge = "+country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
     *  ThreadB.bundle.getString("language");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
     *      B-->try to find "language" in Bug4168625Resource_sp
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
     *      B-->try to find "language" in Bug4168625Resource (parent of Bug4168625Resource_sp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
     *      B-->return the string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
     *  ThreadB.System.out.println("Langauge = "+country);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
     *  </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
     *  <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     *  Note that the first call to getString() by ThreadB returns null, but the second
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     *  returns a value.  Thus to ThreadB, the bundle appears to change.  ThreadA gets
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     *  the expected results right away.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
}