From 351dc065f3d3733f8b78e246c993a560b587d39a Mon Sep 17 00:00:00 2001 From: naoto Date: Tue, 8 Aug 2017 11:07:46 -0700 Subject: [PATCH] 8182601: Improve usage messages Reviewed-by: alanb, ahgross, ksrini, mchung, dfuchs --- src/share/classes/java/util/ResourceBundle.java | 15 ++++++++++++--- src/share/classes/java/util/logging/Level.java | 16 +++++++++++----- src/share/classes/java/util/logging/Logger.java | 5 ++--- src/share/classes/javax/swing/UIDefaults.java | 5 +++-- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/share/classes/java/util/ResourceBundle.java b/src/share/classes/java/util/ResourceBundle.java index 134894ccd..b88b7bf66 100644 --- a/src/share/classes/java/util/ResourceBundle.java +++ b/src/share/classes/java/util/ResourceBundle.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1996, 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 @@ -485,7 +485,7 @@ public abstract class ResourceBundle { } /** - * A wrapper of ClassLoader.getSystemClassLoader(). + * A wrapper of Extension Class Loader */ private static class RBClassLoader extends ClassLoader { private static final RBClassLoader INSTANCE = AccessController.doPrivileged( @@ -494,7 +494,16 @@ public abstract class ResourceBundle { return new RBClassLoader(); } }); - private static final ClassLoader loader = ClassLoader.getSystemClassLoader(); + private static final ClassLoader loader; + static { + // Find the extension class loader. + ClassLoader ld = ClassLoader.getSystemClassLoader(); + ClassLoader parent; + while ((parent = ld.getParent()) != null) { + ld = parent; + } + loader = ld; + } private RBClassLoader() { } diff --git a/src/share/classes/java/util/logging/Level.java b/src/share/classes/java/util/logging/Level.java index e42336d36..7c6c9d522 100644 --- a/src/share/classes/java/util/logging/Level.java +++ b/src/share/classes/java/util/logging/Level.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -262,11 +262,17 @@ public class Level implements java.io.Serializable { } private String computeLocalizedLevelName(Locale newLocale) { - ResourceBundle rb = ResourceBundle.getBundle(resourceBundleName, newLocale); - final String localizedName = rb.getString(name); + // If this is a custom Level, load resource bundles on the + // classpath and return. + if (!defaultBundle.equals(resourceBundleName)) { + return ResourceBundle.getBundle(resourceBundleName, newLocale, + ClassLoader.getSystemClassLoader()).getString(name); + } - final boolean isDefaultBundle = defaultBundle.equals(resourceBundleName); - if (!isDefaultBundle) return localizedName; + // The default bundle "sun.util.logging.resources.logging" should only + // be loaded from the runtime; so use the extension class loader; + final ResourceBundle rb = ResourceBundle.getBundle(defaultBundle, newLocale); + final String localizedName = rb.getString(name); // This is a trick to determine whether the name has been translated // or not. If it has not been translated, we need to use Locale.ROOT diff --git a/src/share/classes/java/util/logging/Logger.java b/src/share/classes/java/util/logging/Logger.java index 61bbe4e3d..9e7bc7bca 100644 --- a/src/share/classes/java/util/logging/Logger.java +++ b/src/share/classes/java/util/logging/Logger.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2000, 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 @@ -1817,8 +1817,7 @@ public class Logger { public ResourceBundle run() { try { return ResourceBundle.getBundle(SYSTEM_LOGGER_RB_NAME, - locale, - ClassLoader.getSystemClassLoader()); + locale); } catch (MissingResourceException e) { throw new InternalError(e.toString()); } diff --git a/src/share/classes/javax/swing/UIDefaults.java b/src/share/classes/javax/swing/UIDefaults.java index 12c381453..7910c6bcc 100644 --- a/src/share/classes/javax/swing/UIDefaults.java +++ b/src/share/classes/javax/swing/UIDefaults.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 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 @@ -305,7 +305,8 @@ public class UIDefaults extends Hashtable if (c != null) { b = ResourceBundle.getBundle(bundleName, l, c); } else { - b = ResourceBundle.getBundle(bundleName, l); + b = ResourceBundle.getBundle(bundleName, l, + ClassLoader.getSystemClassLoader()); } Enumeration keys = b.getKeys(); -- GitLab