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:
russell@unturf.com 2026-03-26 17:11:57 -04:00
commit 0a580b313d
70422 changed files with 17213626 additions and 0 deletions

View file

@ -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");
}
}
}

View file

@ -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");
}
}
}

View file

@ -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 {
}

View file

@ -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" }
};
}
}

View file

@ -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();
}
}

View file

@ -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

View file

@ -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;
}

View file

@ -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" }
};
}
}

View file

@ -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;
}
}

View file

@ -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

View file

@ -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;
}
}

View file

@ -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;
}

View file

@ -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" }
};
}
}

View file

@ -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

View file

@ -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");
}
}
}

View file

@ -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");
}
}
}

View file

@ -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");
}
}
}

View file

@ -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;
}