changeset 43305:8c539ce46344

8172808: Handle sun.security.util.Resources bundle in ResourcesMgr in the same way as AuthResources Reviewed-by: mullan
author mchung
date Wed, 25 Jan 2017 10:53:01 -0800
parents ef028cd46c9d
children 9f6c9b11a4b1
files jdk/src/java.base/share/classes/sun/security/util/LocalizedMessage.java jdk/src/java.base/share/classes/sun/security/util/ResourcesMgr.java jdk/test/sun/security/util/Resources/customSysClassLoader/CustomClassLoader.java
diffstat 3 files changed, 16 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/src/java.base/share/classes/sun/security/util/LocalizedMessage.java	Wed Jan 25 15:53:17 2017 +0100
+++ b/jdk/src/java.base/share/classes/sun/security/util/LocalizedMessage.java	Wed Jan 25 10:53:01 2017 -0800
@@ -4,7 +4,9 @@
  *
  * 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.
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
  *
  * This code is distributed in the hope that it will be useful, but WITHOUT
  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
--- a/jdk/src/java.base/share/classes/sun/security/util/ResourcesMgr.java	Wed Jan 25 15:53:17 2017 +0100
+++ b/jdk/src/java.base/share/classes/sun/security/util/ResourcesMgr.java	Wed Jan 25 10:53:01 2017 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000, 2006, 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
@@ -34,37 +34,24 @@
  */
 public class ResourcesMgr {
     // intended for java.security, javax.security and sun.security resources
-    private final static String RESOURCES = "sun.security.util.Resources";
-    private final static String AUTH_RESOURCES = "sun.security.util.AuthResources";
-
     private final static Map<String, ResourceBundle> bundles = new ConcurrentHashMap<>();
 
     public static String getString(String s) {
-        ResourceBundle bundle = bundles.get(RESOURCES);
-        if (bundle == null) {
-
-            // only load if/when needed
-            bundle = java.security.AccessController.doPrivileged(
-                new java.security.PrivilegedAction<java.util.ResourceBundle>() {
-                public java.util.ResourceBundle run() {
-                    return (java.util.ResourceBundle.getBundle
-                                ("sun.security.util.Resources"));
-                }
-            });
-        }
-
-        return bundle.getString(s);
+        return getBundle("sun.security.util.Resources").getString(s);
     }
 
     public static String getAuthResourceString(String s) {
-        if (VM.initLevel() == 3) {
-            // cannot trigger loading of any resource bundle as
-            // it depends on the system class loader fully initialized.
-            throw new InternalError("system class loader is being initialized");
+        return getBundle("sun.security.util.AuthResources").getString(s);
+    }
+
+    private static ResourceBundle getBundle(String bundleName) {
+        if (!VM.isBooted()) {
+            // don't expect this be called before the system is fully initialized.
+            // This triggers loading of any resource bundle that should be
+            // be done during initialization of system class loader.
+            throw new InternalError("Expected to use ResourceBundle only after booted");
         }
-
-        return bundles.computeIfAbsent(AUTH_RESOURCES, ResourceBundle::getBundle)
-                      .getString(s);
+        return bundles.computeIfAbsent(bundleName, ResourceBundle::getBundle);
     }
 
 }
--- a/jdk/test/sun/security/util/Resources/customSysClassLoader/CustomClassLoader.java	Wed Jan 25 15:53:17 2017 +0100
+++ b/jdk/test/sun/security/util/Resources/customSysClassLoader/CustomClassLoader.java	Wed Jan 25 10:53:01 2017 -0800
@@ -5,9 +5,7 @@
  *
  * 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.  Oracle designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Oracle in the LICENSE file that accompanied this code.
+ * 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