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
|
|
@ -0,0 +1,340 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2025, 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 8137317 8139238 8210408
|
||||
* @summary Visibility tests for ResourceBundle.getBundle with and without
|
||||
* an unnamed module argument.
|
||||
* @requires vm.flagless
|
||||
* @library /test/lib
|
||||
* ..
|
||||
* @build jdk.test.lib.JDKToolLauncher
|
||||
* jdk.test.lib.Utils
|
||||
* jdk.test.lib.compiler.CompilerUtils
|
||||
* jdk.test.lib.process.ProcessTools
|
||||
* ModuleTestUtil
|
||||
* @run junit VisibilityTest
|
||||
*/
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import jdk.test.lib.JDKToolLauncher;
|
||||
import jdk.test.lib.Utils;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class VisibilityTest {
|
||||
private static final Path SRC_DIR = Paths.get(Utils.TEST_SRC, "src");
|
||||
private static final Path MODS_DIR = Paths.get(Utils.TEST_CLASSES, "mods");
|
||||
private static final Path CLASSES_DIR = Paths.get(Utils.TEST_CLASSES, "classes");
|
||||
private static final Path NAMED_BUNDLES_DIR = MODS_DIR.resolve("named.bundles");
|
||||
private static final Path EXPORTED_NAMED_BUNDLES_DIR = MODS_DIR.resolve("exported.named.bundles");
|
||||
|
||||
private static final List<String> MODULE_LIST = List.of("embargo",
|
||||
"exported.named.bundles", "named.bundles", "test");
|
||||
|
||||
@BeforeAll
|
||||
public void prepareTestEnv() throws Throwable {
|
||||
MODULE_LIST.forEach(mn -> ModuleTestUtil.prepareModule(SRC_DIR,
|
||||
MODS_DIR, mn, ".properties"));
|
||||
|
||||
// Prepare resource bundles in an unnamed module
|
||||
ModuleTestUtil.compilePkg(SRC_DIR, CLASSES_DIR, "pkg");
|
||||
ModuleTestUtil.copyResFiles(SRC_DIR, CLASSES_DIR, "pkg", ".properties");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Package jdk.test is in named module "test".
|
||||
* Package jdk.embargo is in named module "embargo".
|
||||
*
|
||||
* jdk.{test,embargo}.TestWithUnnamedModuleArg call:
|
||||
* ResourceBundle.getBundle(basename, classloader.getUnnamedModule())
|
||||
* where classloader is the TCCL or system class loader.
|
||||
* jdk.{test,embargo}.TestWithNoModuleArg call:
|
||||
* ResourceBundle.getBundle(basename)
|
||||
*
|
||||
* jdk.test.resources[.exported].classes.* are class-based resource bundles.
|
||||
* jdk.test.resources[.exported].props.* are properties file-based resource bundles.
|
||||
*
|
||||
* Packages jdk.test.resources.{classes,props} in named module "named.bundles"
|
||||
* are exported only to named module "test".
|
||||
* Packages jdk.test.resources.exported.{classes,props} in named module
|
||||
* "exported.named.bundle" are exported to unnamed modules.
|
||||
*/
|
||||
|
||||
Object[][] RunWithTestResData() {
|
||||
return new Object[][] {
|
||||
// Tests using jdk.test.TestWithNoModuleArg and jdk.embargo.TestWithNoModuleArg.
|
||||
// Neither of which specifies an unnamed module with ResourceBundle.getBundle().
|
||||
|
||||
// jdk.test.resources.{classes,props}.* are available only to
|
||||
// named module "test" by ResourceBundleProvider.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "false")},
|
||||
|
||||
// Add mods/named.bundles to the class path.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
|
||||
// Tests using jdk.test.TestWithUnnamedModuleArg and
|
||||
// jdk.embargo.TestWithUnnamedModuleArg.
|
||||
// Both of which specify an unnamed module with ResourceBundle.getBundle.
|
||||
|
||||
// jdk.test.resources.classes is exported to named module "test".
|
||||
// IllegalAccessException is thrown in ResourceBundle.Control.newBundle().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "false")},
|
||||
|
||||
// jdk.test.resources.props is exported to named module "test".
|
||||
// loader.getResource() doesn't find jdk.test.resources.props.MyResources.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "false")},
|
||||
|
||||
// IllegalAccessException is thrown in ResourceBundle.Control.newBundle().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "false")},
|
||||
|
||||
// jdk.test.resources.props is exported to named module "test".
|
||||
// loader.getResource() doesn't find jdk.test.resources.props.MyResources.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "false")},
|
||||
|
||||
// Add mods/named.bundles to the class path.
|
||||
|
||||
// IllegalAccessException is thrown in ResourceBundle.Control.newBundle().
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "false")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
|
||||
// jdk.test.resources.exported.classes.MyResources is treated
|
||||
// as if the class is in an unnamed module.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.classes.MyResources", "true")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.props.MyResources", "true")},
|
||||
};
|
||||
}
|
||||
|
||||
Object[][] RunWithExportedResData() {
|
||||
return new Object[][] {
|
||||
// Tests using jdk.test.TestWithNoModuleArg and jdk.embargo.TestWithNoModuleArg
|
||||
// neither of which specifies an unnamed module with ResourceBundle.getBundle.
|
||||
|
||||
// None of jdk.test.resources.exported.** is available to the named modules.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "false")},
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "false")},
|
||||
|
||||
// Add mods/exported.named.bundles to the class path.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "true")},
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithNoModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "true")},
|
||||
|
||||
// Tests using jdk.test.TestWithUnnamedModuleArg and
|
||||
// jdk.embargo.TestWithUnnamedModuleArg which specify
|
||||
// an unnamed module with ResourceBundle.getBundle.
|
||||
|
||||
// loader.loadClass() doesn't find jdk.test.resources.exported.classes.MyResources
|
||||
// and throws a ClassNotFoundException.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "false")},
|
||||
|
||||
// The properties files in jdk.test.resources.exported.props
|
||||
// are not found with loader.getResource().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "false")},
|
||||
|
||||
// loader.loadClass() doesn't find jdk.test.resources.exported.classes.MyResources
|
||||
// and throws a ClassNotFoundException.
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "false")},
|
||||
|
||||
// The properties files in jdk.test.resources.exported.props are not found
|
||||
// with loader.getResource().
|
||||
{List.of("-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "false")},
|
||||
|
||||
// Add mods/exported.named.bundles to the class path.
|
||||
|
||||
// jdk.test.resources.exported.classes.MyResources.getModule().isNamed()
|
||||
// returns false.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "test/jdk.test.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "true")},
|
||||
|
||||
// jdk.test.resources.exported.classes.MyResources.getModule().isNamed()
|
||||
// returns false.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.classes.MyResources", "true")},
|
||||
|
||||
// loader.getResource() finds jdk.test.resources.exported.props.MyResources.
|
||||
{List.of("-cp", EXPORTED_NAMED_BUNDLES_DIR.toString(),
|
||||
"-p", MODS_DIR.toString(),
|
||||
"-m", "embargo/jdk.embargo.TestWithUnnamedModuleArg",
|
||||
"jdk.test.resources.exported.props.MyResources", "true")},
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
Object[][] RunWithPkgResData() {
|
||||
return new Object[][] {
|
||||
// jdk.pkg.resources.* are in an unnamed module.
|
||||
// jdk.pkg.test.Main calls ResourceBundle.getBundle with an unnamed module.
|
||||
{ List.of("-cp", CLASSES_DIR.resolve("pkg").toString(), "jdk.pkg.test.Main",
|
||||
"jdk.pkg.resources.classes.MyResources", "true")},
|
||||
{ List.of("-cp", CLASSES_DIR.resolve("pkg").toString(), "jdk.pkg.test.Main",
|
||||
"jdk.pkg.resources.props.MyResources", "true")},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases with jdk.test.resources.*
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("RunWithTestResData")
|
||||
public void RunWithTestRes(List<String> argsList) throws Throwable {
|
||||
int exitCode = runCmd(argsList);
|
||||
assertEquals(0, exitCode, "Execution of the tests with "
|
||||
+ "jdk.test.resources.* failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases with jdk.test.resources.exported.*
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("RunWithExportedResData")
|
||||
public void RunWithExportedRes(List<String> argsList) throws Throwable {
|
||||
int exitCode = runCmd(argsList);
|
||||
assertEquals(0, exitCode, "Execution of the tests with "
|
||||
+ "jdk.test.resources.exported.* failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test cases with jdk.pkg.resources.*
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@MethodSource("RunWithPkgResData")
|
||||
public void RunWithPkgRes(List<String> argsList) throws Throwable {
|
||||
int exitCode = runCmd(argsList);
|
||||
assertEquals(0, exitCode, "Execution of the tests with "
|
||||
+ "jdk.pkg.resources.* failed. "
|
||||
+ "Unexpected exit code: " + exitCode);
|
||||
}
|
||||
|
||||
private int runCmd(List<String> argsList) throws Throwable {
|
||||
// Build process (without VM flags)
|
||||
ProcessBuilder pb = ProcessTools.createLimitedTestJavaProcessBuilder(
|
||||
Stream.concat(Stream.of("-ea", "-esa"), argsList.stream()).toList());
|
||||
// Evaluate process status
|
||||
return ProcessTools.executeCommand(pb).getExitValue();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.embargo;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class TestWithNoModuleArg {
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
System.out.println("Usage: java ... basename should-be-loaded-flag");
|
||||
System.out.println(" ex. java ... jdk.test.resources.classes.MyResources false");
|
||||
return;
|
||||
}
|
||||
|
||||
String basename = args[0];
|
||||
boolean shouldBeLoaded = "true".equals(args[1]);
|
||||
|
||||
int errors = 0;
|
||||
try {
|
||||
// Set the default Locale to Locale.ROOT to avoid any confusions related to fallback
|
||||
Locale.setDefault(Locale.ROOT);
|
||||
ResourceBundle rb = ResourceBundle.getBundle(basename);
|
||||
if (shouldBeLoaded) {
|
||||
System.out.println("Passed: got resource bundle:");
|
||||
} else {
|
||||
System.out.println("Failed: no MissingResourceException thrown");
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" bundle = " + rb);
|
||||
} catch (MissingResourceException e) {
|
||||
if (!shouldBeLoaded) {
|
||||
System.out.println("Passed: got expected " + e);
|
||||
} else {
|
||||
System.out.println("Failed: got unexpected " + e);
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" cause = " + e.getCause());
|
||||
} catch (Throwable t) {
|
||||
System.out.println("Failed: unexpected throwable: " + t);
|
||||
errors++;
|
||||
}
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException(errors + " errors");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.embargo;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class TestWithUnnamedModuleArg {
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
System.out.println("Usage: java ... basename should-be-loaded-flag");
|
||||
System.out.println(" ex. java ... jdk.test.resources.classes.MyResources false");
|
||||
return;
|
||||
}
|
||||
|
||||
String basename = args[0];
|
||||
boolean shouldBeLoaded = "true".equals(args[1]);
|
||||
|
||||
int errors = 0;
|
||||
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
|
||||
try {
|
||||
// Set the default Locale to Locale.ROOT to avoid any confusions related to fallback
|
||||
Locale.setDefault(Locale.ROOT);
|
||||
ResourceBundle rb = ResourceBundle.getBundle(basename,
|
||||
cl.getUnnamedModule());
|
||||
if (shouldBeLoaded) {
|
||||
System.out.println("Passed: got resource bundle:");
|
||||
} else {
|
||||
System.out.println("Failed: no MissingResourceException thrown");
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" bundle = " + rb);
|
||||
} catch (MissingResourceException e) {
|
||||
if (!shouldBeLoaded) {
|
||||
System.out.println("Passed: got expected " + e);
|
||||
} else {
|
||||
System.out.println("Failed: got unexpected " + e);
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" cause = " + e.getCause());
|
||||
} catch (Throwable t) {
|
||||
System.out.println("Failed: unexpected throwable: " + t);
|
||||
errors++;
|
||||
}
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException(errors + " errors");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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.
|
||||
*/
|
||||
|
||||
module embargo {
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.test.resources.exported.classes;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class MyResources extends ListResourceBundle {
|
||||
@Override
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "key", "root: message" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, 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 jdk.test.resources.exported.classes.spi;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.spi.AbstractResourceBundleProvider;
|
||||
|
||||
public class MyResourcesProvider extends AbstractResourceBundleProvider {
|
||||
public MyResourcesProvider() {
|
||||
super("java.class", "java.properties");
|
||||
System.err.println("MyResourcesProvider called " + this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toBundleName(String baseName, Locale locale) {
|
||||
StringBuilder sb = new StringBuilder(baseName);
|
||||
String lang = locale.getLanguage();
|
||||
if (!lang.isEmpty()) {
|
||||
sb.append('_').append(lang);
|
||||
String country = locale.getCountry();
|
||||
if (!country.isEmpty()) {
|
||||
sb.append('_').append(country);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (c) 2015, 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.
|
||||
#
|
||||
|
||||
key=root: message
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, 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.
|
||||
*/
|
||||
|
||||
module exported.named.bundles {
|
||||
// unqualified exports to verify that resource bundles are not picked
|
||||
// up by other named modules
|
||||
exports jdk.test.resources.exported.classes;
|
||||
provides jdk.test.resources.exported.classes.spi.MyResourcesProvider
|
||||
with jdk.test.resources.exported.classes.spi.MyResourcesProvider;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.test.resources.classes;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class MyResources extends ListResourceBundle {
|
||||
@Override
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "key", "root: message" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, 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 jdk.test.resources.classes.spi;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.spi.AbstractResourceBundleProvider;
|
||||
|
||||
public class MyResourcesProvider extends AbstractResourceBundleProvider {
|
||||
public MyResourcesProvider() {
|
||||
super("java.class");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toBundleName(String baseName, Locale locale) {
|
||||
StringBuilder sb = new StringBuilder(baseName);
|
||||
String lang = locale.getLanguage();
|
||||
if (!lang.isEmpty()) {
|
||||
sb.append('_').append(lang);
|
||||
String country = locale.getCountry();
|
||||
if (!country.isEmpty()) {
|
||||
sb.append('_').append(country);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceBundle getBundle(String baseName, Locale locale) {
|
||||
ResourceBundle rb = super.getBundle(baseName, locale);
|
||||
String tag = locale.toLanguageTag();
|
||||
if (tag.equals("und")) {
|
||||
tag = "ROOT"; // to a human friendly name
|
||||
}
|
||||
System.out.printf(" MyResourcesProvider.getBundle(%s, %s)%n -> %s%n",
|
||||
baseName, tag, rb);
|
||||
return rb;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (c) 2015, 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.
|
||||
#
|
||||
|
||||
key=root: message
|
||||
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, 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 jdk.test.resources.props.spi;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.spi.AbstractResourceBundleProvider;
|
||||
|
||||
public class MyResourcesProvider extends AbstractResourceBundleProvider {
|
||||
public MyResourcesProvider() {
|
||||
super("java.properties");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String toBundleName(String baseName, Locale locale) {
|
||||
StringBuilder sb = new StringBuilder(baseName);
|
||||
String lang = locale.getLanguage();
|
||||
if (!lang.isEmpty()) {
|
||||
sb.append('_').append(lang);
|
||||
String country = locale.getCountry();
|
||||
if (!country.isEmpty()) {
|
||||
sb.append('_').append(country);
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceBundle getBundle(String baseName, Locale locale) {
|
||||
ResourceBundle rb = super.getBundle(baseName, locale);
|
||||
String tag = locale.toLanguageTag();
|
||||
if (tag.equals("und")) {
|
||||
tag = "ROOT"; // to a human friendly name
|
||||
}
|
||||
System.out.printf(" MyResourcesProvider.getBundle(%s, %s)%n -> %s%n",
|
||||
baseName, tag, rb);
|
||||
return rb;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, 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.
|
||||
*/
|
||||
|
||||
module named.bundles {
|
||||
exports jdk.test.resources.classes.spi to test; // exports only to test
|
||||
exports jdk.test.resources.props.spi to test; // exports only to test
|
||||
provides jdk.test.resources.classes.spi.MyResourcesProvider
|
||||
with jdk.test.resources.classes.spi.MyResourcesProvider;
|
||||
provides jdk.test.resources.props.spi.MyResourcesProvider
|
||||
with jdk.test.resources.props.spi.MyResourcesProvider;
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.pkg.resources.classes;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public class MyResources extends ListResourceBundle {
|
||||
@Override
|
||||
public Object[][] getContents() {
|
||||
return new Object[][] {
|
||||
{ "key", "root: message" }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# Copyright (c) 2015, 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.
|
||||
#
|
||||
|
||||
key=root: message
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.pkg.test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
System.out.println("Usage: java ... basename should-be-loaded-flag");
|
||||
System.out.println(" ex. java ... jdk.test.resources.classes.MyResources false");
|
||||
return;
|
||||
}
|
||||
|
||||
String basename = args[0];
|
||||
boolean shouldBeLoaded = "true".equals(args[1]);
|
||||
|
||||
int errors = 0;
|
||||
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
|
||||
try {
|
||||
// Use the default Locale to avoid confusion related to fallback
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
ResourceBundle rb = ResourceBundle.getBundle(basename,
|
||||
cl.getUnnamedModule());
|
||||
if (shouldBeLoaded) {
|
||||
System.out.println("Passed: got resource bundle:");
|
||||
} else {
|
||||
System.out.println("Failed: no MissingResourceException thrown");
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" bundle = " + rb);
|
||||
} catch (MissingResourceException e) {
|
||||
if (!shouldBeLoaded) {
|
||||
System.out.println("Passed: got expected " + e);
|
||||
} else {
|
||||
System.out.println("Failed: got unexpected " + e);
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" cause = " + e.getCause());
|
||||
} catch (Throwable t) {
|
||||
System.out.println("Failed: unexpected throwable: " + t);
|
||||
errors++;
|
||||
}
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException(errors + " errors");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class TestWithNoModuleArg {
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
System.out.println("Usage: java ... basename should-be-loaded-flag");
|
||||
System.out.println(" ex. java ... jdk.test.resources.classes.MyResources false");
|
||||
return;
|
||||
}
|
||||
|
||||
String basename = args[0];
|
||||
boolean shouldBeLoaded = "true".equals(args[1]);
|
||||
|
||||
int errors = 0;
|
||||
try {
|
||||
// Set the default Locale to Locale.ROOT to avoid any confusions related to fallback
|
||||
Locale.setDefault(Locale.ROOT);
|
||||
ResourceBundle rb = ResourceBundle.getBundle(basename);
|
||||
if (shouldBeLoaded) {
|
||||
System.out.println("Passed: got resource bundle:");
|
||||
} else {
|
||||
System.out.println("Failed: no MissingResourceException thrown");
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" bundle = " + rb);
|
||||
} catch (MissingResourceException e) {
|
||||
if (!shouldBeLoaded) {
|
||||
System.out.println("Passed: got expected " + e);
|
||||
} else {
|
||||
System.out.println("Failed: got unexpected " + e);
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" cause = " + e.getCause());
|
||||
} catch (Throwable t) {
|
||||
System.out.println("Failed: unexpected throwable: " + t);
|
||||
errors++;
|
||||
}
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException(errors + " errors");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 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 jdk.test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class TestWithUnnamedModuleArg {
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length != 2) {
|
||||
System.out.println("Usage: java ... basename should-be-loaded-flag");
|
||||
System.out.println(" ex. java ... jdk.test.resources.classes.MyResources false");
|
||||
return;
|
||||
}
|
||||
|
||||
String basename = args[0];
|
||||
boolean shouldBeLoaded = "true".equals(args[1]);
|
||||
|
||||
int errors = 0;
|
||||
|
||||
ClassLoader cl = Thread.currentThread().getContextClassLoader();
|
||||
if (cl == null) {
|
||||
cl = ClassLoader.getSystemClassLoader();
|
||||
}
|
||||
|
||||
try {
|
||||
// Set the default Locale to Locale.ROOT to avoid any confusions related to fallback
|
||||
Locale.setDefault(Locale.ROOT);
|
||||
ResourceBundle rb = ResourceBundle.getBundle(basename,
|
||||
cl.getUnnamedModule());
|
||||
if (shouldBeLoaded) {
|
||||
System.out.println("Passed: got resource bundle:");
|
||||
} else {
|
||||
System.out.println("Failed: no MissingResourceException thrown");
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" bundle = " + rb);
|
||||
} catch (MissingResourceException e) {
|
||||
if (!shouldBeLoaded) {
|
||||
System.out.println("Passed: got expected " + e);
|
||||
} else {
|
||||
System.out.println("Failed: got unexpected " + e);
|
||||
errors++;
|
||||
}
|
||||
System.out.println(" cause = " + e.getCause());
|
||||
} catch (Throwable t) {
|
||||
System.out.println("Failed: unexpected throwable: " + t);
|
||||
errors++;
|
||||
}
|
||||
|
||||
if (errors > 0) {
|
||||
throw new RuntimeException(errors + " errors");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2017, 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.
|
||||
*/
|
||||
|
||||
module test {
|
||||
// jdk.test.resources.classes.spi.MyResourcesProvider is in named.bundles.
|
||||
requires named.bundles;
|
||||
uses jdk.test.resources.classes.spi.MyResourcesProvider;
|
||||
uses jdk.test.resources.props.spi.MyResourcesProvider;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue