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
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>
|
||||
Loading…
Add table
Add a link
Reference in a new issue