undefect. CWE-407 — 63 sites patched across 27 ecosystems
Authors: russell@unturf.com · brackishbert@gmail.com · foxhop.net · TimeHexOn.com Patches, unit tests, benchmarks, whitepaper, and outreach briefs. Public domain — no copyright claimed. Use freely.
This commit is contained in:
commit
0a580b313d
70422 changed files with 17213626 additions and 0 deletions
79
test/jdk/java/util/ResourceBundle/Bug4083270Test.java
Normal file
79
test/jdk/java/util/ResourceBundle/Bug4083270Test.java
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
@test
|
||||
@summary test Bug 4083270
|
||||
@run main Bug4083270Test
|
||||
@bug 4083270
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
* Bug: ResourceBundle.geBundle does not check for subclass of ResourceBundle.
|
||||
* This test tries to load a properties file that has a class file with the
|
||||
* same name that isn't a subclass of ResourceBundle. If the properties
|
||||
* file is found, that means that getBundle ignored the class file because
|
||||
* it wasn't a subclass of ResourceBundle.
|
||||
*/
|
||||
public class Bug4083270Test extends RBTestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new Bug4083270Test(true).run(args);
|
||||
}
|
||||
|
||||
public Bug4083270Test(boolean dummy) {
|
||||
}
|
||||
|
||||
public Bug4083270Test() throws Exception {
|
||||
//If we get here, it means getBundle tried to instantiate this
|
||||
//class. It shouldn't since this class does not subclass
|
||||
//ResourceBundle.
|
||||
errln("ResourceBundle loaded a non-ResourceBundle class");
|
||||
}
|
||||
|
||||
public void testRecursiveResourceLoads() throws Exception {
|
||||
final String className = getClass().getName();
|
||||
try {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(className, Locale.getDefault());
|
||||
if (bundle == null) {
|
||||
errln("ResourceBundle did not find properties file");
|
||||
} else if (!(bundle instanceof PropertyResourceBundle)) {
|
||||
errln("ResourceBundle loaded a non-ResourceBundle class");
|
||||
}
|
||||
} catch (MissingResourceException e) {
|
||||
errln("ResourceBundle threw a MissingResourceException");
|
||||
}
|
||||
}
|
||||
}
|
||||
24
test/jdk/java/util/ResourceBundle/Bug4083270Test.properties
Normal file
24
test/jdk/java/util/ResourceBundle/Bug4083270Test.properties
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
Bug4179221Test=Bug4179221Test
|
||||
|
||||
77
test/jdk/java/util/ResourceBundle/Bug4165815Test.java
Normal file
77
test/jdk/java/util/ResourceBundle/Bug4165815Test.java
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
The fix for 4165815 has been backed out because of compatibility issues.
|
||||
Disabled this test temporarily until a better fix is found by removing
|
||||
the at-signs.
|
||||
test
|
||||
summary test Bug 4165815
|
||||
run main Bug4165815Test
|
||||
bug 4165815
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
/**
|
||||
* This is a regression test for the following bug:
|
||||
* "If the path specified by the baseName argument to
|
||||
* ResourceBundle.getBundle() begins with a leading slash, then the bundle
|
||||
* is not found relative to the classpath.
|
||||
*
|
||||
* Clearly, the leading slash was inappropriate, however this did work
|
||||
* previously (pre 1.2) and should continue to work in the same fashion."
|
||||
*
|
||||
* A Bundle base name should never contain a "/" and thus an
|
||||
* IllegalArgumentException should be thrown.
|
||||
*/
|
||||
public class Bug4165815Test extends RBTestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new Bug4165815Test().run(args);
|
||||
}
|
||||
|
||||
private static final String bundleName = "/Bug4165815Bundle";
|
||||
public void testIt() throws Exception {
|
||||
try {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(bundleName, Locale.US);
|
||||
errln("ResourceBundle returned a bundle when it should not have.");
|
||||
} catch (IllegalArgumentException e) {
|
||||
//This is what we should get when the base name contains a "/" character.
|
||||
} catch (MissingResourceException e) {
|
||||
errln("ResourceBundle threw a MissingResourceException when it should have thrown an IllegalArgumentException.");
|
||||
}
|
||||
}
|
||||
}
|
||||
54
test/jdk/java/util/ResourceBundle/Bug4168625Class.java
Normal file
54
test/jdk/java/util/ResourceBundle/Bug4168625Class.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Class loaded by custom class loader to load resources.
|
||||
* This call is called through the ResourceGetter interface
|
||||
* by the test. The ResourceGetter interface is loaded
|
||||
* by the system loader to avoid ClassCastsExceptions.
|
||||
*/
|
||||
public class Bug4168625Class implements Bug4168625Getter {
|
||||
/** return the specified resource or null if not found */
|
||||
public ResourceBundle getResourceBundle(String resource, Locale locale) {
|
||||
try {
|
||||
return ResourceBundle.getBundle(resource, locale);
|
||||
} catch (MissingResourceException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
54
test/jdk/java/util/ResourceBundle/Bug4168625Getter.java
Normal file
54
test/jdk/java/util/ResourceBundle/Bug4168625Getter.java
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Interface loaded by system class loader allowing
|
||||
* Bug4168625Class instances to be called by
|
||||
* test class. This class provides a common base class
|
||||
* for classes loaded by different loaders. Both the system
|
||||
* loader and the custom loader used by the Bug4168625Test
|
||||
* class load this same interface class using the system class
|
||||
* loader. The custom loader then loads a subclass that is
|
||||
* then passed back to the caller. The fact that the caller
|
||||
* and loader share a common base class allows the caller
|
||||
* to cast the object without causing a ClassCastException.
|
||||
*/
|
||||
public interface Bug4168625Getter {
|
||||
/** return the specified resource or null if not found */
|
||||
public ResourceBundle getResourceBundle(String resource, Locale locale);
|
||||
}
|
||||
47
test/jdk/java/util/ResourceBundle/Bug4168625Resource.java
Normal file
47
test/jdk/java/util/ResourceBundle/Bug4168625Resource.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource" },
|
||||
};
|
||||
}
|
||||
}
|
||||
49
test/jdk/java/util/ResourceBundle/Bug4168625Resource2.java
Normal file
49
test/jdk/java/util/ResourceBundle/Bug4168625Resource2.java
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource2 extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource2" },
|
||||
{ "baseName", "Bug4168625Resource2" },
|
||||
{ "Bug4168625Resource2", "Bug4168625Resource2" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource2_en_US extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource2_en_US" },
|
||||
{ "Bug4168625Resource2_en_US", "Bug4168625Resource2_en_US" },
|
||||
};
|
||||
}
|
||||
}
|
||||
48
test/jdk/java/util/ResourceBundle/Bug4168625Resource3.java
Normal file
48
test/jdk/java/util/ResourceBundle/Bug4168625Resource3.java
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource3 extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource3" },
|
||||
{ "Bug4168625Resource3", "Bug4168625Resource3" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource3_en extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource3_en" },
|
||||
{ "Bug4168625Resource3_en", "Bug4168625Resource3_en" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource3_en_CA extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource3_en_CA" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource3_en_IE extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource3_en_IE" },
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4168625Resource3_en_US extends ListResourceBundle {
|
||||
/**
|
||||
* Overrides ListResourceBundle
|
||||
*/
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "name", "Bug4168625Resource3" },
|
||||
{ "Bug4168625Resource3_en_US", "Bug4168625Resource3_en_US" },
|
||||
};
|
||||
}
|
||||
}
|
||||
593
test/jdk/java/util/ResourceBundle/Bug4168625Test.java
Normal file
593
test/jdk/java/util/ResourceBundle/Bug4168625Test.java
Normal file
|
|
@ -0,0 +1,593 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
@test
|
||||
@summary test Resource Bundle for bug 4168625
|
||||
@build Bug4168625Class Bug4168625Getter Bug4168625Resource Bug4168625Resource3 Bug4168625Resource3_en Bug4168625Resource3_en_CA Bug4168625Resource3_en_IE Bug4168625Resource3_en_US Bug4168625Resource2_en_US Bug4168625Resource2
|
||||
@run main/timeout=600 Bug4168625Test
|
||||
@bug 4168625 6993339
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* This test tries to correct two efficiency problems with the caching
|
||||
* mechanism of ResourceBundle. It also allows concurrent loads
|
||||
* of resource bundles to be performed if the bundles are unrelated (ex. a
|
||||
* load of a local system resource by one thread while another thread is
|
||||
* doing a slow load over a network).
|
||||
*/
|
||||
public class Bug4168625Test extends RBTestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new Bug4168625Test().run(args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify that getBundle will do something reasonable when part of the
|
||||
* resource hierarchy is missing.
|
||||
*/
|
||||
public void testMissingParent() throws Exception {
|
||||
final Locale oldDefault = Locale.getDefault();
|
||||
Locale.setDefault(Locale.US);
|
||||
try {
|
||||
final Locale loc = Locale.of("jf", "jf");
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("Bug4168625Resource2", loc);
|
||||
final String s1 = bundle.getString("name");
|
||||
if (!s1.equals("Bug4168625Resource2_en_US")) {
|
||||
errln("getBundle did not find leaf bundle: "+bundle.getClass().getName());
|
||||
}
|
||||
final String s2 = bundle.getString("baseName");
|
||||
if (!s2.equals("Bug4168625Resource2")) {
|
||||
errln("getBundle did not set up proper inheritance chain");
|
||||
}
|
||||
} finally {
|
||||
Locale.setDefault(oldDefault);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Previous versions of ResourceBundle have had the following
|
||||
* caching behavior. Assume the classes
|
||||
* Bug4168625Resource_fr_FR, Bug4168625Resource_fr,
|
||||
* Bug4168625Resource_en_US, and Bug4168625Resource_en don't
|
||||
* exist. The class Bug4168625Resource does. Assume the default
|
||||
* locale is en_US.
|
||||
* <P>
|
||||
* <pre>
|
||||
* getBundle("Bug4168625Resource", Locale.FRANCE);
|
||||
* -->try to load Bug4168625Resource_fr_FR
|
||||
* -->try to load Bug4168625Resource_fr
|
||||
* -->try to load Bug4168625Resource_en_US
|
||||
* -->try to load Bug4168625Resource_en
|
||||
* -->load Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en_US
|
||||
* -->return Bug4168625Resource
|
||||
* getBundle("Bug4168625Resource", Locale.FRANCE);
|
||||
* -->try to load Bug4168625Resource_fr_FR
|
||||
* -->try to load Bug4168625Resource_fr
|
||||
* -->find cached Bug4168625Resource_en_US
|
||||
* -->return Bug4168625Resource_en_US (which is realy Bug4168625Resource)
|
||||
* </pre>
|
||||
* <P>
|
||||
* The second call causes two loads for Bug4168625Resource_fr_FR and
|
||||
* Bug4168625Resource_en which have already been tried and failed. These
|
||||
* two loads should have been cached as Bug4168625Resource by the first
|
||||
* call.
|
||||
*
|
||||
* The following, more efficient behavior is desired:
|
||||
* <P>
|
||||
* <pre>
|
||||
* getBundle("Bug4168625Resource", Locale.FRANCE);
|
||||
* -->try to load Bug4168625Resource_fr_FR
|
||||
* -->try to load Bug4168625Resource_fr
|
||||
* -->try to load Bug4168625Resource_en_US
|
||||
* -->try to load Bug4168625Resource_en
|
||||
* -->load Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en_US
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_fr
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_fr_FR
|
||||
* -->return Bug4168625Resource
|
||||
* getBundle("Bug4168625Resource", Locale.FRANCE);
|
||||
* -->find cached Bug4168625Resource_fr_FR
|
||||
* -->return Bug4168625Resource_en_US (which is realy Bug4168625Resource)
|
||||
* </pre>
|
||||
* <P>
|
||||
*
|
||||
*/
|
||||
public void testCacheFailures() throws Exception {
|
||||
checkResourceLoading("Bug4168625Resource", Locale.FRANCE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Previous versions of ResourceBundle have had the following
|
||||
* caching behavior. Assume the current locale is locale is en_US.
|
||||
* The classes Bug4168625Resource_en_US, and Bug4168625Resource_en don't
|
||||
* exist. The class Bug4168625Resource does.
|
||||
* <P>
|
||||
* <pre>
|
||||
* getBundle("Bug4168625Resource", Locale.US);
|
||||
* -->try to load Bug4168625Resource_en_US
|
||||
* -->try to load Bug4168625Resource_en
|
||||
* -->try to load Bug4168625Resource_en_US
|
||||
* -->try to load Bug4168625Resource_en
|
||||
* -->load Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en_US
|
||||
* -->return Bug4168625Resource
|
||||
* </pre>
|
||||
* <P>
|
||||
* The redundant loads of Bug4168625Resource_en_US and Bug4168625Resource_en
|
||||
* should not occur. The desired behavior is as follows:
|
||||
* <P>
|
||||
* <pre>
|
||||
* getBundle("Bug4168625Resource", Locale.US);
|
||||
* -->try to load Bug4168625Resource_en_US
|
||||
* -->try to load Bug4168625Resource_en
|
||||
* -->load Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en
|
||||
* -->cache Bug4168625Resource as Bug4168625Resource_en_US
|
||||
* -->return Bug4168625Resource
|
||||
* </pre>
|
||||
* <P>
|
||||
*/
|
||||
public void testRedundantLoads() throws Exception {
|
||||
checkResourceLoading("Bug4168625Resource", Locale.getDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure that resources are only loaded once and are cached correctly
|
||||
*/
|
||||
private void checkResourceLoading(String resName, Locale l) throws Exception {
|
||||
final Loader loader = new Loader( new String[] { "Bug4168625Class" }, new String[] { "Bug4168625Resource3_en_US", "Bug4168625Resource3_en_CA" });
|
||||
final Class c = loader.loadClass("Bug4168625Class");
|
||||
Bug4168625Getter test = (Bug4168625Getter)c.newInstance();
|
||||
final String resClassName;
|
||||
if (l.toString().length() > 0) {
|
||||
resClassName = resName+"_"+l;
|
||||
} else {
|
||||
resClassName = resName;
|
||||
}
|
||||
|
||||
Object bundle = test.getResourceBundle(resName, l);
|
||||
loader.logClasses("Initial lookup of "+resClassName+" generated the following loads:");
|
||||
|
||||
final Vector lastLoad = new Vector(loader.loadedClasses.size());
|
||||
boolean dups = false;
|
||||
for (int i = loader.loadedClasses.size() - 1; i >= 0 ; i--) {
|
||||
final Object item = loader.loadedClasses.elementAt(i);
|
||||
loader.loadedClasses.removeElementAt(i);
|
||||
if (loader.loadedClasses.contains(item)) {
|
||||
logln("Resource loaded more than once: "+item);
|
||||
dups = true;
|
||||
} else {
|
||||
lastLoad.addElement(item);
|
||||
}
|
||||
}
|
||||
if (dups) {
|
||||
errln("ResourceBundle loaded some classes multiple times");
|
||||
}
|
||||
|
||||
loader.loadedClasses.removeAllElements();
|
||||
bundle = test.getResourceBundle(resName, l);
|
||||
loader.logClasses("Second lookup of "+resClassName+" generated the following loads:");
|
||||
|
||||
dups = false;
|
||||
for (int i = 0; i < loader.loadedClasses.size(); i++) {
|
||||
Object item = loader.loadedClasses.elementAt(i);
|
||||
if (lastLoad.contains(item)) {
|
||||
logln("ResourceBundle did not cache "+item+" correctly");
|
||||
dups = true;
|
||||
}
|
||||
}
|
||||
if (dups) {
|
||||
errln("Resource bundle not caching some classes properly");
|
||||
}
|
||||
}
|
||||
|
||||
private class ConcurrentLoadingThread extends Thread {
|
||||
private Loader loader;
|
||||
public Object bundle;
|
||||
private Bug4168625Getter test;
|
||||
private Locale locale;
|
||||
private String resourceName = "Bug4168625Resource3";
|
||||
public ConcurrentLoadingThread(Loader loader, Bug4168625Getter test, Locale l, String resourceName) {
|
||||
this.loader = loader;
|
||||
this.test = test;
|
||||
this.locale = l;
|
||||
this.resourceName = resourceName;
|
||||
}
|
||||
public ConcurrentLoadingThread(Loader loader, Bug4168625Getter test, Locale l) {
|
||||
this.loader = loader;
|
||||
this.test = test;
|
||||
this.locale = l;
|
||||
}
|
||||
public void run() {
|
||||
try {
|
||||
logln(">>"+threadName()+">run");
|
||||
bundle = test.getResourceBundle(resourceName, locale);
|
||||
} catch (Exception e) {
|
||||
errln("TEST CAUGHT UNEXPECTED EXCEPTION: "+e);
|
||||
} finally {
|
||||
logln("<<"+threadName()+"<run");
|
||||
}
|
||||
}
|
||||
public synchronized void waitUntilPinged() {
|
||||
logln(">>"+threadName()+">waitUntilPinged");
|
||||
loader.notifyEveryone();
|
||||
try {
|
||||
wait(30000); //wait 30 seconds max.
|
||||
} catch (InterruptedException e) {
|
||||
logln("Test deadlocked.");
|
||||
}
|
||||
logln("<<"+threadName()+"<waitUntilPinged");
|
||||
}
|
||||
public synchronized void ping() {
|
||||
logln(">>"+threadName()+">ping "+threadName(this));
|
||||
notifyAll();
|
||||
logln("<<"+threadName()+"<ping "+threadName(this));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* This test ensures that multiple resources can be loading at the same
|
||||
* time as long as they don't depend on each other in some way.
|
||||
*/
|
||||
public void testConcurrentLoading() throws Exception {
|
||||
final Loader loader = new Loader( new String[] { "Bug4168625Class" }, new String[] { "Bug4168625Resource3_en_US", "Bug4168625Resource3_en_CA" });
|
||||
final Class c = loader.loadClass("Bug4168625Class");
|
||||
final Bug4168625Getter test = (Bug4168625Getter)c.newInstance();
|
||||
|
||||
ConcurrentLoadingThread thread1 = new ConcurrentLoadingThread(loader, test, Locale.of("en", "CA"));
|
||||
ConcurrentLoadingThread thread2 = new ConcurrentLoadingThread(loader, test, Locale.of("en", "IE"));
|
||||
|
||||
thread1.start(); //start thread 1
|
||||
loader.waitForNotify(1); //wait for thread1 to do getBundle & block in loader
|
||||
thread2.start(); //start second thread
|
||||
thread2.join(); //wait until thread2 terminates.
|
||||
|
||||
//Thread1 should be blocked inside getBundle at the class loader
|
||||
//Thread2 should have completed its getBundle call and terminated
|
||||
if (!thread1.isAlive() || thread2.isAlive()) {
|
||||
errln("ResourceBundle.getBundle not allowing legal concurrent loads");
|
||||
}
|
||||
|
||||
thread1.ping(); //continue thread1
|
||||
thread1.join();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that a resource loads correctly (with all its parents)
|
||||
* when memory is very low (ex. the cache gets purged during a load).
|
||||
*/
|
||||
public void testLowMemoryLoad() throws Exception {
|
||||
final String[] classToLoad = { "Bug4168625Class" };
|
||||
final String[] classToWait = { "Bug4168625Resource3_en_US","Bug4168625Resource3_en","Bug4168625Resource3" };
|
||||
final Loader loader = new Loader(classToLoad, classToWait);
|
||||
final Class c = loader.loadClass("Bug4168625Class");
|
||||
final Bug4168625Getter test = (Bug4168625Getter)c.newInstance();
|
||||
causeResourceBundleCacheFlush();
|
||||
|
||||
ConcurrentLoadingThread thread1 = new ConcurrentLoadingThread(loader, test, Locale.US);
|
||||
thread1.start(); //start thread 1
|
||||
loader.waitForNotify(1); //wait for thread1 to do getBundle(en_US) & block in loader
|
||||
causeResourceBundleCacheFlush(); //cause a cache flush
|
||||
thread1.ping(); //kick thread 1
|
||||
loader.waitForNotify(2); //wait for thread1 to do getBundle(en) & block in loader
|
||||
causeResourceBundleCacheFlush(); //cause a cache flush
|
||||
thread1.ping(); //kick thread 1
|
||||
loader.waitForNotify(3); //wait for thread1 to do getBundle(en) & block in loader
|
||||
causeResourceBundleCacheFlush(); //cause a cache flush
|
||||
thread1.ping(); //kick thread 1
|
||||
thread1.join(); //wait until thread1 terminates
|
||||
|
||||
ResourceBundle bundle = (ResourceBundle)thread1.bundle;
|
||||
String s1 = bundle.getString("Bug4168625Resource3_en_US");
|
||||
String s2 = bundle.getString("Bug4168625Resource3_en");
|
||||
String s3 = bundle.getString("Bug4168625Resource3");
|
||||
if ((s1 == null) || (s2 == null) || (s3 == null)) {
|
||||
errln("Bundle not constructed correctly. The parent chain is incorrect.");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple class loader that loads classes from the current
|
||||
* working directory. The loader will block the current thread
|
||||
* of execution before it returns when it tries to load
|
||||
* the class "Bug4168625Resource3_en_US".
|
||||
*/
|
||||
private static final String CLASS_PREFIX = "";
|
||||
private static final String CLASS_SUFFIX = ".class";
|
||||
|
||||
private static final class SimpleLoader extends ClassLoader {
|
||||
private boolean network = false;
|
||||
|
||||
public SimpleLoader() {
|
||||
super(SimpleLoader.class.getClassLoader());
|
||||
this.network = false;
|
||||
}
|
||||
public SimpleLoader(boolean simulateNetworkLoad) {
|
||||
super(SimpleLoader.class.getClassLoader());
|
||||
this.network = simulateNetworkLoad;
|
||||
}
|
||||
public Class loadClass(final String className, final boolean resolveIt)
|
||||
throws ClassNotFoundException {
|
||||
Class result;
|
||||
synchronized (this) {
|
||||
result = findLoadedClass(className);
|
||||
if (result == null) {
|
||||
if (network) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
}
|
||||
}
|
||||
result = getParent().loadClass(className);
|
||||
if ((result != null) && resolveIt) {
|
||||
resolveClass(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private final class Loader extends ClassLoader {
|
||||
public final Vector loadedClasses = new Vector();
|
||||
private String[] classesToLoad;
|
||||
private String[] classesToWaitFor;
|
||||
|
||||
public Loader() {
|
||||
super(Loader.class.getClassLoader());
|
||||
classesToLoad = new String[0];
|
||||
classesToWaitFor = new String[0];
|
||||
}
|
||||
|
||||
public Loader(final String[] classesToLoadIn, final String[] classesToWaitForIn) {
|
||||
super(Loader.class.getClassLoader());
|
||||
classesToLoad = classesToLoadIn;
|
||||
classesToWaitFor = classesToWaitForIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class. Files we can load take preference over ones the system
|
||||
* can load.
|
||||
*/
|
||||
private byte[] getClassData(final String className) {
|
||||
boolean shouldLoad = false;
|
||||
for (int i = classesToLoad.length-1; i >= 0; --i) {
|
||||
if (className.equals(classesToLoad[i])) {
|
||||
shouldLoad = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldLoad) {
|
||||
final String name = CLASS_PREFIX+className+CLASS_SUFFIX;
|
||||
try {
|
||||
final InputStream fi = this.getClass().getClassLoader().getResourceAsStream(name);
|
||||
final byte[] result = new byte[fi.available()];
|
||||
fi.read(result);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
logln("Error loading test class: "+name);
|
||||
logln(e.toString());
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a class. Files we can load take preference over ones the system
|
||||
* can load.
|
||||
*/
|
||||
public Class loadClass(final String className, final boolean resolveIt)
|
||||
throws ClassNotFoundException {
|
||||
Class result;
|
||||
synchronized (this) {
|
||||
try {
|
||||
logln(">>"+threadName()+">load "+className);
|
||||
loadedClasses.addElement(className);
|
||||
|
||||
result = findLoadedClass(className);
|
||||
if (result == null) {
|
||||
final byte[] classData = getClassData(className);
|
||||
if (classData == null) {
|
||||
//we don't have a local copy of this one
|
||||
logln("Loading system class: "+className);
|
||||
result = loadFromSystem(className);
|
||||
} else {
|
||||
result = defineClass(classData, 0, classData.length);
|
||||
if (result == null) {
|
||||
//there was an error defining the class
|
||||
result = loadFromSystem(className);
|
||||
}
|
||||
}
|
||||
if ((result != null) && resolveIt) {
|
||||
resolveClass(result);
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
// Ignore loading of Bug4168625ResourceProvider
|
||||
if (className.equals("Bug4168625ResourceProvider")) {
|
||||
logln("Ignoring " + className);
|
||||
loadedClasses.remove(className);
|
||||
return null;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
for (int i = classesToWaitFor.length-1; i >= 0; --i) {
|
||||
if (className.equals(classesToWaitFor[i])) {
|
||||
rendezvous();
|
||||
break;
|
||||
}
|
||||
}
|
||||
logln("<<"+threadName()+"<load "+className);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delegate loading to its parent class loader that loads the test classes.
|
||||
* In othervm mode, the parent class loader is the system class loader;
|
||||
* in samevm mode, the parent class loader is the jtreg URLClassLoader.
|
||||
*/
|
||||
private Class loadFromSystem(String className) throws ClassNotFoundException {
|
||||
return getParent().loadClass(className);
|
||||
}
|
||||
|
||||
public void logClasses(String title) {
|
||||
logln(title);
|
||||
for (int i = 0; i < loadedClasses.size(); i++) {
|
||||
logln(" "+loadedClasses.elementAt(i));
|
||||
}
|
||||
logln("");
|
||||
}
|
||||
|
||||
public int notifyCount = 0;
|
||||
public int waitForNotify(int count) {
|
||||
return waitForNotify(count, 0);
|
||||
}
|
||||
public synchronized int waitForNotify(int count, long time) {
|
||||
logln(">>"+threadName()+">waitForNotify");
|
||||
if (count > notifyCount) {
|
||||
try {
|
||||
wait(time);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
} else {
|
||||
logln(" count("+count+") > notifyCount("+notifyCount+")");
|
||||
}
|
||||
logln("<<"+threadName()+"<waitForNotify");
|
||||
return notifyCount;
|
||||
}
|
||||
private synchronized void notifyEveryone() {
|
||||
logln(">>"+threadName()+">notifyEveryone");
|
||||
notifyCount++;
|
||||
notifyAll();
|
||||
logln("<<"+threadName()+"<notifyEveryone");
|
||||
}
|
||||
private void rendezvous() {
|
||||
final Thread current = Thread.currentThread();
|
||||
if (current instanceof ConcurrentLoadingThread) {
|
||||
((ConcurrentLoadingThread)current).waitUntilPinged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String threadName() {
|
||||
return threadName(Thread.currentThread());
|
||||
}
|
||||
|
||||
private static String threadName(Thread t) {
|
||||
String temp = t.toString();
|
||||
int ndx = temp.indexOf("Thread[");
|
||||
temp = temp.substring(ndx + "Thread[".length());
|
||||
ndx = temp.indexOf(',');
|
||||
temp = temp.substring(0, ndx);
|
||||
return temp;
|
||||
}
|
||||
|
||||
/** Fill memory to force all SoftReferences to be GCed */
|
||||
private void causeResourceBundleCacheFlush() {
|
||||
logln("Filling memory...");
|
||||
int allocationSize = 1024;
|
||||
Vector memoryHog = new Vector();
|
||||
try {
|
||||
while (true) {
|
||||
memoryHog.addElement(new byte[allocationSize]);
|
||||
allocationSize *= 2;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
logln("Caught "+e+" filling memory");
|
||||
} finally{
|
||||
memoryHog = null;
|
||||
System.gc();
|
||||
}
|
||||
logln("last allocation size: " + allocationSize);
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE: this problem is not externally testable and can only be
|
||||
* verified through code inspection unless special code to force
|
||||
* a task switch is inserted into ResourceBundle.
|
||||
* The class Bug4168625Resource_sp exists. It's parent bundle
|
||||
* (Bug4168625Resource) contains a resource string with the tag
|
||||
* "language" but Bug4168625Resource_sp does not.
|
||||
* Assume two threads are executing, ThreadA and ThreadB and they both
|
||||
* load a resource Bug4168625Resource with from sp locale.
|
||||
* ResourceBundle.getBundle adds a bundle to the bundle cache (in
|
||||
* findBundle) before it sets the bundle's parent (in getBundle after
|
||||
* returning from findBundle).
|
||||
* <P>
|
||||
* <pre>
|
||||
* ThreadA.getBundle("Bug4168625Resource", Locale.of("sp"));
|
||||
* A-->load Bug4168625Resource_sp
|
||||
* A-->find cached Bug4168625Resource
|
||||
* A-->cache Bug4168625Resource_sp as Bug4168625Resource_sp
|
||||
* ThreadB.getBundle("Bug4168625Resource", Locale.of("sp"));
|
||||
* B-->find cached Bug4168625Resource_sp
|
||||
* B-->return Bug4168625Resource_sp
|
||||
* ThreadB.bundle.getString("language");
|
||||
* B-->try to find "language" in Bug4168625Resource_sp
|
||||
* B-->Bug4168625Resource_sp does not have a parent, so return null;
|
||||
* ThreadB.System.out.println("Some unknown country");
|
||||
* A-->set parent of Bug4168625Resource_sp to Bug4168625Resource
|
||||
* A-->return Bug4168625Resource_sp (the same bundle ThreadB got)
|
||||
* ThreadA.bundle.getString("language");
|
||||
* A-->try to find "language" in Bug4168625Resource_sp
|
||||
* A-->try to find "language" in Bug4168625Resource (parent of Bug4168625Resource_sp)
|
||||
* A-->return the string
|
||||
* ThreadA.System.out.println("Langauge = "+country);
|
||||
* ThreadB.bundle.getString("language");
|
||||
* B-->try to find "language" in Bug4168625Resource_sp
|
||||
* B-->try to find "language" in Bug4168625Resource (parent of Bug4168625Resource_sp)
|
||||
* B-->return the string
|
||||
* ThreadB.System.out.println("Langauge = "+country);
|
||||
* </pre>
|
||||
* <P>
|
||||
* Note that the first call to getString() by ThreadB returns null, but the second
|
||||
* returns a value. Thus to ThreadB, the bundle appears to change. ThreadA gets
|
||||
* the expected results right away.
|
||||
*/
|
||||
}
|
||||
70
test/jdk/java/util/ResourceBundle/Bug4177489Test.java
Normal file
70
test/jdk/java/util/ResourceBundle/Bug4177489Test.java
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
@test
|
||||
@summary test Resource Bundle for bug 4177489
|
||||
@build Bug4177489_Resource Bug4177489_Resource_jf
|
||||
@run main Bug4177489Test
|
||||
@bug 4177489
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Bug4177489Test extends RBTestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new Bug4177489Test().run(args);
|
||||
}
|
||||
|
||||
public void testIt() throws Exception {
|
||||
ResourceBundle rb = ResourceBundle.getBundle( "Bug4177489_Resource" );
|
||||
Locale l = rb.getLocale();
|
||||
if (l.toString().length() > 0) {
|
||||
errln("ResourceBundle didn't handle resource class name with '_' in it.");
|
||||
}
|
||||
|
||||
Locale loc = Locale.of("jf");
|
||||
ResourceBundle rb2 = ResourceBundle.getBundle( "Bug4177489_Resource", loc );
|
||||
if (!loc.equals(rb2.getLocale())) {
|
||||
errln("ResourceBundle didn't return proper locale name:"+rb2.getLocale());
|
||||
}
|
||||
|
||||
loc = Locale.of("jf", "JF");
|
||||
ResourceBundle rb3 = ResourceBundle.getBundle("Bug4177489_Resource", loc);
|
||||
if (!loc.equals(rb3.getLocale())) {
|
||||
errln("ResourceBundle didn't return proper locale name for property bundle:"+rb3.getLocale());
|
||||
}
|
||||
}
|
||||
}
|
||||
45
test/jdk/java/util/ResourceBundle/Bug4177489_Resource.java
Normal file
45
test/jdk/java/util/ResourceBundle/Bug4177489_Resource.java
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Bug4177489_Resource extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
static final Object[][] contents = {
|
||||
{"key1", "value1"}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1999 - All Rights Reserved
|
||||
*
|
||||
* The original version of this source code and documentation is
|
||||
* copyrighted and owned by IBM. These materials are provided
|
||||
* under terms of a License Agreement between IBM and Sun.
|
||||
* This technology is protected by multiple US and International
|
||||
* patents. This notice and attribution to IBM may not be removed.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Bug4177489_Resource_jf extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
static final Object[][] contents = {
|
||||
{"keyJF", "valueJF"}
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
Bug4177489Test=Bug4177489Test
|
||||
75
test/jdk/java/util/ResourceBundle/Bug4179766Class.java
Normal file
75
test/jdk/java/util/ResourceBundle/Bug4179766Class.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file and, per its terms, should not be removed:
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
|
||||
*
|
||||
* Portions copyright (c) 2007 Sun Microsystems, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* The original version of this source code and documentation
|
||||
* is copyrighted and owned by Taligent, Inc., a wholly-owned
|
||||
* subsidiary of IBM. These materials are provided under terms
|
||||
* of a License Agreement between Taligent and Sun. This technology
|
||||
* is protected by multiple US and International patents.
|
||||
*
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL purposes and without
|
||||
* fee is hereby granted provided that this copyright notice
|
||||
* appears in all copies. Please refer to the file "copyright.html"
|
||||
* for further important copyright and licensing information.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
|
||||
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
|
||||
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
/**
|
||||
* Class loaded by custom class loader to load resources.
|
||||
* This call is called through the ResourceGetter interface
|
||||
* by the test. The ResourceGetter interface is loaded
|
||||
* by the system loader to avoid ClassCastsExceptions.
|
||||
*/
|
||||
public class Bug4179766Class implements Bug4179766Getter {
|
||||
/** return the specified resource or null if not found */
|
||||
public ResourceBundle getResourceBundle(String resource) {
|
||||
try {
|
||||
return ResourceBundle.getBundle(resource);
|
||||
} catch (MissingResourceException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
75
test/jdk/java/util/ResourceBundle/Bug4179766Getter.java
Normal file
75
test/jdk/java/util/ResourceBundle/Bug4179766Getter.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file and, per its terms, should not be removed:
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
|
||||
*
|
||||
* Portions copyright (c) 2007 Sun Microsystems, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* The original version of this source code and documentation
|
||||
* is copyrighted and owned by Taligent, Inc., a wholly-owned
|
||||
* subsidiary of IBM. These materials are provided under terms
|
||||
* of a License Agreement between Taligent and Sun. This technology
|
||||
* is protected by multiple US and International patents.
|
||||
*
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL purposes and without
|
||||
* fee is hereby granted provided that this copyright notice
|
||||
* appears in all copies. Please refer to the file "copyright.html"
|
||||
* for further important copyright and licensing information.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
|
||||
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
|
||||
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Interface loaded by system class loader allowing
|
||||
* Bug4179766Class instances to be called by
|
||||
* test class. This class provides a common base class
|
||||
* for classes loaded by different loaders. Both the system
|
||||
* loader and the custom loader used by the TestBug4179766
|
||||
* class load this same interface class using the system class
|
||||
* loader. The custom loader then loads a subclass that is
|
||||
* then passed back to the caller. The fact that the caller
|
||||
* and loader share a common base class allows the caller
|
||||
* to cast the object without causing a ClassCastException.
|
||||
*/
|
||||
public interface Bug4179766Getter {
|
||||
/** return the specified resource or null if not found */
|
||||
public ResourceBundle getResourceBundle(String resource);
|
||||
}
|
||||
96
test/jdk/java/util/ResourceBundle/Bug4179766Resource.java
Normal file
96
test/jdk/java/util/ResourceBundle/Bug4179766Resource.java
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file and, per its terms, should not be removed:
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1996 - 1999 - All Rights Reserved
|
||||
*
|
||||
* Portions copyright (c) 2007 Sun Microsystems, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* The original version of this source code and documentation
|
||||
* is copyrighted and owned by Taligent, Inc., a wholly-owned
|
||||
* subsidiary of IBM. These materials are provided under terms
|
||||
* of a License Agreement between Taligent and Sun. This technology
|
||||
* is protected by multiple US and International patents.
|
||||
*
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL purposes and without
|
||||
* fee is hereby granted provided that this copyright notice
|
||||
* appears in all copies. Please refer to the file "copyright.html"
|
||||
* for further important copyright and licensing information.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
|
||||
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
|
||||
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
/**
|
||||
* A dummy resource to be loaded by the custom class loader.
|
||||
* The contents are unimportant.
|
||||
*/
|
||||
public class Bug4179766Resource extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "MonthNames",
|
||||
new String[] {
|
||||
"January",
|
||||
"February",
|
||||
"March",
|
||||
"April",
|
||||
"May",
|
||||
"June",
|
||||
"July",
|
||||
"August",
|
||||
"September",
|
||||
"October",
|
||||
"November",
|
||||
"December",
|
||||
"",
|
||||
}
|
||||
},
|
||||
{ "DayNames",
|
||||
new String[] {
|
||||
"Sunday",
|
||||
"Monday",
|
||||
"Tuesday",
|
||||
"Wednesday",
|
||||
"Thursday",
|
||||
"Friday",
|
||||
"Saturday",
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
72
test/jdk/java/util/ResourceBundle/Bug4195978Test.java
Normal file
72
test/jdk/java/util/ResourceBundle/Bug4195978Test.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/**
|
||||
* @test
|
||||
* @bug 4195978
|
||||
* @summary Verifies that resource bundle names have case distinction.
|
||||
* @author joconner
|
||||
*/
|
||||
import java.util.*;
|
||||
|
||||
public class Bug4195978Test extends ListResourceBundle {
|
||||
|
||||
public static void main(final String args[]) throws Exception {
|
||||
new Bug4195978Test().test();
|
||||
}
|
||||
|
||||
public void test() throws Exception {
|
||||
try {
|
||||
// load a property resourcebundle
|
||||
final ResourceBundle bundle = ResourceBundle.getBundle("bug4195978Test");
|
||||
// load this file as a ListResourceBundle
|
||||
final ResourceBundle bundle2 = ResourceBundle.getBundle("Bug4195978Test");
|
||||
|
||||
// get the "test" keyid from both bundles
|
||||
String b1 = bundle.getString("test");
|
||||
String b2 = bundle2.getString("test");
|
||||
|
||||
// one should be lowercase, the other is uppercase
|
||||
// each bundle can be used seperately because their names
|
||||
// are distinguished by case.
|
||||
if (b1.equals("test") && b2.equals("TEST")) {
|
||||
System.out.println("Passed");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println("Failed");
|
||||
System.err.println(e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
Object[][] contents = {
|
||||
{"test", "TEST"},
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
59
test/jdk/java/util/ResourceBundle/Bug4257318.java
Normal file
59
test/jdk/java/util/ResourceBundle/Bug4257318.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/**
|
||||
* @test
|
||||
* @bug 4257318
|
||||
* @author John O'Conner
|
||||
* @build Bug4257318Res Bug4257318Res_en
|
||||
* @run main Bug4257318
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
|
||||
public class Bug4257318 {
|
||||
ResourceBundle res;
|
||||
boolean passed;
|
||||
|
||||
public Bug4257318() {
|
||||
passed = false;
|
||||
res = ResourceBundle.getBundle("Bug4257318Res", new java.util.Locale("","",""));
|
||||
}
|
||||
|
||||
boolean run() {
|
||||
String str = res.getString("Hello");
|
||||
passed = str.equals("Hello from the root bundle!");
|
||||
System.out.println("Root bundle string: " + str);
|
||||
return passed;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
boolean passed;
|
||||
Bug4257318 test = new Bug4257318();
|
||||
passed = test.run();
|
||||
if (!passed) {
|
||||
throw new Exception("Bug4257318 Test: FAILED");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
40
test/jdk/java/util/ResourceBundle/Bug4257318Res.java
Normal file
40
test/jdk/java/util/ResourceBundle/Bug4257318Res.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/**
|
||||
|
||||
@bug 4257318
|
||||
@author John O'Conner
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4257318Res extends ListResourceBundle {
|
||||
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
static Object[][] contents = {
|
||||
{"Hello", "Hello from the root bundle!"},
|
||||
};
|
||||
}
|
||||
40
test/jdk/java/util/ResourceBundle/Bug4257318Res_en.java
Normal file
40
test/jdk/java/util/ResourceBundle/Bug4257318Res_en.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/**
|
||||
|
||||
@bug 4257318
|
||||
@author John O'Conner
|
||||
*/
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4257318Res_en extends ListResourceBundle {
|
||||
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
static Object[][] contents = {
|
||||
{"Hello", "Hello from the en bundle!"},
|
||||
};
|
||||
}
|
||||
52
test/jdk/java/util/ResourceBundle/Bug4353454.java
Normal file
52
test/jdk/java/util/ResourceBundle/Bug4353454.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 4353454
|
||||
* @summary Test if the second getBundle call finds a bundle in the default Locale search path.
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Bug4353454 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Locale l = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(Locale.US);
|
||||
test();
|
||||
test();
|
||||
} finally {
|
||||
Locale.setDefault(l);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test() {
|
||||
ResourceBundle myResources = ResourceBundle.getBundle("RB4353454", Locale.of(""));
|
||||
if (!"Got it!".equals(myResources.getString("text"))) {
|
||||
throw new RuntimeException("returned wrong resource for key 'text': "
|
||||
+ myResources.getString("text"));
|
||||
}
|
||||
}
|
||||
}
|
||||
52
test/jdk/java/util/ResourceBundle/Bug4396021.java
Normal file
52
test/jdk/java/util/ResourceBundle/Bug4396021.java
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 4396021
|
||||
* @summary Verify that a resource bundle can override its parent.
|
||||
* @build Bug4396021GeneralMessages Bug4396021SpecialMessages
|
||||
* @run main Bug4396021
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Bug4396021 {
|
||||
|
||||
private static ResourceBundle bundle;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
bundle = ResourceBundle.getBundle("Bug4396021SpecialMessages");
|
||||
|
||||
checkValue("special_key", "special_value");
|
||||
checkValue("general_key", "general_value");
|
||||
}
|
||||
|
||||
private static void checkValue(String key, String expected) throws Exception {
|
||||
String result = bundle.getString(key);
|
||||
if (!result.equals(expected)) {
|
||||
throw new RuntimeException("Got wrong value from resource bundle"
|
||||
+ " - key: " + key + ", expected: " + expected
|
||||
+ ", got: " + result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4396021GeneralMessages extends ListResourceBundle {
|
||||
|
||||
private static final Object[][] contents = {
|
||||
{"general_key", "general_value"},
|
||||
};
|
||||
|
||||
public Bug4396021GeneralMessages() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Bug4396021SpecialMessages extends ListResourceBundle {
|
||||
|
||||
private static final Object[][] contents = {
|
||||
{"special_key", "special_value"},
|
||||
};
|
||||
|
||||
public Bug4396021SpecialMessages() {
|
||||
setParent(getBundle("Bug4396021GeneralMessages"));
|
||||
}
|
||||
|
||||
protected Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
}
|
||||
77
test/jdk/java/util/ResourceBundle/Bug6190861.java
Normal file
77
test/jdk/java/util/ResourceBundle/Bug6190861.java
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6190861
|
||||
* @summary Make sure to always load the default locale's bundle when
|
||||
* there's no bundle for the requested locale.
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Bug6190861 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Locale reservedLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(Locale.US);
|
||||
|
||||
List localeList = new ArrayList();
|
||||
localeList.add(Locale.ENGLISH);
|
||||
localeList.add(Locale.KOREA);
|
||||
localeList.add(Locale.UK);
|
||||
localeList.add(Locale.of("en", "CA"));
|
||||
localeList.add(Locale.ENGLISH);
|
||||
|
||||
Iterator iter = localeList.iterator();
|
||||
while (iter.hasNext()){
|
||||
Locale currentLocale = (Locale) iter.next();
|
||||
System.out.println("\ncurrentLocale = "
|
||||
+ currentLocale.getDisplayName());
|
||||
|
||||
ResourceBundle messages =
|
||||
ResourceBundle.getBundle("Bug6190861Data",currentLocale);
|
||||
|
||||
Locale messagesLocale = messages.getLocale();
|
||||
System.out.println("messagesLocale = "
|
||||
+ messagesLocale.getDisplayName());
|
||||
checkMessages(messages);
|
||||
}
|
||||
} finally {
|
||||
// restore the reserved locale
|
||||
Locale.setDefault(reservedLocale);
|
||||
}
|
||||
}
|
||||
|
||||
static void checkMessages(ResourceBundle messages) {
|
||||
String greetings = messages.getString("greetings");
|
||||
String inquiry = messages.getString("inquiry");
|
||||
String farewell = messages.getString("farewell");
|
||||
System.out.println(greetings);
|
||||
System.out.println(inquiry);
|
||||
System.out.println(farewell);
|
||||
if (!greetings.equals("Hiya.")) {
|
||||
throw new RuntimeException("got wrong resource bundle");
|
||||
}
|
||||
}
|
||||
}
|
||||
28
test/jdk/java/util/ResourceBundle/Bug6190861Data.properties
Normal file
28
test/jdk/java/util/ResourceBundle/Bug6190861Data.properties
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
greetings = Hello.
|
||||
farewell = Goodbye.
|
||||
inquiry = How are you?
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
greetings = Hiya.
|
||||
farewell = Seeya.
|
||||
inquiry = Howdy?
|
||||
85
test/jdk/java/util/ResourceBundle/Bug6204853.java
Normal file
85
test/jdk/java/util/ResourceBundle/Bug6204853.java
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6204853
|
||||
* @summary tests PropertyResourceBundle(Reader) constructor.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.PropertyResourceBundle;
|
||||
|
||||
public final class Bug6204853 {
|
||||
|
||||
public Bug6204853() {
|
||||
String srcDir = System.getProperty("test.src", ".");
|
||||
try (FileInputStream fis8859_1 =
|
||||
new FileInputStream(new File(srcDir, "Bug6204853.properties"));
|
||||
FileInputStream fisUtf8 =
|
||||
new FileInputStream(new File(srcDir, "Bug6204853_Utf8.properties"));
|
||||
InputStreamReader isrUtf8 = new InputStreamReader(fisUtf8, "UTF-8"))
|
||||
{
|
||||
PropertyResourceBundle bundleUtf8 = new PropertyResourceBundle(isrUtf8);
|
||||
PropertyResourceBundle bundle = new PropertyResourceBundle(fis8859_1);
|
||||
|
||||
String[] arrayUtf8 = createKeyValueArray(bundleUtf8);
|
||||
String[] array = createKeyValueArray(bundle);
|
||||
|
||||
if (!Arrays.equals(arrayUtf8, array)) {
|
||||
throw new RuntimeException("PropertyResourceBundle constructed from a UTF-8 encoded property file is not equal to the one constructed from ISO-8859-1 encoded property file.");
|
||||
}
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
throw new RuntimeException(fnfe);
|
||||
} catch (IOException ioe) {
|
||||
throw new RuntimeException(ioe);
|
||||
}
|
||||
}
|
||||
|
||||
private final String[] createKeyValueArray(PropertyResourceBundle b) {
|
||||
List<String> keyValueList = new ArrayList<String>();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (String key : b.keySet()) {
|
||||
sb.setLength(0);
|
||||
sb.append(key);
|
||||
sb.append(" = ");
|
||||
sb.append(b.getString(key));
|
||||
keyValueList.add(sb.toString());
|
||||
}
|
||||
|
||||
String[] keyValueArray = keyValueList.toArray(new String[0]);
|
||||
Arrays.sort(keyValueArray);
|
||||
return keyValueArray;
|
||||
}
|
||||
|
||||
public static final void main(String[] args) {
|
||||
new Bug6204853();
|
||||
}
|
||||
}
|
||||
28
test/jdk/java/util/ResourceBundle/Bug6204853.properties
Normal file
28
test/jdk/java/util/ResourceBundle/Bug6204853.properties
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
|
||||
# These should remain Unicode escape sequences
|
||||
key1 = \u30b5\u30f3\u30bf\u30af\u30e9\u30e9
|
||||
key2 = \u30ab\u30ea\u30d5\u30a9\u30eb\u30cb\u30a2
|
||||
key3 = \u30a2\u30e1\u30ea\u30ab\u5408\u8846\u56fd
|
||||
27
test/jdk/java/util/ResourceBundle/Bug6204853_Utf8.properties
Normal file
27
test/jdk/java/util/ResourceBundle/Bug6204853_Utf8.properties
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
|
||||
key1 = サンタクララ
|
||||
key2 = カリフォルニア
|
||||
key3 = アメリカ合衆国
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 6299235 8210408
|
||||
* @summary test Bug 6299235 to make sure the third-party provided sun resources
|
||||
* could be picked up.
|
||||
* @modules java.desktop
|
||||
* @library patches
|
||||
* @build java.desktop/sun.awt.resources.awt_ru_RU
|
||||
* @run main Bug6299235Test
|
||||
*/
|
||||
|
||||
import java.awt.Toolkit;
|
||||
import java.util.Locale;
|
||||
|
||||
/*
|
||||
* After introducing CoreResourceBundleControl for Awt/Swing resources
|
||||
* loading, non-existent resources won't be actually searched from
|
||||
* bootclasspath and extension directory. But we should still fallback
|
||||
* to the current behavior which allows the third-part to provide their
|
||||
* own version of awt resources, for example even though we never claim
|
||||
* we support it yet.
|
||||
* Look into bug 6299235 for more details.
|
||||
*/
|
||||
|
||||
public class Bug6299235Test {
|
||||
private static final Locale ru_RU = Locale.of("ru", "RU");
|
||||
|
||||
public static void main(String args[]) {
|
||||
Locale locale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(ru_RU);
|
||||
// Get the value for the test key "foo"
|
||||
String value = Toolkit.getProperty("foo", "undefined");
|
||||
if (!value.equals("bar")) {
|
||||
throw new RuntimeException("key = foo, value = " + value);
|
||||
}
|
||||
// Get the value for a valid key "AWT.enter"
|
||||
value = Toolkit.getProperty("AWT.enter", "DO NOT ENTER");
|
||||
if (value.equals("DO NOT ENTER")) {
|
||||
throw new RuntimeException("AWT.enter undefined.");
|
||||
}
|
||||
} finally {
|
||||
// Restore the default Locale
|
||||
Locale.setDefault(locale);
|
||||
}
|
||||
System.out.println("Bug6299235Test passed");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
package sun.awt.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
/**
|
||||
* A faked sun.awt.resources.awt_ru_RU resource file.
|
||||
*/
|
||||
public class awt_ru_RU extends ListResourceBundle {
|
||||
@Override
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "foo", "bar" }
|
||||
};
|
||||
}
|
||||
}
|
||||
51
test/jdk/java/util/ResourceBundle/Bug6355009.java
Normal file
51
test/jdk/java/util/ResourceBundle/Bug6355009.java
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6355009
|
||||
* @summary Make sure not to have too many causes for MissingResourceException
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
public final strictfp class Bug6355009 {
|
||||
private final ResourceBundle bundle = ResourceBundle.getBundle(Bug6355009.class.getName());
|
||||
|
||||
public static final void main(String[] args) {
|
||||
try {
|
||||
new Bug6355009();
|
||||
} catch (MissingResourceException e) {
|
||||
Throwable cause = e;
|
||||
int count = 0;
|
||||
while ((cause = cause.getCause()) != null) {
|
||||
if (cause instanceof MissingResourceException) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
throw new RuntimeException("too many causes: " + count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
47
test/jdk/java/util/ResourceBundle/Bug6356571.java
Normal file
47
test/jdk/java/util/ResourceBundle/Bug6356571.java
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 6356571
|
||||
* @summary Make sure that non-ResourceBundle classes are ignored and
|
||||
* properties files are loaded correctly.
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Bug6356571 {
|
||||
// Bug6356571.class is not a ResourceBundle class, so it will be
|
||||
// ignored and Bug6356571.properties will be loaded.
|
||||
private ResourceBundle bundle = ResourceBundle.getBundle("Bug6356571");
|
||||
|
||||
void check() {
|
||||
String id = bundle.getString("id");
|
||||
if (!"6356571".equals(id)) {
|
||||
throw new RuntimeException("wrong id: " + id);
|
||||
}
|
||||
}
|
||||
|
||||
public static final void main(String[] args) {
|
||||
new Bug6356571().check();
|
||||
}
|
||||
}
|
||||
25
test/jdk/java/util/ResourceBundle/Bug6356571.properties
Normal file
25
test/jdk/java/util/ResourceBundle/Bug6356571.properties
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
|
||||
id=6356571
|
||||
40
test/jdk/java/util/ResourceBundle/Bug6572242.java
Normal file
40
test/jdk/java/util/ResourceBundle/Bug6572242.java
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @summary Make sure that ResourceBundle.getBundle ignores LinkageError for compatibility.
|
||||
* @bug 6572242
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Bug6572242 {
|
||||
public static void main(String[] args) {
|
||||
ResourceBundle rb = ResourceBundle.getBundle("bug6572242");
|
||||
String data = rb.getString("data");
|
||||
if (!data.equals("type")) {
|
||||
throw new RuntimeException("got \"" + data + "\", expected \"type\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
35
test/jdk/java/util/ResourceBundle/Control/AbstractRB.java
Normal file
35
test/jdk/java/util/ResourceBundle/Control/AbstractRB.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public abstract class AbstractRB extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "class (abstract)" }
|
||||
};
|
||||
}
|
||||
}
|
||||
111
test/jdk/java/util/ResourceBundle/Control/BadControlsTest.java
Normal file
111
test/jdk/java/util/ResourceBundle/Control/BadControlsTest.java
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 5102289
|
||||
* @summary Test if ResourceBundle.getBundle detects bad Control implementations.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import static java.util.ResourceBundle.Control.*;
|
||||
|
||||
public class BadControlsTest {
|
||||
public static void main(String[] args) {
|
||||
ResourceBundle.Control control;
|
||||
|
||||
control = new ResourceBundle.Control() {
|
||||
public List<String> getFormats(String name) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
testControl(control, "getFormats returns null");
|
||||
|
||||
control = new ResourceBundle.Control() {
|
||||
public List<String> getFormats(String name) {
|
||||
return Arrays.asList("java.class", null, "java.properties");
|
||||
}
|
||||
};
|
||||
testControl(control, "getFormats returns a List containing null");
|
||||
|
||||
control = new ResourceBundle.Control() {
|
||||
public List<Locale> getCandidateLocales(String name, Locale loc) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
testControl(control, "getCandidateLocales returns null");
|
||||
|
||||
control = new ResourceBundle.Control() {
|
||||
public List<Locale> getCandidateLocales(String name, Locale loc) {
|
||||
return Arrays.asList(Locale.US, null, Locale.ENGLISH);
|
||||
}
|
||||
};
|
||||
testControl(control, "getCandidateLocales returns a List containing null");
|
||||
|
||||
long[] badTtls = {
|
||||
TTL_NO_EXPIRATION_CONTROL - 1,
|
||||
-10000,
|
||||
Long.MIN_VALUE
|
||||
};
|
||||
for (final long ttl : badTtls) {
|
||||
control = new ResourceBundle.Control() {
|
||||
public long getTimeToLive(String name, Locale loc) {
|
||||
return ttl;
|
||||
}
|
||||
};
|
||||
testControl(control, "getTimeToLive returns " + ttl);
|
||||
}
|
||||
|
||||
control = new ResourceBundle.Control() {
|
||||
public String toBundleName(String name, Locale loc) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
try {
|
||||
ResourceBundle rb = ResourceBundle.getBundle("StressOut", control);
|
||||
throw new RuntimeException("toBundleName returns null");
|
||||
} catch (MissingResourceException e) {
|
||||
if (!(e.getCause() instanceof NullPointerException)) {
|
||||
throw new RuntimeException("toBundleName returns null. The cause isn't NPE.");
|
||||
}
|
||||
}
|
||||
|
||||
// null Control tests
|
||||
control = null;
|
||||
try {
|
||||
ResourceBundle rb = ResourceBundle.getBundle("StressOut", control);
|
||||
throw new RuntimeException("getBundle doesn't throw NPE with null Control");
|
||||
} catch (NullPointerException e) {
|
||||
// OK
|
||||
}
|
||||
}
|
||||
|
||||
private static void testControl(ResourceBundle.Control control, String testTitle) {
|
||||
try {
|
||||
ResourceBundle rb = ResourceBundle.getBundle("StressOut", control);
|
||||
throw new RuntimeException(testTitle);
|
||||
} catch (IllegalArgumentException e) {
|
||||
System.out.println(testTitle + ": PASSED (" + e.getMessage() + ")");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class BadStaticInitRB extends ListResourceBundle {
|
||||
// Must have an error in this static initializer
|
||||
static {
|
||||
int[] x = new int[1];
|
||||
x[100] = 100;
|
||||
}
|
||||
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "class (static initializer error)" }
|
||||
};
|
||||
}
|
||||
}
|
||||
55
test/jdk/java/util/ResourceBundle/Control/Bug6530694.java
Normal file
55
test/jdk/java/util/ResourceBundle/Control/Bug6530694.java
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
* @test
|
||||
* @bug 6530694
|
||||
* @summary Checks that sun.util.CoreResourceBundleControl does not apply
|
||||
* to the application provided Swing resources.
|
||||
* @modules java.desktop
|
||||
* @run main/othervm -Djava.awt.headless=true Bug6530694
|
||||
*/
|
||||
|
||||
import java.util.Locale;
|
||||
import javax.swing.UIDefaults;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
public class Bug6530694 {
|
||||
Bug6530694() {
|
||||
Locale.setDefault(Locale.GERMANY);
|
||||
UIDefaults defs = UIManager.getDefaults();
|
||||
defs.addResourceBundle("Bug6530694");
|
||||
String str = defs.getString("testkey");
|
||||
if (!"testvalue".equals(str)) {
|
||||
throw new RuntimeException("Could not load the resource for de_DE locale");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Locale reservedLocale = Locale.getDefault();
|
||||
try {
|
||||
new Bug6530694();
|
||||
} finally {
|
||||
// restore the reserved locale
|
||||
Locale.setDefault(reservedLocale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
testkey=testvalue
|
||||
27
test/jdk/java/util/ResourceBundle/Control/Chinese.properties
Normal file
27
test/jdk/java/util/ResourceBundle/Control/Chinese.properties
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
data=root
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
data=zh
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Empty
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# Empty
|
||||
|
|
@ -0,0 +1,165 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 5102289
|
||||
* @summary Test the ResourceBundle.Control factory methods.
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import static java.util.ResourceBundle.Control.*;
|
||||
|
||||
public class ControlFactoryTest {
|
||||
|
||||
/**
|
||||
* An interface for calling ResourceBundle.Control.getControl or
|
||||
* ResourceBundle.Control.getNoFallbackControl.
|
||||
*/
|
||||
private static interface Factory {
|
||||
public ResourceBundle.Control getControl(List<String> formats);
|
||||
public String name();
|
||||
}
|
||||
|
||||
static int errors;
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Test getControl.
|
||||
testControlFactory(new Factory() {
|
||||
public ResourceBundle.Control getControl(List<String> formats) {
|
||||
return ResourceBundle.Control.getControl(formats);
|
||||
}
|
||||
public String name() { return "getControl"; }
|
||||
}, Locale.getDefault());
|
||||
|
||||
// Test getNoFallbackControl.
|
||||
testControlFactory(new Factory() {
|
||||
public ResourceBundle.Control getControl(List<String> formats) {
|
||||
return ResourceBundle.Control.getNoFallbackControl(formats);
|
||||
}
|
||||
public String name() { return "getNoFallbackControl"; }
|
||||
}, null);
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException("FAILED: " + errors + " error(s)");
|
||||
}
|
||||
}
|
||||
|
||||
private static void testControlFactory(Factory factory, Locale loc) {
|
||||
testGetControl(factory, loc, FORMAT_DEFAULT, "java.class", "java.properties");
|
||||
testGetControl(factory, loc, FORMAT_CLASS, "java.class");
|
||||
testGetControl(factory, loc, FORMAT_PROPERTIES, "java.properties");
|
||||
|
||||
// test IllegalArgumentException
|
||||
String[][] data = {
|
||||
{ "java.class", "java.properties", "java.xml" },
|
||||
{ "java.class", "java.props" },
|
||||
{ "java.properties", "java.class" },
|
||||
{ "java.foo", "java.properties" },
|
||||
{ "java.foo" },
|
||||
{ null },
|
||||
};
|
||||
for (String[] fmts : data) {
|
||||
try {
|
||||
List<String> fmt = Arrays.asList(fmts);
|
||||
ResourceBundle.Control control = factory.getControl(fmt);
|
||||
error("getControl: %s%n", fmt);
|
||||
} catch (IllegalArgumentException e) {
|
||||
}
|
||||
}
|
||||
|
||||
// test NPE
|
||||
try {
|
||||
ResourceBundle.Control control = factory.getControl(null);
|
||||
error("%s: doesn't throw NPE.%n", factory.name());
|
||||
} catch (NullPointerException npe) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetControl(Factory factory,
|
||||
Locale loc,
|
||||
final List<String> FORMATS,
|
||||
String... fmtStrings) {
|
||||
final ResourceBundle.Control CONTROL = factory.getControl(FORMATS);
|
||||
List<String> fmt = CONTROL.getFormats("any");
|
||||
if (fmt != FORMATS) {
|
||||
error("%s: returns %s, expected %s.%n",
|
||||
factory.name(), fmt, FORMATS);
|
||||
}
|
||||
ResourceBundle.Control control = null;
|
||||
|
||||
// Check if getControl always returns the expected singleton.
|
||||
for (int i = 0; i < 10; i++) {
|
||||
fmt = Arrays.asList(fmtStrings);
|
||||
control = factory.getControl(fmt);
|
||||
if (control != CONTROL) {
|
||||
error("%s: doesn't return the singleton: got %s, expected %s%n",
|
||||
factory.name(), control, CONTROL);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if getFallbackLocale performs as expected.
|
||||
Locale defaultLocale = Locale.getDefault();
|
||||
Locale nonDefaultLocale = defaultLocale.equals(Locale.US) ? Locale.JAPAN : Locale.US;
|
||||
if (loc != null) {
|
||||
// Test ResourceBundle.Control.getControl()
|
||||
Locale l = CONTROL.getFallbackLocale("any", nonDefaultLocale);
|
||||
if (!defaultLocale.equals(l)) {
|
||||
error("%s: getFallbackLocale doesn't return default locale. got %s, expected %s%n",
|
||||
factory.name(), toString(l), toString(defaultLocale));
|
||||
}
|
||||
l = CONTROL.getFallbackLocale("any", defaultLocale);
|
||||
if (l != null) {
|
||||
error("%s: getFallbackLocale doesn't return null. got %s%n",
|
||||
factory.name(), toString(l));
|
||||
}
|
||||
} else {
|
||||
// Test ResourceBundle.Control.getNoFallbackControl()
|
||||
Locale l = CONTROL.getFallbackLocale("any", nonDefaultLocale);
|
||||
if (l != null) {
|
||||
error("%s: getFallbackLocale doesn't return null. got %s%n",
|
||||
factory.name(), toString(l));
|
||||
}
|
||||
l = CONTROL.getFallbackLocale("any", defaultLocale);
|
||||
if (l != null) {
|
||||
error("%s: getFallbackLocale doesn't return null. got %s%n",
|
||||
factory.name(), toString(l));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(Locale loc) {
|
||||
if (loc == null)
|
||||
return "null";
|
||||
return "\"" + loc.getLanguage() + "_" + loc.getCountry() + "_" + loc.getVariant() + "\"";
|
||||
}
|
||||
|
||||
private static void error(String msg) {
|
||||
System.out.println(msg);
|
||||
errors++;
|
||||
}
|
||||
|
||||
private static void error(String fmt, Object... args) {
|
||||
System.out.printf(fmt, args);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,462 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 5102289 6278334 8261179
|
||||
* @summary Test the default Control implementation. The expiration
|
||||
* functionality of newBundle, getTimeToLive, and needsReload is
|
||||
* tested by ExpirationTest.sh. The factory methods are tested
|
||||
* separately.
|
||||
* @build TestResourceRB
|
||||
* @build NonResourceBundle
|
||||
* @run main DefaultControlTest
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import static java.util.ResourceBundle.Control.*;
|
||||
|
||||
public class DefaultControlTest {
|
||||
// The ResourceBundle.Control instance
|
||||
static final ResourceBundle.Control CONTROL
|
||||
= ResourceBundle.Control.getControl(FORMAT_DEFAULT);
|
||||
|
||||
static final ResourceBundle BUNDLE = new ResourceBundle() {
|
||||
public Enumeration<String> getKeys() { return null; }
|
||||
protected Object handleGetObject(String key) { return null; }
|
||||
};
|
||||
|
||||
static final String CLAZZ = FORMAT_CLASS.get(0);
|
||||
|
||||
static final String PROPERTIES = FORMAT_PROPERTIES.get(0);
|
||||
|
||||
static final ClassLoader LOADER = DefaultControlTest.class.getClassLoader();
|
||||
|
||||
// Full arguments for NPE testing
|
||||
static final Object[] FULLARGS = { "any",
|
||||
Locale.US,
|
||||
FORMAT_PROPERTIES.get(0),
|
||||
LOADER,
|
||||
BUNDLE };
|
||||
|
||||
static int errors;
|
||||
|
||||
public static void main(String[] args) {
|
||||
checkConstants();
|
||||
|
||||
// Test getFormats(String)
|
||||
testGetFormats();
|
||||
|
||||
// Test getCandidateLocales(String, Locale)
|
||||
testGetCandidateLocales();
|
||||
|
||||
// Test getFallbackLocale(String, Locale)
|
||||
testGetFallbackLocale();
|
||||
|
||||
// Test newBundle(String, Locale, String, ClassLoader, boolean)
|
||||
testNewBundle();
|
||||
|
||||
// Test toBundleName(String, Locale)
|
||||
testToBundleName();
|
||||
|
||||
// Test getTimeToLive(String, Locale)
|
||||
testGetTimeToLive();
|
||||
|
||||
// Test needsReload(String, Locale, String, ClassLoader,
|
||||
// ResourceBundle, long)
|
||||
testNeedsReload();
|
||||
|
||||
// Test toResourceName(String, String)
|
||||
testToResourceName();
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException("FAILED: " + errors + " error(s)");
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkConstants() {
|
||||
// Check FORMAT_*
|
||||
if (!CONTROL.FORMAT_DEFAULT.equals(Arrays.asList("java.class",
|
||||
"java.properties"))) {
|
||||
error("Wrong Control.FORMAT_DEFAULT");
|
||||
}
|
||||
checkImmutableList(CONTROL.FORMAT_DEFAULT);
|
||||
if (!CONTROL.FORMAT_CLASS.equals(Arrays.asList("java.class"))) {
|
||||
error("Wrong Control.FORMAT_CLASS");
|
||||
}
|
||||
checkImmutableList(CONTROL.FORMAT_CLASS);
|
||||
if (!CONTROL.FORMAT_PROPERTIES.equals(Arrays.asList("java.properties"))) {
|
||||
error("Wrong Control.FORMAT_PROPERTIES");
|
||||
}
|
||||
checkImmutableList(CONTROL.FORMAT_PROPERTIES);
|
||||
|
||||
// Check TTL_*
|
||||
if (CONTROL.TTL_DONT_CACHE != -1) {
|
||||
error("Wrong Control.TTL_DONT_CACHE: %d%n", CONTROL.TTL_DONT_CACHE);
|
||||
}
|
||||
if (CONTROL.TTL_NO_EXPIRATION_CONTROL != -2) {
|
||||
error("Wrong Control.TTL_NO_EXPIRATION_CONTROL: %d%n",
|
||||
CONTROL.TTL_NO_EXPIRATION_CONTROL);
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkImmutableList(List<String> list) {
|
||||
try {
|
||||
list.add("hello");
|
||||
error("%s is mutable%n", list);
|
||||
} catch (UnsupportedOperationException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetFormats() {
|
||||
List<String> list = CONTROL.getFormats("foo");
|
||||
if (list != CONTROL.FORMAT_DEFAULT) {
|
||||
error("getFormats returned " + list);
|
||||
}
|
||||
try {
|
||||
list = CONTROL.getFormats(null);
|
||||
error("getFormats doesn't throw NPE.");
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetCandidateLocales() {
|
||||
Map<Locale, Locale[]> candidateData = new HashMap<Locale, Locale[]>();
|
||||
candidateData.put(Locale.of("ja", "JP", "YOK"), new Locale[] {
|
||||
Locale.of("ja", "JP", "YOK"),
|
||||
Locale.of("ja", "JP"),
|
||||
Locale.of("ja"),
|
||||
Locale.ROOT });
|
||||
candidateData.put(Locale.of("ja", "JP"), new Locale[] {
|
||||
Locale.of("ja", "JP"),
|
||||
Locale.of("ja"),
|
||||
Locale.ROOT });
|
||||
candidateData.put(Locale.of("ja"), new Locale[] {
|
||||
Locale.of("ja"),
|
||||
Locale.ROOT });
|
||||
|
||||
candidateData.put(Locale.of("ja", "", "YOK"), new Locale[] {
|
||||
Locale.of("ja", "", "YOK"),
|
||||
Locale.of("ja"),
|
||||
Locale.ROOT });
|
||||
candidateData.put(Locale.of("", "JP", "YOK"), new Locale[] {
|
||||
Locale.of("", "JP", "YOK"),
|
||||
Locale.of("", "JP"),
|
||||
Locale.ROOT });
|
||||
candidateData.put(Locale.of("", "", "YOK"), new Locale[] {
|
||||
Locale.of("", "", "YOK"),
|
||||
Locale.ROOT });
|
||||
candidateData.put(Locale.of("", "JP"), new Locale[] {
|
||||
Locale.of("", "JP"),
|
||||
Locale.ROOT });
|
||||
candidateData.put(Locale.ROOT, new Locale[] {
|
||||
Locale.ROOT });
|
||||
|
||||
// Norwegian Bokmal
|
||||
candidateData.put(Locale.forLanguageTag("nb-NO-POSIX"), new Locale[] {
|
||||
Locale.forLanguageTag("nb-NO-POSIX"),
|
||||
Locale.forLanguageTag("no-NO-POSIX"),
|
||||
Locale.forLanguageTag("nb-NO"),
|
||||
Locale.forLanguageTag("no-NO"),
|
||||
Locale.forLanguageTag("nb"),
|
||||
Locale.forLanguageTag("no"),
|
||||
Locale.ROOT});
|
||||
candidateData.put(Locale.forLanguageTag("no-NO-POSIX"), new Locale[] {
|
||||
Locale.forLanguageTag("no-NO-POSIX"),
|
||||
Locale.forLanguageTag("nb-NO-POSIX"),
|
||||
Locale.forLanguageTag("no-NO"),
|
||||
Locale.forLanguageTag("nb-NO"),
|
||||
Locale.forLanguageTag("no"),
|
||||
Locale.forLanguageTag("nb"),
|
||||
Locale.ROOT});
|
||||
|
||||
|
||||
for (Locale locale : candidateData.keySet()) {
|
||||
List<Locale> candidates = CONTROL.getCandidateLocales("any", locale);
|
||||
List<Locale> expected = Arrays.asList(candidateData.get(locale));
|
||||
if (!candidates.equals(expected)) {
|
||||
error("Wrong candidates for %s: got %s, expected %s%n",
|
||||
toString(locale), candidates, expected);
|
||||
}
|
||||
}
|
||||
final int NARGS = 2;
|
||||
for (int mask = 0; mask < (1 << NARGS)-1; mask++) {
|
||||
Object[] data = getNpeArgs(NARGS, mask);
|
||||
try {
|
||||
List<Locale> candidates = CONTROL.getCandidateLocales((String) data[0],
|
||||
(Locale) data[1]);
|
||||
error("getCandidateLocales(%s, %s) doesn't throw NPE.%n",
|
||||
data[0], toString((Locale)data[1]));
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetFallbackLocale() {
|
||||
Locale current = Locale.getDefault();
|
||||
Locale.setDefault(Locale.ITALY);
|
||||
try {
|
||||
Locale loc = CONTROL.getFallbackLocale("any", Locale.FRANCE);
|
||||
if (loc != Locale.ITALY) {
|
||||
error("getFallbackLocale: got %s, expected %s%n",
|
||||
toString(loc), toString(Locale.ITALY));
|
||||
}
|
||||
loc = CONTROL.getFallbackLocale("any", Locale.ITALY);
|
||||
if (loc != null) {
|
||||
error("getFallbackLocale: got %s, expected null%n", toString(loc));
|
||||
}
|
||||
} finally {
|
||||
Locale.setDefault(current);
|
||||
}
|
||||
|
||||
final int NARGS = 2;
|
||||
for (int mask = 0; mask < (1 << NARGS)-1; mask++) {
|
||||
Object[] data = getNpeArgs(NARGS, mask);
|
||||
try {
|
||||
Locale loc = CONTROL.getFallbackLocale((String) data[0], (Locale) data[1]);
|
||||
error("getFallbackLocale(%s, %s) doesn't throw NPE.%n", data[0], data[1]);
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testNewBundle() {
|
||||
int testNo = 0;
|
||||
ResourceBundle rb = null;
|
||||
try {
|
||||
testNo = 1;
|
||||
rb = CONTROL.newBundle("StressOut", Locale.JAPANESE,
|
||||
PROPERTIES, LOADER, false);
|
||||
String s = rb.getString("data");
|
||||
if (!s.equals("Japan")) {
|
||||
error("newBundle: #%d got %s, expected Japan%n", testNo, s);
|
||||
}
|
||||
|
||||
testNo = 2;
|
||||
rb = CONTROL.newBundle("TestResourceRB", Locale.ROOT,
|
||||
CLAZZ, LOADER, false);
|
||||
s = rb.getString("type");
|
||||
if (!s.equals(CLAZZ)) {
|
||||
error("newBundle: #%d got %s, expected %s%n", testNo, s, CLAZZ);
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
error("newBundle: #%d threw %s%n", testNo, e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// Test exceptions
|
||||
|
||||
try {
|
||||
// MalformedDataRB contains an invalid Unicode notation which
|
||||
// causes to throw an IllegalArgumentException.
|
||||
rb = CONTROL.newBundle("MalformedDataRB", Locale.ENGLISH,
|
||||
PROPERTIES, LOADER, false);
|
||||
error("newBundle: doesn't throw IllegalArgumentException with malformed data.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (Exception e) {
|
||||
error("newBundle: threw %s%n", e);
|
||||
}
|
||||
|
||||
try {
|
||||
rb = CONTROL.newBundle("StressOut", Locale.JAPANESE,
|
||||
"foo.bar", LOADER, false);
|
||||
error("newBundle: doesn't throw IllegalArgumentException with invalid format.");
|
||||
} catch (IllegalArgumentException iae) {
|
||||
} catch (Exception e) {
|
||||
error("newBundle: threw %s%n", e);
|
||||
}
|
||||
|
||||
try {
|
||||
rb = CONTROL.newBundle("NonResourceBundle", Locale.ROOT,
|
||||
"java.class", LOADER, false);
|
||||
error("newBundle: doesn't throw ClassCastException with a non-ResourceBundle subclass.");
|
||||
} catch (ClassCastException cce) {
|
||||
} catch (Exception e) {
|
||||
error("newBundle: threw %s%n", e);
|
||||
}
|
||||
|
||||
// NPE test
|
||||
final int NARGS = 4;
|
||||
for (int mask = 0; mask < (1 << NARGS)-1; mask++) {
|
||||
Object[] data = getNpeArgs(NARGS, mask);
|
||||
Locale loc = (Locale) data[1];
|
||||
try {
|
||||
rb = CONTROL.newBundle((String) data[0], loc,
|
||||
(String) data[2], (ClassLoader) data[3],
|
||||
false);
|
||||
error("newBundle(%s, %s, %s, %s, false) doesn't throw NPE.%n",
|
||||
data[0], toString(loc), data[2], data[3]);
|
||||
} catch (NullPointerException npe) {
|
||||
} catch (Exception e) {
|
||||
error("newBundle(%s, %s, %s, %s, false) threw %s.%n",
|
||||
data[0], toString(loc), data[2], data[3], e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testGetTimeToLive() {
|
||||
long ttl = CONTROL.getTimeToLive("any", Locale.US);
|
||||
if (ttl != CONTROL.TTL_NO_EXPIRATION_CONTROL) {
|
||||
error("getTimeToLive: got %d, expected %d%n", ttl,
|
||||
CONTROL.TTL_NO_EXPIRATION_CONTROL);
|
||||
}
|
||||
final int NARGS = 2;
|
||||
for (int mask = 0; mask < (1 << NARGS)-1; mask++) {
|
||||
Object[] data = getNpeArgs(NARGS, mask);
|
||||
try {
|
||||
ttl = CONTROL.getTimeToLive((String) data[0], (Locale) data[1]);
|
||||
error("getTimeToLive(%s, %s) doesn't throw NPE.%n", data[0], data[1]);
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The functionality of needsReload is tested by
|
||||
// ExpirationTest.sh. Only parameter checking is tested here.
|
||||
private static void testNeedsReload() {
|
||||
long loadTime = System.currentTimeMillis();
|
||||
|
||||
// NPE test
|
||||
final int NARGS = 5;
|
||||
for (int mask = 0; mask < (1 << NARGS)-1; mask++) {
|
||||
Object[] data = getNpeArgs(NARGS, mask);
|
||||
Locale loc = (Locale) data[1];
|
||||
try {
|
||||
boolean b = CONTROL.needsReload((String) data[0], loc,
|
||||
(String) data[2], (ClassLoader) data[3],
|
||||
(ResourceBundle) data[4], loadTime);
|
||||
error("needsReload(%s, %s, %s, %s, %s, loadTime) doesn't throw NPE.%n",
|
||||
data[0], toString(loc), data[2], data[3], data[4]);
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testToBundleName() {
|
||||
final String name = "J2SE";
|
||||
Map<Locale, String> bundleNames = new HashMap<Locale, String>();
|
||||
bundleNames.put(Locale.of("ja", "JP", "YOK"),
|
||||
name + "_" + "ja" + "_" + "JP" + "_" + "YOK");
|
||||
bundleNames.put(Locale.of("ja", "JP"),
|
||||
name + "_" + "ja" + "_" + "JP");
|
||||
bundleNames.put(Locale.of("ja"),
|
||||
name + "_" + "ja");
|
||||
bundleNames.put(Locale.of("ja", "", "YOK"),
|
||||
name + "_" + "ja" + "_" + "" + "_" + "YOK");
|
||||
bundleNames.put(Locale.of("", "JP", "YOK"),
|
||||
name + "_" + "" + "_" + "JP" + "_" + "YOK");
|
||||
bundleNames.put(Locale.of("", "", "YOK"),
|
||||
name + "_" + "" + "_" + "" + "_" + "YOK");
|
||||
bundleNames.put(Locale.of("", "JP"),
|
||||
name + "_" + "" + "_" + "JP");
|
||||
bundleNames.put(Locale.ROOT,
|
||||
name);
|
||||
|
||||
for (Locale locale : bundleNames.keySet()) {
|
||||
String bn = CONTROL.toBundleName(name, locale);
|
||||
String expected = bundleNames.get(locale);
|
||||
if (!bn.equals(expected)) {
|
||||
error("toBundleName: got %s, expected %s%n", bn, expected);
|
||||
}
|
||||
}
|
||||
|
||||
final int NARGS = 2;
|
||||
for (int mask = 0; mask < (1 << NARGS)-1; mask++) {
|
||||
Object[] data = getNpeArgs(NARGS, mask);
|
||||
try {
|
||||
String s = CONTROL.toBundleName((String) data[0], (Locale) data[1]);
|
||||
error("toBundleName(%s, %s) doesn't throw NPE.%n", data[0], data[1]);
|
||||
} catch (NullPointerException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void testToResourceName() {
|
||||
String[][] names = {
|
||||
// bundleName, suffix, expected result
|
||||
{ "com.sun.J2SE", "xml", "com/sun/J2SE.xml" },
|
||||
{ ".J2SE", "xml", "/J2SE.xml" },
|
||||
{ "J2SE", "xml", "J2SE.xml" },
|
||||
{ "com/sun/J2SE", "xml", "com/sun/J2SE.xml" },
|
||||
{ "com.sun.J2SE", "", "com/sun/J2SE." },
|
||||
{ ".", "", "/." },
|
||||
{ "", "", "." },
|
||||
|
||||
// data for NPE tests
|
||||
{ null, "any", null },
|
||||
{ "any", null, null },
|
||||
{ null, null, null },
|
||||
};
|
||||
|
||||
for (String[] data : names) {
|
||||
String result = null;
|
||||
boolean npeThrown = false;
|
||||
try {
|
||||
result = CONTROL.toResourceName(data[0], data[1]);
|
||||
} catch (NullPointerException npe) {
|
||||
npeThrown = true;
|
||||
}
|
||||
String expected = data[2];
|
||||
if (expected != null) {
|
||||
if (!result.equals(expected)) {
|
||||
error("toResourceName: got %s, expected %s%n", result, data[2]);
|
||||
}
|
||||
} else {
|
||||
if (!npeThrown) {
|
||||
error("toResourceName(%s, %s) doesn't throw NPE.%n", data[0], data[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Produces permutations argument data that contains at least one
|
||||
* null.
|
||||
*/
|
||||
private static Object[] getNpeArgs(int length, int mask) {
|
||||
Object[] data = new Object[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
if ((mask & (1 << i)) == 0) {
|
||||
data[i] = null;
|
||||
} else {
|
||||
data[i] = FULLARGS[i];
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private static String toString(Locale loc) {
|
||||
if (loc == null)
|
||||
return "null";
|
||||
return "\"" + loc.getLanguage() + "_" + loc.getCountry() + "_" + loc.getVariant() + "\"";
|
||||
}
|
||||
|
||||
private static void error(String msg) {
|
||||
System.out.println(msg);
|
||||
errors++;
|
||||
}
|
||||
|
||||
private static void error(String fmt, Object... args) {
|
||||
System.out.printf(fmt, args);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,157 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 4303146 5102289 6272060
|
||||
* @summary Test non-standard loading strategies with ResourceBundle.Control subclasses
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class LoadingStrategiesTest {
|
||||
|
||||
static int errors;
|
||||
|
||||
public static void main(String[] args) {
|
||||
ResourceBundle rb;
|
||||
String s;
|
||||
|
||||
// Test zh_TW -> root, zh_CN -> zh -> root
|
||||
rb = ResourceBundle.getBundle("Chinese", Locale.TAIWAN, new ChineseControl());
|
||||
s = rb.getString("data");
|
||||
check("chinese with Locale.TAIWAN", s, "root");
|
||||
|
||||
rb = ResourceBundle.getBundle("Chinese", Locale.CHINA, new ChineseControl());
|
||||
s = rb.getString("data");
|
||||
check("chinese with Locale.CHINA", s, "zh");
|
||||
|
||||
|
||||
// Test use of per-locale packaging
|
||||
preparePerLocalePackageProperties();
|
||||
|
||||
rb = ResourceBundle.getBundle("test.package.Messages", Locale.US,
|
||||
new PerLocalePackageControl());
|
||||
s = rb.getString("data");
|
||||
check("Per-locale package with Locale.US", s, "");
|
||||
|
||||
rb = ResourceBundle.getBundle("test.package.Messages", Locale.GERMAN,
|
||||
new PerLocalePackageControl());
|
||||
s = rb.getString("data");
|
||||
check("Per-locale package with Locale.GERMAN", s, "de");
|
||||
|
||||
rb = ResourceBundle.getBundle("test.package.Messages", Locale.JAPAN,
|
||||
new PerLocalePackageControl());
|
||||
s = rb.getString("data");
|
||||
check("Per-locale package with Locale.JAPAN", s, "ja_JP");
|
||||
|
||||
|
||||
// Check any errors
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException("FAILED: " + errors + " error(s)");
|
||||
}
|
||||
}
|
||||
|
||||
private static void check(String msg, String got, String expected) {
|
||||
if (!got.equals(expected)) {
|
||||
error("%s: got \"%s\", expected \"%s\"%n", msg, got, expected);
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChineseControl extends ResourceBundle.Control {
|
||||
@Override
|
||||
public List<Locale> getCandidateLocales(String baseName,
|
||||
Locale locale) {
|
||||
if (locale.equals(Locale.TAIWAN)) {
|
||||
return Arrays.asList(locale,
|
||||
// no Locale("zh")
|
||||
Locale.of(""));
|
||||
}
|
||||
return super.getCandidateLocales(baseName, locale);
|
||||
}
|
||||
}
|
||||
|
||||
private static class PerLocalePackageControl extends ResourceBundle.Control {
|
||||
@Override
|
||||
public String toBundleName(String baseName, Locale locale) {
|
||||
if (baseName == null || locale == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
String loc = super.toBundleName("", locale);
|
||||
if (loc.length() > 0) {
|
||||
return baseName.replaceFirst("^([\\w\\.]+)\\.(\\w+)$",
|
||||
"$1." + loc.substring(1) + ".$2");
|
||||
}
|
||||
return baseName;
|
||||
}
|
||||
|
||||
// Avoid fallback to the default locale (6272060)
|
||||
@Override
|
||||
public Locale getFallbackLocale(String baseName, Locale locale) {
|
||||
if (baseName == null || locale == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// Creates:
|
||||
// test/package/Messages.properties
|
||||
// test/package/de/Messages.properties
|
||||
// test/package/ja_JP/Messages.properties
|
||||
private static void preparePerLocalePackageProperties() {
|
||||
final String DEL = File.separator;
|
||||
try {
|
||||
String dir = System.getProperty("test.classes", ".");
|
||||
String[] subdirs = { "", "de", "ja_JP" };
|
||||
for (String subdir : subdirs) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(dir).append(DEL).append("test").append(DEL).append("package");
|
||||
if (subdir.length() > 0) {
|
||||
sb.append(DEL).append(subdir);
|
||||
}
|
||||
File path = new File(sb.toString());
|
||||
path.mkdirs();
|
||||
File propsfile = new File(path, "Messages.properties");
|
||||
OutputStream os = new FileOutputStream(propsfile);
|
||||
Properties props = new Properties();
|
||||
props.setProperty("data", subdir);
|
||||
props.store(os, null);
|
||||
System.out.println("Created: " + propsfile);
|
||||
os.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Can't set up per-locale properties", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static void error(String msg) {
|
||||
System.out.println(msg);
|
||||
errors++;
|
||||
}
|
||||
|
||||
private static void error(String fmt, Object... args) {
|
||||
System.out.printf(fmt, args);
|
||||
errors++;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
data=\u001xyz
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class MissingResourceCauseTest {
|
||||
public static void main(String[] args) {
|
||||
callGetBundle("NonResourceBundle", ClassCastException.class);
|
||||
callGetBundle("MalformedDataRB", Locale.ENGLISH, IllegalArgumentException.class);
|
||||
callGetBundle("PrivateConstructorRB", IllegalAccessException.class);
|
||||
callGetBundle("AbstractRB", InstantiationException.class);
|
||||
callGetBundle("BadStaticInitRB", ExceptionInInitializerError.class);
|
||||
if (!System.getProperty("os.name").toLowerCase().startsWith("win")) {
|
||||
callGetBundle("UnreadableRB", IOException.class);
|
||||
}
|
||||
callGetBundle("NoNoArgConstructorRB", InstantiationException.class);
|
||||
}
|
||||
|
||||
private static void callGetBundle(String baseName,
|
||||
Class<? extends Throwable> expectedCause) {
|
||||
callGetBundle(baseName, Locale.getDefault(), expectedCause);
|
||||
}
|
||||
|
||||
private static void callGetBundle(String baseName, Locale locale,
|
||||
Class<? extends Throwable> expectedCause) {
|
||||
ResourceBundle rb;
|
||||
try {
|
||||
rb = ResourceBundle.getBundle(baseName, locale);
|
||||
throw new RuntimeException("getBundle(\""+baseName+"\") doesn't throw "
|
||||
+ expectedCause);
|
||||
} catch (MissingResourceException e) {
|
||||
Throwable cause = e.getCause();
|
||||
if (!expectedCause.isInstance(cause)) {
|
||||
throw new RuntimeException("getBundle(\""+baseName+"\") throws "
|
||||
+ cause + ", expected " + expectedCause);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 4354216 8213127 8334333
|
||||
* @summary Test for the cause support when throwing a
|
||||
* MissingResourceBundle. (This test exists under
|
||||
* ResourceBundle/Control because bad resource bundle data can be
|
||||
* shared with other test cases.)
|
||||
* @library /test/lib
|
||||
* @build jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Utils
|
||||
* jdk.test.lib.process.ProcessTools
|
||||
* jdk.test.lib.Platform
|
||||
* MissingResourceCauseTest
|
||||
* NonResourceBundle
|
||||
* PrivateConstructorRB
|
||||
* AbstractRB
|
||||
* BadStaticInitRB
|
||||
* NoNoArgConstructorRB
|
||||
* @run main MissingResourceCauseTestRun
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
import jdk.test.lib.Platform;
|
||||
import jtreg.SkippedException;
|
||||
|
||||
public class MissingResourceCauseTestRun {
|
||||
public static void main(String[] args) throws Throwable {
|
||||
if (Platform.isRoot() && !Platform.isWindows()) {
|
||||
throw new SkippedException("Unable to create an unreadable properties file.");
|
||||
}
|
||||
Path path = Paths.get("UnreadableRB.properties");
|
||||
Files.deleteIfExists(path);
|
||||
try {
|
||||
writeFile(path);
|
||||
runCmd();
|
||||
} finally {
|
||||
deleteFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an unreadable properties file
|
||||
*/
|
||||
private static void writeFile(Path path) throws Throwable {
|
||||
String str = "type=unreadable";
|
||||
Files.createFile(path);
|
||||
try (FileWriter fw = new FileWriter(path.toString())) {
|
||||
fw.write(str);
|
||||
}
|
||||
ProcessTools.executeCommand("chmod", "000", path.toString())
|
||||
.outputTo(System.out)
|
||||
.errorTo(System.out)
|
||||
.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
private static void runCmd() throws Throwable {
|
||||
// Class files are in Utils.TEST_CLASSES
|
||||
// MalformedDataRB_en.properties is in Utils.TEST_SRC
|
||||
// UnreadableRB.properties is in current directory
|
||||
String cp = Utils.TEST_CLASSES + File.pathSeparator + Utils.TEST_SRC
|
||||
+ File.pathSeparator + ".";
|
||||
// Build process (with VM flags)
|
||||
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
|
||||
"-ea", "-esa",
|
||||
"-cp", cp,
|
||||
"MissingResourceCauseTest");
|
||||
// Evaluate process status
|
||||
int exitCode = ProcessTools.executeCommand(pb).getExitValue();
|
||||
if (exitCode != 0) {
|
||||
throw new RuntimeException("Execution of the test failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
}
|
||||
|
||||
private static void deleteFile(Path path) throws Throwable {
|
||||
if (path.toFile().exists()) {
|
||||
ProcessTools.executeCommand("chmod", "666", path.toString())
|
||||
.outputTo(System.out)
|
||||
.errorTo(System.out)
|
||||
.shouldHaveExitValue(0);
|
||||
Files.delete(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class NoNoArgConstructorRB extends ListResourceBundle {
|
||||
public NoNoArgConstructorRB(Object o) {
|
||||
}
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "class (no no-arg constructor)" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
public class NonResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "Non-ResourceBundle" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
// Package private resource bundle
|
||||
class PackagePrivateRB extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "class (package1.PackagePrivateRB)" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 4175293 5102289
|
||||
* @summary Test if package private ResourceBundles can be loaded.
|
||||
* @build PackagePrivateRB
|
||||
* @run main/timeout=300/othervm -esa PackagePrivateTest
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import static java.util.ResourceBundle.Control.*;
|
||||
|
||||
public class PackagePrivateTest {
|
||||
public static void main(String[] args) {
|
||||
ResourceBundle rb;
|
||||
|
||||
// Make sure that the default Control can't load the package
|
||||
// private resource bundles.
|
||||
try {
|
||||
rb = ResourceBundle.getBundle("PackagePrivateRB");
|
||||
throw new RuntimeException(
|
||||
"doesn't throw MissingResourceException with the default Control");
|
||||
} catch (MissingResourceException e) {
|
||||
}
|
||||
|
||||
// Remove the dummy cache entry
|
||||
ResourceBundle.clearCache();
|
||||
|
||||
rb = ResourceBundle.getBundle("PackagePrivateRB",
|
||||
new ResourceBundle.Control() {
|
||||
@Override
|
||||
public List<String> getFormats(String baseName) {
|
||||
return FORMAT_CLASS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceBundle newBundle(String baseName,
|
||||
Locale locale,
|
||||
String format,
|
||||
ClassLoader loader,
|
||||
boolean reload)
|
||||
throws IllegalAccessException,
|
||||
InstantiationException, IOException {
|
||||
String bn = toBundleName(baseName, locale);
|
||||
if ("java.class".equals(format)) {
|
||||
try {
|
||||
Class<? extends ResourceBundle> cl =
|
||||
(Class<? extends ResourceBundle>) loader.loadClass(bn);
|
||||
return cl.newInstance();
|
||||
} catch (ClassNotFoundException e) {
|
||||
//System.out.println("ClassNotFoundException: " + e.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
throw new IllegalArgumentException("unknown format: " + format);
|
||||
}
|
||||
});
|
||||
String s = rb.getString("type");
|
||||
if (!s.equals("class (package1.PackagePrivateRB)")) {
|
||||
throw new RuntimeException("wrong type: got " + s + ", expected '" +
|
||||
"class (package1.PackagePrivateRB)'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class PrivateConstructorRB extends ListResourceBundle {
|
||||
private PrivateConstructorRB() {
|
||||
}
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "class (private constructor)" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
data: U.S.A.
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# empty
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
data: Japan
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
# empty
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
data: Korea
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
|
||||
data: China
|
||||
218
test/jdk/java/util/ResourceBundle/Control/StressTest.java
Normal file
218
test/jdk/java/util/ResourceBundle/Control/StressTest.java
Normal file
|
|
@ -0,0 +1,218 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 5102289
|
||||
* @summary Stress test for ResourceBundle.getBundle with ResourceBundle.Control.
|
||||
* @run main/othervm -esa StressTest 2 15
|
||||
* @key randomness
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
import java.util.concurrent.atomic.*;
|
||||
|
||||
// Usage: java StressTest [threadsFactor [duration]]
|
||||
public class StressTest {
|
||||
static final Random rand = new Random();
|
||||
static final Locale[] locales = {
|
||||
Locale.US,
|
||||
Locale.CHINA,
|
||||
Locale.ROOT,
|
||||
Locale.JAPAN,
|
||||
Locale.CANADA,
|
||||
Locale.KOREA
|
||||
};
|
||||
static final String[] expected = {
|
||||
"U.S.A.",
|
||||
"China",
|
||||
"U.S.A.",
|
||||
"Japan",
|
||||
"U.S.A.", // StressOut_en_CA.properties is empty.
|
||||
"Korea"
|
||||
};
|
||||
static final long startTime = System.currentTimeMillis();
|
||||
|
||||
// increment each element when one getBundle call is done.
|
||||
static AtomicIntegerArray counters;
|
||||
static int[] prevCounters;
|
||||
static int intervalForCounterCheck;
|
||||
static AtomicInteger clearCounter = new AtomicInteger();
|
||||
|
||||
static volatile boolean runrun = true;
|
||||
|
||||
public static void main(String[] args) {
|
||||
int threadsFactor = 2;
|
||||
if (args.length > 0) {
|
||||
threadsFactor = Math.max(2, Integer.parseInt(args[0]));
|
||||
}
|
||||
int duration = 180;
|
||||
if (args.length > 1) {
|
||||
duration = Math.max(5, Integer.parseInt(args[1]));
|
||||
}
|
||||
|
||||
Locale reservedLocale = Locale.getDefault();
|
||||
try {
|
||||
Locale.setDefault(Locale.US);
|
||||
Thread[] tasks = new Thread[locales.length * threadsFactor];
|
||||
counters = new AtomicIntegerArray(tasks.length);
|
||||
|
||||
for (int i = 0; i < tasks.length; i++) {
|
||||
tasks[i] = new Thread(new Worker(i));
|
||||
}
|
||||
for (int i = 0; i < tasks.length; i++) {
|
||||
tasks[i].start();
|
||||
}
|
||||
|
||||
int nProcessors = Runtime.getRuntime().availableProcessors();
|
||||
intervalForCounterCheck = Math.max(tasks.length / nProcessors, 1);
|
||||
System.out.printf(
|
||||
"%d processors, intervalForCounterCheck = %d [sec]%n",
|
||||
nProcessors, intervalForCounterCheck);
|
||||
try {
|
||||
for (int i = 0; runrun && i < duration; i++) {
|
||||
Thread.sleep(1000); // 1 second
|
||||
if ((i % intervalForCounterCheck) == 0) {
|
||||
checkCounters();
|
||||
}
|
||||
}
|
||||
runrun = false;
|
||||
for (int i = 0; i < tasks.length; i++) {
|
||||
tasks[i].join();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
printCounters();
|
||||
} finally {
|
||||
// restore the reserved locale
|
||||
Locale.setDefault(reservedLocale);
|
||||
}
|
||||
}
|
||||
|
||||
static void checkCounters() {
|
||||
int length = counters.length();
|
||||
int[] snapshot = new int[length];
|
||||
for (int i = 0; i < length; i++) {
|
||||
snapshot[i] = counters.get(i);
|
||||
}
|
||||
|
||||
if (prevCounters == null) {
|
||||
prevCounters = snapshot;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
if (snapshot[i] > prevCounters[i]) {
|
||||
continue;
|
||||
}
|
||||
System.out.printf(
|
||||
"Warning: Thread #%d hasn't updated its counter for the last %d second(s).%n",
|
||||
i, intervalForCounterCheck);
|
||||
}
|
||||
prevCounters = snapshot;
|
||||
}
|
||||
|
||||
static void printCounters() {
|
||||
long total = 0;
|
||||
int min = Integer.MAX_VALUE;
|
||||
int max = Integer.MIN_VALUE;
|
||||
for (int i = 0; i < counters.length(); i++) {
|
||||
int counter = counters.get(i);
|
||||
total += counter;
|
||||
min = Math.min(min, counter);
|
||||
max = Math.max(max, counter);
|
||||
}
|
||||
System.out.printf("Total: %d calls, min=%d, max=%d, cache cleared %d times%n",
|
||||
total, min, max, clearCounter.get());
|
||||
}
|
||||
|
||||
static class Worker implements Runnable {
|
||||
final int id;
|
||||
final int index;
|
||||
final Locale locale;
|
||||
final String str;
|
||||
final int max;
|
||||
final boolean cleaner;
|
||||
ResourceBundle.Control control;
|
||||
|
||||
Worker(int i) {
|
||||
id = i;
|
||||
index = i % locales.length;
|
||||
locale = locales[index];
|
||||
cleaner = locale.equals(Locale.ROOT);
|
||||
str = expected[index];
|
||||
max = rand.nextInt((index + 1) * 500) + 1000;
|
||||
control = new TestControl(max);
|
||||
System.out.println("Worker" + i + ": locale="+locale+", expected="+str+
|
||||
", max="+max);
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while (runrun) {
|
||||
ResourceBundle rb = ResourceBundle.getBundle("StressOut", locale, control);
|
||||
counters.incrementAndGet(id);
|
||||
String s = rb.getString("data");
|
||||
if (!s.equals(str)) {
|
||||
runrun = false;
|
||||
throw new RuntimeException(locale + ": rb.locale=" + rb.getLocale() +
|
||||
", got " + s + ", expected " + str);
|
||||
}
|
||||
try {
|
||||
Thread.sleep(rand.nextInt(max/500));
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
if (cleaner && (rand.nextInt(10000) == 0)) {
|
||||
//System.out.println("Clearing cache!");
|
||||
ResourceBundle.clearCache();
|
||||
clearCounter.incrementAndGet();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class TestControl extends ResourceBundle.Control {
|
||||
int max;
|
||||
|
||||
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
|
||||
List<Locale> list = super.getCandidateLocales(baseName, locale);
|
||||
//System.out.println("Candidate locales=" + list);
|
||||
return list;
|
||||
}
|
||||
public TestControl(int max) {
|
||||
this.max = max;
|
||||
}
|
||||
public long getTimeToLive(String baseName, Locale locale) {
|
||||
// This will set TTL to a random value for each bundle.
|
||||
long ttl = rand.nextInt(max);
|
||||
//System.out.println("TTL: " + baseName + "_" + locale + " for " + ttl);
|
||||
return ttl;
|
||||
}
|
||||
public boolean needsReload(String baseName, Locale locale,
|
||||
String format, ClassLoader loader,
|
||||
ResourceBundle bundle, long loadTime) {
|
||||
//System.out.println("Expired: " + baseName + "_" + locale + "." + format +
|
||||
// " at " + (loadTime-startTime) + ", bundle=" + bundle);
|
||||
return rand.nextBoolean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class TestResourceRB extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "type", "java.class" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 5102289 4403721
|
||||
* @summary Test XML support as shown in the ResourceBundle.Control description.
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import static java.util.ResourceBundle.Control.*;
|
||||
|
||||
public class XMLResourceBundleTest {
|
||||
public static void main(String[] args) {
|
||||
ResourceBundle.Control xmlControl = new ResourceBundle.Control() {
|
||||
@Override
|
||||
public List<String> getFormats(String baseName) {
|
||||
if (baseName == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return Arrays.asList("xml");
|
||||
}
|
||||
@Override
|
||||
public ResourceBundle newBundle(String baseName, Locale locale,
|
||||
String format,
|
||||
ClassLoader loader,
|
||||
boolean reload)
|
||||
throws IllegalAccessException,
|
||||
InstantiationException, IOException {
|
||||
if (baseName == null || locale == null
|
||||
|| format == null || loader == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
ResourceBundle bundle = null;
|
||||
if (format.equals("xml")) {
|
||||
String bundleName = toBundleName(baseName, locale);
|
||||
String resourceName = toResourceName(bundleName, format);
|
||||
URL url = loader.getResource(resourceName);
|
||||
if (url != null) {
|
||||
URLConnection connection = url.openConnection();
|
||||
if (connection != null) {
|
||||
if (reload) {
|
||||
// disable caches if reloading
|
||||
connection.setUseCaches(false);
|
||||
}
|
||||
InputStream stream = connection.getInputStream();
|
||||
if (stream != null) {
|
||||
BufferedInputStream bis = new BufferedInputStream(stream);
|
||||
bundle = new XMLResourceBundle(bis);
|
||||
bis.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return bundle;
|
||||
}
|
||||
};
|
||||
ResourceBundle rb = ResourceBundle.getBundle("XmlRB", Locale.ROOT, xmlControl);
|
||||
String type = rb.getString("type");
|
||||
if (!type.equals("XML")) {
|
||||
throw new RuntimeException("Root Locale: type: got " + type
|
||||
+ ", expected XML (ASCII)");
|
||||
}
|
||||
|
||||
rb = ResourceBundle.getBundle("XmlRB", Locale.JAPAN, xmlControl);
|
||||
type = rb.getString("type");
|
||||
// Expect fullwidth "XML"
|
||||
if (!type.equals("\uff38\uff2d\uff2c")) {
|
||||
throw new RuntimeException("Locale.JAPAN: type: got " + type
|
||||
+ ", expected \uff38\uff2d\uff2c (fullwidth XML)");
|
||||
}
|
||||
}
|
||||
|
||||
private static class XMLResourceBundle extends ResourceBundle {
|
||||
private Properties props;
|
||||
|
||||
XMLResourceBundle(InputStream stream) throws IOException {
|
||||
props = new Properties();
|
||||
props.loadFromXML(stream);
|
||||
}
|
||||
|
||||
protected Object handleGetObject(String key) {
|
||||
if (key == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
return props.get(key);
|
||||
}
|
||||
|
||||
public Enumeration<String> getKeys() {
|
||||
// Not implemented
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
test/jdk/java/util/ResourceBundle/Control/XmlRB.xml
Normal file
9
test/jdk/java/util/ResourceBundle/Control/XmlRB.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!---->
|
||||
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>Test data for XMLResourceBundleTest.java</comment>
|
||||
<entry key="type">XML</entry>
|
||||
</properties>
|
||||
9
test/jdk/java/util/ResourceBundle/Control/XmlRB_ja.xml
Normal file
9
test/jdk/java/util/ResourceBundle/Control/XmlRB_ja.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
<!---->
|
||||
|
||||
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
|
||||
<properties>
|
||||
<comment>Test data for XMLResourceBundleTest.java</comment>
|
||||
<entry key="type">XML</entry>
|
||||
</properties>
|
||||
66
test/jdk/java/util/ResourceBundle/FakeTestResource.java
Normal file
66
test/jdk/java/util/ResourceBundle/FakeTestResource.java
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file and, per its terms, should not be removed:
|
||||
*
|
||||
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
|
||||
* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
|
||||
*
|
||||
* Portions copyright (c) 2007 Sun Microsystems, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* The original version of this source code and documentation
|
||||
* is copyrighted and owned by Taligent, Inc., a wholly-owned
|
||||
* subsidiary of IBM. These materials are provided under terms
|
||||
* of a License Agreement between Taligent and Sun. This technology
|
||||
* is protected by multiple US and International patents.
|
||||
*
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL purposes and without
|
||||
* fee is hereby granted provided that this copyright notice
|
||||
* appears in all copies. Please refer to the file "copyright.html"
|
||||
* for further important copyright and licensing information.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
|
||||
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
|
||||
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
// NOTE: This class is part of the ResourceBundleTest.
|
||||
// The ResourceBundle code should never find this class, even if the caller looks
|
||||
// for "FakeTestResource". If it does, that's an error.
|
||||
|
||||
public class FakeTestResource {
|
||||
public FakeTestResource() {
|
||||
}
|
||||
}
|
||||
35
test/jdk/java/util/ResourceBundle/KeySetMessages.java
Normal file
35
test/jdk/java/util/ResourceBundle/KeySetMessages.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class KeySetMessages extends ListResourceBundle {
|
||||
protected Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "food", "Cheeseburger" },
|
||||
{ "drink", "Coke" }};
|
||||
}
|
||||
}
|
||||
35
test/jdk/java/util/ResourceBundle/KeySetMessages_zh_CN.java
Normal file
35
test/jdk/java/util/ResourceBundle/KeySetMessages_zh_CN.java
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class KeySetMessages_zh_CN extends ListResourceBundle {
|
||||
protected Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "food", "Peking Duck" },
|
||||
{ "tea", "Oolong" }};
|
||||
}
|
||||
}
|
||||
26
test/jdk/java/util/ResourceBundle/KeySetResources.properties
Normal file
26
test/jdk/java/util/ResourceBundle/KeySetResources.properties
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
|
||||
food: Cheeseburger
|
||||
drink: Coke
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
|
||||
food: Chicken Teriyaki
|
||||
tea: Green Tea
|
||||
114
test/jdk/java/util/ResourceBundle/KeySetTest.java
Normal file
114
test/jdk/java/util/ResourceBundle/KeySetTest.java
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 4095319 4286358
|
||||
* @summary Test cases for the containsKey, keySet, and handleKeySet
|
||||
* methods that are new in Mustang.
|
||||
* @build KeySetMessages KeySetMessages_zh_CN
|
||||
* @run main KeySetTest
|
||||
*/
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.*;
|
||||
|
||||
public class KeySetTest {
|
||||
static final List<String> fullKeys = Arrays.asList("food", "drink", "tea");
|
||||
static final List<String> localKeys = Arrays.asList("food", "tea");
|
||||
|
||||
public static void main(String[] args) {
|
||||
// Test PropertyResourceBundle
|
||||
testKeys("KeySetResources", Locale.JAPAN);
|
||||
|
||||
// Test ListResourceBundle
|
||||
testKeys("KeySetMessages", Locale.CHINA);
|
||||
}
|
||||
|
||||
static void testKeys(String bundleName, Locale locale) {
|
||||
ResourceBundle rb = ResourceBundle.getBundle(bundleName, locale);
|
||||
System.out.println("food = " + rb.getString("food"));
|
||||
|
||||
// Test keySet()
|
||||
Set<String> allKeys = rb.keySet();
|
||||
if (!(allKeys.containsAll(fullKeys) && fullKeys.containsAll(allKeys))) {
|
||||
throw new RuntimeException("got "+allKeys + ", expected " + fullKeys);
|
||||
}
|
||||
|
||||
// Test containsKey()
|
||||
for (String key : fullKeys) {
|
||||
if (!rb.containsKey(key)) {
|
||||
throw new RuntimeException("rb doesn't contain: " + key);
|
||||
}
|
||||
}
|
||||
for (String key : new String[] { "snack", "beer" }) {
|
||||
if (rb.containsKey(key)) {
|
||||
throw new RuntimeException("rb contains: " + key);
|
||||
}
|
||||
}
|
||||
|
||||
// Make sure that the default handleKeySet implementation
|
||||
// returns the subset keys of the given locale.
|
||||
TestBundle tb = new TestBundle(bundleName, locale);
|
||||
Set<String> childKeys = tb.handleKeySet();
|
||||
if (!(childKeys.containsAll(localKeys) || localKeys.containsAll(childKeys))) {
|
||||
throw new RuntimeException("get " + childKeys + ", expected " + localKeys);
|
||||
}
|
||||
}
|
||||
|
||||
static class TestBundle extends ResourceBundle {
|
||||
ResourceBundle bundle;
|
||||
Method m;
|
||||
|
||||
public TestBundle() {}
|
||||
|
||||
public TestBundle(String name, Locale locale) {
|
||||
bundle = ResourceBundle.getBundle(name, locale);
|
||||
|
||||
// Prepare for the handleGetObject call
|
||||
try {
|
||||
Class clazz = bundle.getClass();
|
||||
m = clazz.getMethod("handleGetObject", String.class);
|
||||
m.setAccessible(true);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("method preparation error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Enumeration<String> getKeys() {
|
||||
return bundle.getKeys();
|
||||
}
|
||||
|
||||
// handleGetObject() doesn't look up its parent bundles.
|
||||
protected Object handleGetObject(String key) {
|
||||
try {
|
||||
return m.invoke(bundle, key);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("handleGetObject error", e);
|
||||
}
|
||||
}
|
||||
|
||||
public Set<String> handleKeySet() {
|
||||
return super.handleKeySet();
|
||||
}
|
||||
}
|
||||
}
|
||||
26
test/jdk/java/util/ResourceBundle/RB4353454_en.properties
Normal file
26
test/jdk/java/util/ResourceBundle/RB4353454_en.properties
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
#
|
||||
#
|
||||
#
|
||||
text=Got it!
|
||||
265
test/jdk/java/util/ResourceBundle/RBTestFmwk.java
Normal file
265
test/jdk/java/util/ResourceBundle/RBTestFmwk.java
Normal file
|
|
@ -0,0 +1,265 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file and, per its terms, should not be removed:
|
||||
*
|
||||
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
|
||||
* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
|
||||
*
|
||||
* Portions copyright (c) 2007 Sun Microsystems, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* The original version of this source code and documentation
|
||||
* is copyrighted and owned by Taligent, Inc., a wholly-owned
|
||||
* subsidiary of IBM. These materials are provided under terms
|
||||
* of a License Agreement between Taligent and Sun. This technology
|
||||
* is protected by multiple US and International patents.
|
||||
*
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL purposes and without
|
||||
* fee is hereby granted provided that this copyright notice
|
||||
* appears in all copies. Please refer to the file "copyright.html"
|
||||
* for further important copyright and licensing information.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
|
||||
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
|
||||
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.lang.reflect.*;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Vector;
|
||||
import java.io.*;
|
||||
import java.text.*;
|
||||
|
||||
/**
|
||||
* RBTestFmwk is a base class for tests that can be run conveniently from
|
||||
* the command line as well as under the Java test harness.
|
||||
* <p>
|
||||
* Sub-classes implement a set of methods named Test<something>. Each
|
||||
* of these methods performs some test. Test methods should indicate
|
||||
* errors by calling either err or errln. This will increment the
|
||||
* errorCount field and may optionally print a message to the log.
|
||||
* Debugging information may also be added to the log via the log
|
||||
* and logln methods. These methods will add their arguments to the
|
||||
* log only if the test is being run in verbose mode.
|
||||
*/
|
||||
public class RBTestFmwk {
|
||||
//------------------------------------------------------------------------
|
||||
// Everything below here is boilerplate code that makes it possible
|
||||
// to add a new test by simply adding a function to an existing class
|
||||
//------------------------------------------------------------------------
|
||||
|
||||
protected RBTestFmwk() {
|
||||
// Create a hashtable containing all the test methods.
|
||||
testMethods = new Hashtable();
|
||||
Method[] methods = getClass().getDeclaredMethods();
|
||||
for( int i=0; i<methods.length; i++ ) {
|
||||
if( methods[i].getName().startsWith("Test")
|
||||
|| methods[i].getName().startsWith("test") ) {
|
||||
testMethods.put( methods[i].getName(), methods[i] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void run(String[] args) throws Exception
|
||||
{
|
||||
System.out.println(getClass().getName() + " {");
|
||||
indentLevel++;
|
||||
|
||||
// Set up the log and reference streams. We use PrintWriters in order to
|
||||
// take advantage of character conversion. The JavaEsc converter will
|
||||
// convert Unicode outside the ASCII range to Java's \\uxxxx notation.
|
||||
log = new PrintWriter(System.out,true);
|
||||
|
||||
// Parse the test arguments. They can be either the flag
|
||||
// "-verbose" or names of test methods. Create a list of
|
||||
// tests to be run.
|
||||
Vector testsToRun = new Vector( args.length );
|
||||
for( int i=0; i<args.length; i++ ) {
|
||||
if( args[i].equals("-verbose") ) {
|
||||
verbose = true;
|
||||
}
|
||||
else if( args[i].equals("-prompt") ) {
|
||||
prompt = true;
|
||||
} else if (args[i].equals("-nothrow")) {
|
||||
nothrow = true;
|
||||
} else {
|
||||
Object m = testMethods.get( args[i] );
|
||||
if( m != null ) {
|
||||
testsToRun.addElement( m );
|
||||
}
|
||||
else {
|
||||
usage();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no test method names were given explicitly, run them all.
|
||||
if( testsToRun.size() == 0 ) {
|
||||
Enumeration methodNames = testMethods.elements();
|
||||
while( methodNames.hasMoreElements() ) {
|
||||
testsToRun.addElement( methodNames.nextElement() );
|
||||
}
|
||||
}
|
||||
|
||||
// Run the list of tests given in the test arguments
|
||||
for( int i=0; i<testsToRun.size(); i++ ) {
|
||||
int oldCount = errorCount;
|
||||
|
||||
Method testMethod = (Method)testsToRun.elementAt(i);
|
||||
writeTestName(testMethod.getName());
|
||||
|
||||
try {
|
||||
testMethod.invoke(this, new Object[0]);
|
||||
}
|
||||
catch( IllegalAccessException e ) {
|
||||
errln("Can't acces test method " + testMethod.getName());
|
||||
}
|
||||
catch( InvocationTargetException e ) {
|
||||
errorCount++;
|
||||
log.println("\nUncaught throwable thrown in test method "
|
||||
+ testMethod.getName());
|
||||
e.getTargetException().printStackTrace(this.log);
|
||||
if (!nothrow) {
|
||||
throw new RuntimeException("Exiting...");
|
||||
}
|
||||
}
|
||||
writeTestResult(errorCount - oldCount);
|
||||
}
|
||||
indentLevel--;
|
||||
writeTestResult(errorCount);
|
||||
if (prompt) {
|
||||
System.out.println("Hit RETURN to exit...");
|
||||
try {
|
||||
System.in.read();
|
||||
}
|
||||
catch (IOException e) {
|
||||
System.out.println("Exception: " + e.toString() + e.getMessage());
|
||||
}
|
||||
}
|
||||
if (nothrow) {
|
||||
System.exit(errorCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds given string to the log if we are in verbose mode.
|
||||
*/
|
||||
protected void log( String message ) {
|
||||
if( verbose ) {
|
||||
indent(indentLevel + 1);
|
||||
log.print( message );
|
||||
log.flush();
|
||||
}
|
||||
}
|
||||
|
||||
protected void logln( String message ) {
|
||||
log(message + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Report an error
|
||||
*/
|
||||
protected void err( String message ) {
|
||||
errorCount++;
|
||||
indent(indentLevel + 1);
|
||||
log.print( message );
|
||||
log.flush();
|
||||
|
||||
if (!nothrow) {
|
||||
throw new RuntimeException(message);
|
||||
}
|
||||
}
|
||||
|
||||
protected void errln( String message ) {
|
||||
err(message + System.getProperty("line.separator"));
|
||||
}
|
||||
|
||||
|
||||
protected void writeTestName(String testName) {
|
||||
indent(indentLevel);
|
||||
log.print(testName);
|
||||
log.flush();
|
||||
needLineFeed = true;
|
||||
}
|
||||
|
||||
protected void writeTestResult(int count) {
|
||||
if (!needLineFeed) {
|
||||
indent(indentLevel);
|
||||
log.print("}");
|
||||
}
|
||||
needLineFeed = false;
|
||||
|
||||
if (count != 0)
|
||||
log.println(" FAILED");
|
||||
else
|
||||
log.println(" Passed");
|
||||
}
|
||||
|
||||
private final void indent(int distance) {
|
||||
if (needLineFeed) {
|
||||
log.println(" {");
|
||||
needLineFeed = false;
|
||||
}
|
||||
log.print(spaces.substring(0, distance * 2));
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a usage message for this test class.
|
||||
*/
|
||||
void usage() {
|
||||
System.out.println(getClass().getName() +
|
||||
": [-verbose] [-nothrow] [-prompt] [test names]");
|
||||
|
||||
System.out.println("test names:");
|
||||
Enumeration methodNames = testMethods.keys();
|
||||
while( methodNames.hasMoreElements() ) {
|
||||
System.out.println("\t" + methodNames.nextElement() );
|
||||
}
|
||||
}
|
||||
|
||||
private boolean prompt = false;
|
||||
private boolean nothrow = false;
|
||||
protected boolean verbose = false;
|
||||
|
||||
private PrintWriter log;
|
||||
private int indentLevel = 0;
|
||||
private boolean needLineFeed = false;
|
||||
private int errorCount = 0;
|
||||
|
||||
private Hashtable testMethods;
|
||||
private final String spaces = " ";
|
||||
}
|
||||
145
test/jdk/java/util/ResourceBundle/ReferencesTest.java
Normal file
145
test/jdk/java/util/ResourceBundle/ReferencesTest.java
Normal file
|
|
@ -0,0 +1,145 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
* @test
|
||||
* @bug 4405807
|
||||
* @modules java.base/java.util:open
|
||||
* @run main/othervm -Xms10m ReferencesTest
|
||||
* @summary Verify that references from ResourceBundle cache don't prevent
|
||||
* class loader reclamation.
|
||||
*/
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* This test relies on the current behavior of the garbage collector and is
|
||||
* therefore no clear indicator of whether the fix for 4405807 works.
|
||||
* If the test fails, it might indicate a regression, or it might just mean
|
||||
* that a less aggressive garbage collector is used.
|
||||
*/
|
||||
public class ReferencesTest {
|
||||
|
||||
private static final int CLASS_LOADER_COUNT = 20;
|
||||
|
||||
// These two parallel arrays have references to the same class loaders.
|
||||
// The weakLoaders array lets us track whether class loaders are being
|
||||
// reclaimed after the references in the loaders array are nulled out.
|
||||
private static ClassLoader[] loaders = new ClassLoader[CLASS_LOADER_COUNT];
|
||||
private static WeakReference[] weakLoaders = new WeakReference[CLASS_LOADER_COUNT];
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
URL testDirectory = new File(System.getProperty("test.classes", ".")).toURL();
|
||||
|
||||
for (int i = 0; i < loaders.length; i++) {
|
||||
URL[] urls = { testDirectory };
|
||||
loaders[i] = new URLClassLoader(urls);
|
||||
weakLoaders[i] = new WeakReference(loaders[i]);
|
||||
}
|
||||
|
||||
// fill the ResourceBundle cache with entries for half the class loaders
|
||||
loadBundles(0, CLASS_LOADER_COUNT / 2);
|
||||
|
||||
report("After loading resource bundles for first half of class loaders: ");
|
||||
|
||||
// release the first half of the class loaders
|
||||
for (int i = 0; i < CLASS_LOADER_COUNT / 2; i++) {
|
||||
loaders[i] = null;
|
||||
}
|
||||
|
||||
System.gc();
|
||||
|
||||
report("After releasing first half of class loaders: ");
|
||||
|
||||
// fill the ResourceBundle cache with entries for second half the class loaders
|
||||
loadBundles(CLASS_LOADER_COUNT / 2, CLASS_LOADER_COUNT);
|
||||
|
||||
report("After loading resource bundles for second half of class loaders: ");
|
||||
|
||||
// release the second half of the class loaders
|
||||
for (int i = CLASS_LOADER_COUNT / 2; i < CLASS_LOADER_COUNT; i++) {
|
||||
loaders[i] = null;
|
||||
}
|
||||
|
||||
System.gc();
|
||||
|
||||
report("After releasing second half of class loaders: ");
|
||||
|
||||
// The garbage collector in Tiger actually has reclaimed all class
|
||||
// loaders at this point, but in order not to become too dependent
|
||||
// on the current behavior, we only require that the first half
|
||||
// has been reclaimed.
|
||||
if (countLoaders(0, CLASS_LOADER_COUNT / 2) > 0) {
|
||||
throw new RuntimeException("Too many class loaders not reclaimed yet.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void report(String when) throws Exception {
|
||||
int first = countLoaders(0, CLASS_LOADER_COUNT / 2);
|
||||
int second = countLoaders(CLASS_LOADER_COUNT / 2, CLASS_LOADER_COUNT);
|
||||
|
||||
Class clazz = ResourceBundle.class;
|
||||
Field cacheList = clazz.getDeclaredField("cacheList");
|
||||
cacheList.setAccessible(true);
|
||||
int cacheSize = ((Map)cacheList.get(clazz)).size();
|
||||
|
||||
System.out.println(when);
|
||||
System.out.println(" " + first + " loaders alive in first half");
|
||||
System.out.println(" " + second + " loaders alive in second half");
|
||||
System.out.println(" " + cacheSize + " entries in resource bundle cache");
|
||||
}
|
||||
|
||||
private static void loadBundles(int start, int end) throws Exception {
|
||||
for (int i = start; i < end; i++) {
|
||||
// There's no resource bundle for NonExistantBundle - this
|
||||
// let's us test the case where a resource bundle is not found,
|
||||
// which in the past created a SoftReference on the value side
|
||||
// of the cache.
|
||||
try {
|
||||
ResourceBundle.getBundle("NonExistantBundle", Locale.US, loaders[i]);
|
||||
} catch (MissingResourceException e) {
|
||||
}
|
||||
// There's a base resource bundle for ReferencesTestBundle - the
|
||||
// normal case.
|
||||
ResourceBundle.getBundle("ReferencesTestBundle", Locale.US, loaders[i]);
|
||||
}
|
||||
}
|
||||
|
||||
private static int countLoaders(int start, int end) {
|
||||
int count = 0;
|
||||
for (int i = start; i < end; i++) {
|
||||
if (weakLoaders[i].get() != null) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
unused=Hallo, alle miteinander!
|
||||
456
test/jdk/java/util/ResourceBundle/ResourceBundleTest.java
Normal file
456
test/jdk/java/util/ResourceBundle/ResourceBundleTest.java
Normal file
|
|
@ -0,0 +1,456 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
@test
|
||||
@bug 4049325 4073127 4083270 4106034 4108126 8027930 8171139
|
||||
@summary test Resource Bundle
|
||||
@build TestResource TestResource_de TestResource_fr TestResource_fr_CH
|
||||
@build TestResource_it FakeTestResource
|
||||
@run main ResourceBundleTest
|
||||
*/
|
||||
/*
|
||||
* This file is available under and governed by the GNU General Public
|
||||
* License version 2 only, as published by the Free Software Foundation.
|
||||
* However, the following notice accompanied the original version of this
|
||||
* file and, per its terms, should not be removed:
|
||||
*
|
||||
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
|
||||
* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
|
||||
*
|
||||
* Portions copyright (c) 2007 Sun Microsystems, Inc.
|
||||
* All Rights Reserved.
|
||||
*
|
||||
* The original version of this source code and documentation
|
||||
* is copyrighted and owned by Taligent, Inc., a wholly-owned
|
||||
* subsidiary of IBM. These materials are provided under terms
|
||||
* of a License Agreement between Taligent and Sun. This technology
|
||||
* is protected by multiple US and International patents.
|
||||
*
|
||||
* This notice and attribution to Taligent may not be removed.
|
||||
* Taligent is a registered trademark of Taligent, Inc.
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software
|
||||
* and its documentation for NON-COMMERCIAL purposes and without
|
||||
* fee is hereby granted provided that this copyright notice
|
||||
* appears in all copies. Please refer to the file "copyright.html"
|
||||
* for further important copyright and licensing information.
|
||||
*
|
||||
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
|
||||
* THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
||||
* TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||||
* PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
|
||||
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
|
||||
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.text.*;
|
||||
import java.util.*;
|
||||
import java.util.ResourceBundle.Control;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
|
||||
public class ResourceBundleTest extends RBTestFmwk {
|
||||
public static void main(String[] args) throws Exception {
|
||||
new ResourceBundleTest().run(args);
|
||||
}
|
||||
|
||||
public ResourceBundleTest() {
|
||||
makePropertiesFile();
|
||||
}
|
||||
|
||||
public void TestResourceBundle() {
|
||||
Locale saveDefault = Locale.getDefault();
|
||||
Locale.setDefault(Locale.FRANCE);
|
||||
|
||||
// load up the resource bundle, and make sure we got the right one
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("TestResource");
|
||||
if (!bundle.getClass().getName().equals("TestResource_fr"))
|
||||
errln("Expected TestResource_fr, got " + bundle.getClass().getName());
|
||||
|
||||
// these resources are defines in ResourceBundle_fr
|
||||
String test1 = bundle.getString("Time");
|
||||
if (!test1.equals("Time keeps on slipping..."))
|
||||
errln("TestResource_fr returned wrong value for \"Time\": got " + test1);
|
||||
|
||||
test1 = bundle.getString("For");
|
||||
if (!test1.equals("Four score and seven years ago..."))
|
||||
errln("TestResource_fr returned wrong value for \"For\": got " + test1);
|
||||
|
||||
String[] test2 = bundle.getStringArray("All");
|
||||
if (test2.length != 4)
|
||||
errln("TestResource_fr returned wrong number of elements for \"All\": got " + test2.length);
|
||||
else if (!test2[0].equals("'Twas brillig, and the slithy toves") ||
|
||||
!test2[1].equals("Did gyre and gimble in the wabe.") ||
|
||||
!test2[2].equals("All mimsy were the borogoves,") ||
|
||||
!test2[3].equals("And the mome raths outgrabe."))
|
||||
errln("TestResource_fr returned the wrong value for one of the elements in \"All\"");
|
||||
|
||||
Object test3 = bundle.getObject("Good");
|
||||
if (test3 == null || test3.getClass() != Integer.class)
|
||||
errln("TestResource_fr returned an object of the wrong class for \"Good\"");
|
||||
else if (((Integer)test3).intValue() != 3)
|
||||
errln("TestResource_fr returned the wrong value for \"Good\": got " + test3);
|
||||
|
||||
// This resource is defined in TestResource and inherited by TestResource_fr
|
||||
test2 = bundle.getStringArray("Men");
|
||||
if (test2.length != 3)
|
||||
errln("TestResource_fr returned wrong number of elements for \"Men\": got " + test2.length);
|
||||
else if (!test2[0].equals("1") ||
|
||||
!test2[1].equals("2") ||
|
||||
!test2[2].equals("C"))
|
||||
errln("TestResource_fr returned the wrong value for one of the elements in \"All\"");
|
||||
|
||||
// This resource is defined in neither TestResource not TestResource_fr
|
||||
try {
|
||||
test3 = bundle.getObject("Is");
|
||||
errln("TestResource_fr returned a value for \"Is\" when it shouldn't: got " + test3);
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
}
|
||||
|
||||
String[] keys = { "Now", "Time", "For", "All", "Good", "Men", "Come" };
|
||||
checkKeys(bundle.getKeys(), keys);
|
||||
|
||||
Locale.setDefault(saveDefault);
|
||||
}
|
||||
|
||||
public void TestListResourceBundle() {
|
||||
// load up the resource and check to make sure we got the right class
|
||||
// (we don't define be_BY or be, so we fall back on the root default)
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
|
||||
Locale.of("be", "BY"),
|
||||
Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
|
||||
if (!bundle.getClass().getName().equals("TestResource"))
|
||||
errln("Expected TestResource, got " + bundle.getClass().getName());
|
||||
|
||||
doListResourceBundleTest(bundle);
|
||||
}
|
||||
|
||||
/**
|
||||
* @bug 4073127
|
||||
* Repeat TestListResourceBundle on TestResource_it, which is a ListResourceBundle
|
||||
* with NO contents. It should gracefully inherit everything from the root
|
||||
* TestResource.
|
||||
*/
|
||||
public void TestEmptyListResourceBundle() {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
|
||||
Locale.ITALY);
|
||||
doListResourceBundleTest(bundle);
|
||||
}
|
||||
|
||||
private void doListResourceBundleTest(ResourceBundle bundle) {
|
||||
// load up the resource and check to make sure we got the right class
|
||||
// all of these resources are defined in TestResource; it doesn' inherit from anybody
|
||||
String test1 = bundle.getString("Now");
|
||||
if (!test1.equals("Now is the time for all..."))
|
||||
errln("TestResource returned wrong value for \"Now\": got " + test1);
|
||||
|
||||
test1 = bundle.getString("Time");
|
||||
if (!test1.equals("Howdy Doody Time!"))
|
||||
errln("TestResource returned wrong value for \"Time\": got " + test1);
|
||||
|
||||
test1 = bundle.getString("Come");
|
||||
if (!test1.equals("Come into my parlor..."))
|
||||
errln("TestResource returned wrong value for \"Come\": got " + test1);
|
||||
|
||||
Object test3 = bundle.getObject("Good");
|
||||
if (test3 == null || test3.getClass() != Integer.class)
|
||||
errln("TestResource returned an object of the wrong class for \"Good\"");
|
||||
else if (((Integer)test3).intValue() != 27)
|
||||
errln("TestResource returned the wrong value for \"Good\": got " + test3);
|
||||
|
||||
String[] test2 = bundle.getStringArray("Men");
|
||||
if (test2.length != 3)
|
||||
errln("TestResource returned wrong number of elements for \"Men\": got " + test2.length);
|
||||
else if (!test2[0].equals("1") ||
|
||||
!test2[1].equals("2") ||
|
||||
!test2[2].equals("C"))
|
||||
errln("TestResource returned the wrong value for one of the elements in \"All\"");
|
||||
|
||||
// this item isn't defined in TestResource
|
||||
try {
|
||||
test3 = bundle.getObject("All");
|
||||
errln("TestResource_en returned a value for \"All\" when it shouldn't: got " + test3);
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
}
|
||||
|
||||
String[] keys = { "Now", "Time", "Good", "Men", "Come" };
|
||||
checkKeys(bundle.getKeys(), keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* @bug 4049325
|
||||
* @ summary Bug 4049325 says ResourceBundle.findBundle() uses a hard-coded '/' as
|
||||
* the directory separator when searching for properties files. Interestingly, it
|
||||
* still works on my NT installation. I can't tell whether this is a required
|
||||
* property of all Java implementations (the magic appears to happen ClassLoader.
|
||||
* getResourceAsStream(), which is a native function) or a lucky property of my
|
||||
* particular implementation. If this bug regresses, this test may still pass
|
||||
* because a lower-level facility translates the / to the platform-specific separator
|
||||
* for us.
|
||||
*/
|
||||
public void TestPropertyResourceBundle() {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle("TestResource",
|
||||
Locale.of("es", "ES"));
|
||||
|
||||
// these resources are defined in TestResource_es.properties
|
||||
String test = bundle.getString("Now");
|
||||
if (!test.equals("How now brown cow"))
|
||||
errln("TestResource_es returned wrong value for \"Now\": got " + test);
|
||||
|
||||
test = bundle.getString("Is");
|
||||
if (!test.equals("Is there a dog?"))
|
||||
errln("TestResource_es returned wrong value for \"Is\": got " + test);
|
||||
|
||||
test = bundle.getString("The");
|
||||
if (!test.equals("The rain in Spain"))
|
||||
errln("TestResource_es returned wrong value for \"The\": got " + test);
|
||||
|
||||
test = bundle.getString("Time");
|
||||
if (!test.equals("Time marches on..."))
|
||||
errln("TestResource_es returned wrong value for \"Time\": got " + test);
|
||||
|
||||
// this resource is defined in TestResource and inherited by TestResource_es
|
||||
String[] test2 = bundle.getStringArray("Men");
|
||||
if (test2.length != 3)
|
||||
errln("TestResource returned wrong number of elements for \"Men\": got " + test2.length);
|
||||
else if (!test2[0].equals("1") ||
|
||||
!test2[1].equals("2") ||
|
||||
!test2[2].equals("C"))
|
||||
errln("TestResource returned the wrong value for one of the elements in \"All\"");
|
||||
|
||||
// this resource is defined in neither TestResource nor TestResource_es
|
||||
try {
|
||||
test = bundle.getString("All");
|
||||
errln("TestResource_es returned a value for \"All\" when it shouldn't: got " + test);
|
||||
}
|
||||
catch (MissingResourceException e) {
|
||||
}
|
||||
|
||||
String[] keys = { "Now", "Is", "The", "Time", "Good", "Men", "Come" };
|
||||
checkKeys(bundle.getKeys(), keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* @bug 4108126
|
||||
*/
|
||||
public void TestGetLocale() {
|
||||
// try to find TestResource_fr_CH. Should get fr_CH as its locale
|
||||
ResourceBundle test = ResourceBundle.getBundle("TestResource",
|
||||
Locale.of("fr", "CH"));
|
||||
Locale locale = test.getLocale();
|
||||
if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("CH")))
|
||||
errln("Actual locale for TestResource_fr_CH should have been fr_CH, got " + locale);
|
||||
|
||||
// try to find TestResource_fr_BE, which doesn't exist. Should get fr as its locale
|
||||
test = ResourceBundle.getBundle("TestResource",
|
||||
Locale.of("fr", "BE"));
|
||||
locale = test.getLocale();
|
||||
if (!(locale.getLanguage().equals("fr")) || !(locale.getCountry().equals("")))
|
||||
errln("Actual locale for TestResource_fr_BE should have been fr, got " + locale);
|
||||
|
||||
// try to find TestResource_iw_IL, which doesn't exist. Should get root locale
|
||||
// as its locale
|
||||
test = ResourceBundle.getBundle("TestResource",
|
||||
Locale.of("iw", "IL"),
|
||||
Control.getNoFallbackControl(Control.FORMAT_DEFAULT));
|
||||
locale = test.getLocale();
|
||||
if (!(locale.getLanguage().equals("")) || !(locale.getCountry().equals("")))
|
||||
errln("Actual locale for TestResource_iw_IL should have been the root locale, got "
|
||||
+ locale);
|
||||
}
|
||||
|
||||
/*
|
||||
* @bug 4083270
|
||||
*/
|
||||
public void TestNonSubclass() {
|
||||
// ResourceBundle.getBundle should never return an object that isn't an instance
|
||||
// of ResourceBundle or one of its subclasses. We have a class called FakeTestResource
|
||||
// in this package that isn't a ResourceBundle. If we get that back, we barf.
|
||||
// (Actually, at the time I fixed this bug, getResource() would throw a
|
||||
// ClassCastException in that case.)
|
||||
// There's also a properties file called FakeTestResource; we should get back a
|
||||
// PropertyResourceBundle pointing to that file.
|
||||
Object test1 = ResourceBundle.getBundle("FakeTestResource",
|
||||
Locale.US);
|
||||
|
||||
if (!(test1 instanceof ResourceBundle))
|
||||
errln("Got back a " + test1.getClass().getName() + " instead of a PropertyResourceBundle when looking for FakeTestResource.");
|
||||
|
||||
ResourceBundle test = (ResourceBundle)test1;
|
||||
|
||||
// there's also a properties file called FakeTestResource. getBundle() should
|
||||
// find it, and it should have the following contents
|
||||
String message = test.getString("message");
|
||||
if (!message.equals("Hello!"))
|
||||
errln("Supposedly found FakeTestResource.properties, but it had the wrong contents.");
|
||||
}
|
||||
|
||||
/*
|
||||
* @bug 4106034
|
||||
*/
|
||||
public void TestErrorMessage() {
|
||||
// Ensure that the message produced by the exception thrown
|
||||
// by ResourceBundle.getObject contains both the class name and
|
||||
// the key name.
|
||||
final String className = "TestResource";
|
||||
final String keyName = "DontGetThis";
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(className,
|
||||
Locale.ITALY);
|
||||
try {
|
||||
Object o = bundle.getObject(keyName);
|
||||
errln(bundle.getClass().getName()+" returned a value for tag \""+keyName+"\" when it should have thrown an exception. It returned "+o);
|
||||
} catch (MissingResourceException e) {
|
||||
String message = e.getMessage();
|
||||
boolean found = false;
|
||||
if (message.indexOf(className) < 0) {
|
||||
errln("MissingResourceException error message did not contain class name.");
|
||||
}
|
||||
if (message.indexOf(keyName) < 0) {
|
||||
errln("MissingResourceException error message did not contain resource key name.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @bug 8171139
|
||||
* @summary Make sure clearCache() clears cached ResourceBundle instances
|
||||
*/
|
||||
public void TestClearCache() {
|
||||
final String className = "TestResource";
|
||||
Locale loc = Locale.getDefault();
|
||||
|
||||
// testing no-arg clearCache()
|
||||
ResourceBundle rb1 = ResourceBundle.getBundle(className, loc);
|
||||
ResourceBundle.clearCache();
|
||||
ResourceBundle rb2 = ResourceBundle.getBundle(className, loc);
|
||||
if (rb1 == rb2) {
|
||||
errln("clearCache(no-arg) did not clear cache");
|
||||
}
|
||||
|
||||
// clearCache() with a custom classloader
|
||||
ClassLoader cl1 = new DummyClassLoader();
|
||||
rb1 = ResourceBundle.getBundle(className, loc, cl1);
|
||||
if (rb1 == rb2) {
|
||||
errln("Same bundle was returned for different class loaders");
|
||||
}
|
||||
ResourceBundle.clearCache(cl1);
|
||||
rb2= ResourceBundle.getBundle(className, loc, cl1);
|
||||
if (rb1 == rb2) {
|
||||
errln("clearCache(classLoader) did not clear cache");
|
||||
}
|
||||
ClassLoader cl2 = new DummyClassLoader();
|
||||
rb1 = ResourceBundle.getBundle(className, loc, cl2);
|
||||
if (rb1 == rb2) {
|
||||
errln("Same bundle was returned for different class loaders");
|
||||
}
|
||||
ResourceBundle.clearCache(cl1);
|
||||
rb2 = ResourceBundle.getBundle(className, loc, cl2);
|
||||
if (rb1 != rb2) {
|
||||
errln("clearCache(classLoader) incorrectly cleared cache");
|
||||
}
|
||||
}
|
||||
|
||||
private void makePropertiesFile() {
|
||||
try {
|
||||
//
|
||||
// The getProperty call is to ensure that this test will work with
|
||||
// the JTREG test harness. When running in the harness, the current
|
||||
// directory is often set to someplace that isn't on the CLASSPATH,
|
||||
// so we can't just create the properties files in the current
|
||||
// directory. But the harness uses the "test.classes" property to
|
||||
// tell us where the classes directory is.
|
||||
//
|
||||
String classesDir = System.getProperty("test.classes", ".");
|
||||
File file = new File(classesDir, "TestResource_es.properties");
|
||||
if (!file.exists()) {
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
Properties props = new Properties();
|
||||
|
||||
props.put("Now", "How now brown cow");
|
||||
props.put("Is", "Is there a dog?");
|
||||
props.put("The", "The rain in Spain");
|
||||
props.put("Time", "Time marches on...");
|
||||
|
||||
props.save(stream, "Test property list");
|
||||
|
||||
stream.close();
|
||||
}
|
||||
|
||||
file = new File(classesDir, "FakeTestResource.properties");
|
||||
if (!file.exists()) {
|
||||
FileOutputStream stream = new FileOutputStream(file);
|
||||
Properties props = new Properties();
|
||||
|
||||
props.put("message", "Hello!");
|
||||
|
||||
props.save(stream, "Test property list");
|
||||
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
catch (java.io.IOException e) {
|
||||
errln("Got exception: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkKeys(Enumeration testKeys, String[] expectedKeys) {
|
||||
Hashtable hash = new Hashtable();
|
||||
String element;
|
||||
int elementCount = 0;
|
||||
|
||||
for (int i=0; i < expectedKeys.length; i++)
|
||||
hash.put(expectedKeys[i], expectedKeys[i]);
|
||||
|
||||
while (testKeys.hasMoreElements()) {
|
||||
element = (String)testKeys.nextElement();
|
||||
elementCount++;
|
||||
if (!hash.containsKey(element))
|
||||
errln(element + " missing from key list.");
|
||||
}
|
||||
|
||||
if (elementCount != expectedKeys.length)
|
||||
errln("Wrong number of elements in key list: expected " + expectedKeys.length +
|
||||
" got " + elementCount);
|
||||
}
|
||||
|
||||
private static class DummyClassLoader extends ClassLoader {
|
||||
public DummyClassLoader() {
|
||||
super(DummyClassLoader.class.getClassLoader());
|
||||
}
|
||||
|
||||
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
||||
return DummyClassLoader.class.getClassLoader().loadClass(name);
|
||||
}
|
||||
|
||||
public URL getResource(String name) {
|
||||
return DummyClassLoader.class.getClassLoader().getResource(name);
|
||||
}
|
||||
|
||||
public InputStream getResourceAsStream(String name) {
|
||||
return DummyClassLoader.class.getClassLoader().getResourceAsStream(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
test/jdk/java/util/ResourceBundle/Test4300693.java
Normal file
45
test/jdk/java/util/ResourceBundle/Test4300693.java
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
@test
|
||||
@summary test that ResourceBundle.getBundle can be called recursively
|
||||
@build Test4300693RB
|
||||
@run main Test4300693
|
||||
@bug 4300693
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Test4300693 {
|
||||
|
||||
private static ResourceBundle rb = ResourceBundle.getBundle("Test4300693RB");
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(rb.getString("test result"));
|
||||
}
|
||||
|
||||
}
|
||||
42
test/jdk/java/util/ResourceBundle/Test4300693RB.java
Normal file
42
test/jdk/java/util/ResourceBundle/Test4300693RB.java
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Test4300693RB extends ListResourceBundle {
|
||||
|
||||
public static ResourceBundle rb = ResourceBundle.getBundle("Test4300693RB");
|
||||
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
|
||||
static final Object[][] contents = {
|
||||
{"test result", "Test4300693 succeeded"}
|
||||
};
|
||||
|
||||
}
|
||||
113
test/jdk/java/util/ResourceBundle/Test4314141.java
Normal file
113
test/jdk/java/util/ResourceBundle/Test4314141.java
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
@test
|
||||
@summary Verify a few assertions of the new specification of ResourceBundle.getBundle
|
||||
@build Test4314141B Test4314141B_fr_CH Test4314141B_es_ES
|
||||
@run main Test4314141
|
||||
@bug 4314141
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
|
||||
public class Test4314141 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Locale reservedLocale = Locale.getDefault();
|
||||
try {
|
||||
testCandidateOmission();
|
||||
testExample();
|
||||
} finally {
|
||||
// restore the reserved locale
|
||||
Locale.setDefault(reservedLocale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that candidate bundle names where the final component is an empty string are omitted.
|
||||
* Previous versions of ResourceBundle might attempt to load bundles with a trailing
|
||||
* underscore (e.g., "Test4314141_") resulting from concatenation with an empty string.
|
||||
* This is no longer permitted.
|
||||
*/
|
||||
static void testCandidateOmission() {
|
||||
Locale.setDefault(Locale.US);
|
||||
doTestCandidateOmission("de", "DE", "EURO", new String[] {"_de", ""});
|
||||
doTestCandidateOmission("de", "DE", "", new String[] {"_de", ""});
|
||||
doTestCandidateOmission("de", "", "EURO", new String[] {"_de", ""});
|
||||
doTestCandidateOmission("de", "", "", new String[] {"_de", ""});
|
||||
doTestCandidateOmission("", "DE", "EURO", new String[] {"__DE", ""});
|
||||
doTestCandidateOmission("", "DE", "", new String[] {"__DE", ""});
|
||||
doTestCandidateOmission("", "", "EURO", new String[] {"___EURO", ""});
|
||||
doTestCandidateOmission("", "", "", new String[] {""});
|
||||
}
|
||||
|
||||
static void doTestCandidateOmission(String language, String country, String variant,
|
||||
String[] expectedSuffixes) {
|
||||
doTest("Test4314141A", language, country, variant, expectedSuffixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies the example from the getBundle specification.
|
||||
*/
|
||||
static void testExample() {
|
||||
Locale.setDefault(Locale.of("en", "UK"));
|
||||
doTestExample("fr", "CH", new String[] {"_fr_CH.class", "_fr.properties", ".class"});
|
||||
doTestExample("fr", "FR", new String[] {"_fr.properties", ".class"});
|
||||
doTestExample("de", "DE", new String[] {"_en.properties", ".class"});
|
||||
doTestExample("en", "US", new String[] {"_en.properties", ".class"});
|
||||
doTestExample("es", "ES", new String[] {"_es_ES.class", ".class"});
|
||||
}
|
||||
|
||||
static void doTestExample(String language, String country, String[] expectedSuffixes) {
|
||||
doTest("Test4314141B", language, country, "", expectedSuffixes);
|
||||
}
|
||||
|
||||
static void doTest(String baseName, String language, String country, String variant,
|
||||
String[] expectedSuffixes) {
|
||||
System.out.print("Looking for " + baseName + " \"" + language + "\", \"" + country + "\", \"" + variant + "\"");
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(baseName, Locale.of(language, country, variant));
|
||||
System.out.print(" => got ");
|
||||
String previousName = null;
|
||||
int nameCount = 0;
|
||||
for (int i = 3; i >= 0; i--) {
|
||||
String name = bundle.getString("name" + i);
|
||||
if (!name.equals(previousName)) {
|
||||
if (previousName != null) {
|
||||
System.out.print(", ");
|
||||
}
|
||||
System.out.print(name);
|
||||
if (!name.equals(baseName + expectedSuffixes[nameCount++])) {
|
||||
System.out.println();
|
||||
throw new RuntimeException("Error: got unexpected resource bundle");
|
||||
}
|
||||
previousName = name;
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
if (nameCount != expectedSuffixes.length) {
|
||||
throw new RuntimeException("Error: parent chain too short");
|
||||
}
|
||||
}
|
||||
}
|
||||
26
test/jdk/java/util/ResourceBundle/Test4314141A.properties
Normal file
26
test/jdk/java/util/ResourceBundle/Test4314141A.properties
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name0=Test4314141A
|
||||
name1=Test4314141A
|
||||
name2=Test4314141A
|
||||
name3=Test4314141A
|
||||
25
test/jdk/java/util/ResourceBundle/Test4314141A_.properties
Normal file
25
test/jdk/java/util/ResourceBundle/Test4314141A_.properties
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name1=Test4314141A_
|
||||
name2=Test4314141A_
|
||||
name3=Test4314141A_
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name2=Test4314141A__DE
|
||||
name3=Test4314141A__DE
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name3=Test4314141A___EURO
|
||||
25
test/jdk/java/util/ResourceBundle/Test4314141A_de.properties
Normal file
25
test/jdk/java/util/ResourceBundle/Test4314141A_de.properties
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name1=Test4314141A_de
|
||||
name2=Test4314141A_de
|
||||
name3=Test4314141A_de
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name2=Test4314141A_de_
|
||||
name3=Test4314141A_de_
|
||||
34
test/jdk/java/util/ResourceBundle/Test4314141B.java
Normal file
34
test/jdk/java/util/ResourceBundle/Test4314141B.java
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Test4314141B extends ListResourceBundle {
|
||||
protected Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{"name0", "Test4314141B.class"},
|
||||
{"name1", "Test4314141B.class"},
|
||||
{"name2", "Test4314141B.class"},
|
||||
{"name3", "Test4314141B.class"}
|
||||
};
|
||||
}
|
||||
}
|
||||
25
test/jdk/java/util/ResourceBundle/Test4314141B_en.properties
Normal file
25
test/jdk/java/util/ResourceBundle/Test4314141B_en.properties
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name1=Test4314141B_en.properties
|
||||
name2=Test4314141B_en.properties
|
||||
name3=Test4314141B_en.properties
|
||||
32
test/jdk/java/util/ResourceBundle/Test4314141B_es_ES.java
Normal file
32
test/jdk/java/util/ResourceBundle/Test4314141B_es_ES.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Test4314141B_es_ES extends ListResourceBundle {
|
||||
protected Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{"name2", "Test4314141B_es_ES.class"},
|
||||
{"name3", "Test4314141B_es_ES.class"}
|
||||
};
|
||||
}
|
||||
}
|
||||
25
test/jdk/java/util/ResourceBundle/Test4314141B_fr.properties
Normal file
25
test/jdk/java/util/ResourceBundle/Test4314141B_fr.properties
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name1=Test4314141B_fr.properties
|
||||
name2=Test4314141B_fr.properties
|
||||
name3=Test4314141B_fr.properties
|
||||
32
test/jdk/java/util/ResourceBundle/Test4314141B_fr_CH.java
Normal file
32
test/jdk/java/util/ResourceBundle/Test4314141B_fr_CH.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class Test4314141B_fr_CH extends ListResourceBundle {
|
||||
protected Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{"name2", "Test4314141B_fr_CH.class"},
|
||||
{"name3", "Test4314141B_fr_CH.class"}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name2=Test4314141B_fr_CH.properties
|
||||
name3=Test4314141B_fr_CH.properties
|
||||
59
test/jdk/java/util/ResourceBundle/Test4318520.java
Normal file
59
test/jdk/java/util/ResourceBundle/Test4318520.java
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
/*
|
||||
@test
|
||||
@summary test that getBundle handles change in default locale correctly
|
||||
@bug 4318520
|
||||
*/
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Locale;
|
||||
|
||||
public class Test4318520 {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Locale reservedLocale = Locale.getDefault();
|
||||
try {
|
||||
test(Locale.GERMAN);
|
||||
test(Locale.ENGLISH);
|
||||
} finally {
|
||||
// restore the reserved locale
|
||||
Locale.setDefault(reservedLocale);
|
||||
}
|
||||
}
|
||||
|
||||
private static void test(Locale locale) {
|
||||
Locale.setDefault(locale);
|
||||
ResourceBundle myResources =
|
||||
ResourceBundle.getBundle("Test4318520RB", Locale.FRENCH);
|
||||
String actualLocale = myResources.getString("name");
|
||||
if (!actualLocale.equals(locale.toString())) {
|
||||
System.out.println("expected: " + locale + ", got: " + actualLocale);
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
#
|
||||
# Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
#
|
||||
# This code is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License version 2 only, as
|
||||
# published by the Free Software Foundation.
|
||||
#
|
||||
# This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
# version 2 for more details (a copy is included in the LICENSE file that
|
||||
# accompanied this code).
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License version
|
||||
# 2 along with this work; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
# or visit www.oracle.com if you need additional information or have any
|
||||
# questions.
|
||||
#
|
||||
name=de
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue