< prev index next >
src/java.base/share/classes/java/security/Security.java
Print this page
@@ -23,15 +23,16 @@
* questions.
*/
package java.security;
-import java.lang.reflect.*;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.io.*;
import java.net.URL;
+
+import jdk.internal.misc.SharedSecrets;
import sun.security.util.Debug;
import sun.security.util.PropertyExpander;
import sun.security.jca.*;
@@ -798,56 +799,19 @@
* Implementation detail: If the property we just set in
* setProperty() was either "package.access" or
* "package.definition", we need to signal to the SecurityManager
* class that the value has just changed, and that it should
* invalidate it's local cache values.
- *
- * Rather than create a new API entry for this function,
- * we use reflection to set a private variable.
*/
private static void invalidateSMCache(String key) {
final boolean pa = key.equals("package.access");
final boolean pd = key.equals("package.definition");
if (pa || pd) {
- AccessController.doPrivileged(new PrivilegedAction<>() {
- public Void run() {
- try {
- /* Get the class via the bootstrap class loader. */
- Class<?> cl = Class.forName(
- "java.lang.SecurityManager", false, null);
- Field f = null;
- boolean accessible = false;
-
- if (pa) {
- f = cl.getDeclaredField("packageAccessValid");
- accessible = f.isAccessible();
- f.setAccessible(true);
- } else {
- f = cl.getDeclaredField("packageDefinitionValid");
- accessible = f.isAccessible();
- f.setAccessible(true);
- }
- f.setBoolean(f, false);
- f.setAccessible(accessible);
- }
- catch (Exception e1) {
- /* If we couldn't get the class, it hasn't
- * been loaded yet. If there is no such
- * field, we shouldn't try to set it. There
- * shouldn't be a security execption, as we
- * are loaded by boot class loader, and we
- * are inside a doPrivileged() here.
- *
- * NOOP: don't do anything...
- */
+ SharedSecrets.getJavaLangAccess().invalidatePackageAccessCache();
}
- return null;
- } /* run */
- }); /* PrivilegedAction */
- } /* if */
}
private static void check(String directive) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
< prev index next >