8344337: SecurityManager cleanup in java.prefs module

Reviewed-by: lancea, bpb, rriggs, iris
This commit is contained in:
Brent Christian 2024-11-26 01:17:37 +00:00
parent 1c7f34d3dd
commit 4d4cef800a
6 changed files with 181 additions and 344 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,8 +28,6 @@ package java.util.prefs;
import java.util.Objects; import java.util.Objects;
class MacOSXPreferences extends AbstractPreferences { class MacOSXPreferences extends AbstractPreferences {
// fixme need security checks?
// CF preferences file name for Java nodes with short names // CF preferences file name for Java nodes with short names
// This value is also in MacOSXPreferencesFile.c // This value is also in MacOSXPreferencesFile.c
private static final String defaultAppName = "com.apple.java.util.prefs"; private static final String defaultAppName = "com.apple.java.util.prefs";

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2011, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -82,15 +82,9 @@ class MacOSXPreferencesFile {
loadPrefsLib(); loadPrefsLib();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadPrefsLib() { private static void loadPrefsLib() {
java.security.AccessController.doPrivileged(
new java.security.PrivilegedAction<Void>() {
public Void run() {
System.loadLibrary("prefs"); System.loadLibrary("prefs");
return null;
}
});
} }
private static class FlushTask extends TimerTask { private static class FlushTask extends TimerTask {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,6 @@ package java.util.prefs;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
/** /**
* This class provides a skeletal implementation of the {@link Preferences} * This class provides a skeletal implementation of the {@link Preferences}
@ -1058,15 +1056,9 @@ public abstract class AbstractPreferences extends Preferences {
* preference tree, {@code false} if it's in the system * preference tree, {@code false} if it's in the system
* preference tree. * preference tree.
*/ */
@SuppressWarnings("removal")
public boolean isUserNode() { public boolean isUserNode() {
return AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
return root == Preferences.userRoot(); return root == Preferences.userRoot();
} }
}).booleanValue();
}
public void addPreferenceChangeListener(PreferenceChangeListener pcl) { public void addPreferenceChangeListener(PreferenceChangeListener pcl) {
if (pcl==null) if (pcl==null)

View File

@ -30,20 +30,10 @@ import jdk.internal.util.OperatingSystem;
import java.io.InputStream; import java.io.InputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream; import java.io.OutputStream;
import java.security.AccessController;
import java.security.Permission;
import java.security.PrivilegedAction;
import java.util.Iterator; import java.util.Iterator;
import java.util.ServiceLoader; import java.util.ServiceLoader;
import java.util.ServiceConfigurationError; import java.util.ServiceConfigurationError;
// These imports needed only as a workaround for a JavaDoc bug
import java.lang.RuntimePermission;
import java.lang.Integer;
import java.lang.Long;
import java.lang.Float;
import java.lang.Double;
/** /**
* A node in a hierarchical collection of preference data. This class * A node in a hierarchical collection of preference data. This class
* allows applications to store and retrieve user and system * allows applications to store and retrieve user and system
@ -227,19 +217,10 @@ public abstract class Preferences {
private static final PreferencesFactory factory = factory(); private static final PreferencesFactory factory = factory();
@SuppressWarnings("removal")
private static PreferencesFactory factory() { private static PreferencesFactory factory() {
// 1. Try user-specified system property // 1. Try user-specified system property
String factoryName = AccessController.doPrivileged( String factoryName = System.getProperty("java.util.prefs.PreferencesFactory");
new PrivilegedAction<String>() {
public String run() {
return System.getProperty(
"java.util.prefs.PreferencesFactory");}});
if (factoryName != null) { if (factoryName != null) {
// FIXME: This code should be run in a doPrivileged and
// not use the context classloader, to avoid being
// dependent on the invoking thread.
// Checking AllPermission also seems wrong.
try { try {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
Object result =Class.forName(factoryName, false, Object result =Class.forName(factoryName, false,
@ -250,10 +231,6 @@ public abstract class Preferences {
try { try {
// workaround for javaws, plugin, // workaround for javaws, plugin,
// load factory class using non-system classloader // load factory class using non-system classloader
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new java.security.AllPermission());
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
Object result = Class.forName(factoryName, false, Object result = Class.forName(factoryName, false,
Thread.currentThread() Thread.currentThread()
@ -267,14 +244,6 @@ public abstract class Preferences {
} }
} }
} }
return AccessController.doPrivileged(
new PrivilegedAction<PreferencesFactory>() {
public PreferencesFactory run() {
return factory1();}});
}
private static PreferencesFactory factory1() {
// 2. Try service provider interface // 2. Try service provider interface
Iterator<PreferencesFactory> itr = ServiceLoader Iterator<PreferencesFactory> itr = ServiceLoader
.load(PreferencesFactory.class, ClassLoader.getSystemClassLoader()) .load(PreferencesFactory.class, ClassLoader.getSystemClassLoader())
@ -427,24 +396,12 @@ public abstract class Preferences {
return "/" + packageName.replace('.', '/'); return "/" + packageName.replace('.', '/');
} }
/**
* This permission object represents the permission required to get
* access to the user or system root (which in turn allows for all
* other operations).
*/
private static Permission prefsPerm = new RuntimePermission("preferences");
/** /**
* Returns the root preference node for the calling user. * Returns the root preference node for the calling user.
* *
* @return the root preference node for the calling user. * @return the root preference node for the calling user.
*/ */
public static Preferences userRoot() { public static Preferences userRoot() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(prefsPerm);
return factory.userRoot(); return factory.userRoot();
} }
@ -454,11 +411,6 @@ public abstract class Preferences {
* @return the root preference node for the system. * @return the root preference node for the system.
*/ */
public static Preferences systemRoot() { public static Preferences systemRoot() {
@SuppressWarnings("removal")
SecurityManager security = System.getSecurityManager();
if (security != null)
security.checkPermission(prefsPerm);
return factory.systemRoot(); return factory.systemRoot();
} }

View File

@ -27,9 +27,6 @@ package java.util.prefs;
import java.util.*; import java.util.*;
import java.io.*; import java.io.*;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedExceptionAction;
import java.security.PrivilegedActionException; import java.security.PrivilegedActionException;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
@ -53,13 +50,9 @@ class FileSystemPreferences extends AbstractPreferences {
loadPrefsLib(); loadPrefsLib();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadPrefsLib() { private static void loadPrefsLib() {
PrivilegedAction<Void> load = () -> {
System.loadLibrary("prefs"); System.loadLibrary("prefs");
return null;
};
AccessController.doPrivileged(load);
} }
/** /**
@ -67,8 +60,7 @@ class FileSystemPreferences extends AbstractPreferences {
*/ */
@SuppressWarnings("removal") @SuppressWarnings("removal")
private static final int SYNC_INTERVAL = Math.max(1, private static final int SYNC_INTERVAL = Math.max(1,
AccessController.doPrivileged((PrivilegedAction<Integer>) () -> Integer.getInteger("java.util.prefs.syncInterval", 30));
Integer.getInteger("java.util.prefs.syncInterval", 30)));
/** /**
* Returns logger for error messages. Backing store exceptions are logged at * Returns logger for error messages. Backing store exceptions are logged at
@ -117,10 +109,7 @@ class FileSystemPreferences extends AbstractPreferences {
return root; return root;
} }
@SuppressWarnings("removal")
private static void setupUserRoot() { private static void setupUserRoot() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
userRootDir = userRootDir =
new File(System.getProperty("java.util.prefs.userRoot", new File(System.getProperty("java.util.prefs.userRoot",
System.getProperty("user.home")), ".java/.userPrefs"); System.getProperty("user.home")), ".java/.userPrefs");
@ -134,24 +123,24 @@ class FileSystemPreferences extends AbstractPreferences {
" on userRoot directory. "); " on userRoot directory. ");
} }
getLogger().info("Created user preferences directory."); getLogger().info("Created user preferences directory.");
} } else {
else
getLogger().warning("Couldn't create user preferences" + getLogger().warning("Couldn't create user preferences" +
" directory. User preferences are unusable."); " directory. User preferences are unusable.");
} }
}
isUserRootWritable = userRootDir.canWrite(); isUserRootWritable = userRootDir.canWrite();
String USER_NAME = System.getProperty("user.name"); String USER_NAME = System.getProperty("user.name");
userLockFile = new File (userRootDir,".user.lock." + USER_NAME); userLockFile = new File(userRootDir,".user.lock." + USER_NAME);
userRootModFile = new File (userRootDir, userRootModFile = new File (userRootDir,
".userRootModFile." + USER_NAME); ".userRootModFile." + USER_NAME);
if (!userRootModFile.exists()) if (!userRootModFile.exists()) {
try { try {
// create if does not exist. // create if does not exist.
userRootModFile.createNewFile(); userRootModFile.createNewFile();
// Only user can read/write userRootModFile. // Only user can read/write userRootModFile.
int result = chmod(userRootModFile.getCanonicalPath(), int result = chmod(userRootModFile.getCanonicalPath(),
USER_READ_WRITE); USER_READ_WRITE);
if (result !=0) if (result != 0)
getLogger().warning("Problem creating userRoot " + getLogger().warning("Problem creating userRoot " +
"mod file. Chmod failed on " + "mod file. Chmod failed on " +
userRootModFile.getCanonicalPath() + userRootModFile.getCanonicalPath() +
@ -159,10 +148,8 @@ class FileSystemPreferences extends AbstractPreferences {
} catch (IOException e) { } catch (IOException e) {
getLogger().warning(e.toString()); getLogger().warning(e.toString());
} }
userRootModTime = userRootModFile.lastModified();
return null;
} }
}); userRootModTime = userRootModFile.lastModified();
} }
@ -185,12 +172,9 @@ class FileSystemPreferences extends AbstractPreferences {
return root; return root;
} }
@SuppressWarnings("removal")
private static void setupSystemRoot() { private static void setupSystemRoot() {
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
String systemPrefsDirName = String systemPrefsDirName =
System.getProperty("java.util.prefs.systemRoot","/etc/.java"); System.getProperty("java.util.prefs.systemRoot", "/etc/.java");
systemRootDir = systemRootDir =
new File(systemPrefsDirName, ".systemPrefs"); new File(systemPrefsDirName, ".systemPrefs");
// Attempt to create root dir if it does not yet exist. // Attempt to create root dir if it does not yet exist.
@ -219,24 +203,23 @@ class FileSystemPreferences extends AbstractPreferences {
} }
isSystemRootWritable = systemRootDir.canWrite(); isSystemRootWritable = systemRootDir.canWrite();
systemLockFile = new File(systemRootDir, ".system.lock"); systemLockFile = new File(systemRootDir, ".system.lock");
systemRootModFile = systemRootModFile = new File (systemRootDir, ".systemRootModFile");
new File (systemRootDir,".systemRootModFile"); if (!systemRootModFile.exists() && isSystemRootWritable) {
if (!systemRootModFile.exists() && isSystemRootWritable)
try { try {
// create if does not exist. // create if does not exist.
systemRootModFile.createNewFile(); systemRootModFile.createNewFile();
int result = chmod(systemRootModFile.getCanonicalPath(), int result = chmod(systemRootModFile.getCanonicalPath(),
USER_RW_ALL_READ); USER_RW_ALL_READ);
if (result !=0) if (result != 0) {
getLogger().warning("Chmod failed on " + getLogger().warning("Chmod failed on " +
systemRootModFile.getCanonicalPath() + systemRootModFile.getCanonicalPath() +
" Unix error code " + result); " Unix error code " + result);
} catch (IOException e) { getLogger().warning(e.toString()); }
} catch (IOException e) {
getLogger().warning(e.toString());
}
} }
systemRootModTime = systemRootModFile.lastModified(); systemRootModTime = systemRootModFile.lastModified();
return null;
}
});
} }
@ -456,7 +439,6 @@ class FileSystemPreferences extends AbstractPreferences {
addShutdownHook(); addShutdownHook();
} }
@SuppressWarnings("removal")
private static void addShutdownHook() { private static void addShutdownHook() {
// Add periodic timer task to periodically sync cached prefs // Add periodic timer task to periodically sync cached prefs
syncTimer.schedule(new TimerTask() { syncTimer.schedule(new TimerTask() {
@ -466,8 +448,6 @@ class FileSystemPreferences extends AbstractPreferences {
}, SYNC_INTERVAL*1000, SYNC_INTERVAL*1000); }, SYNC_INTERVAL*1000, SYNC_INTERVAL*1000);
// Add shutdown hook to flush cached prefs on normal termination // Add shutdown hook to flush cached prefs on normal termination
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
Runtime.getRuntime().addShutdownHook( Runtime.getRuntime().addShutdownHook(
new Thread(null, null, "Sync Timer Thread", 0, false) { new Thread(null, null, "Sync Timer Thread", 0, false) {
public void run() { public void run() {
@ -475,9 +455,6 @@ class FileSystemPreferences extends AbstractPreferences {
syncWorld(); syncWorld();
} }
}); });
return null;
}
});
} }
private static void syncWorld() { private static void syncWorld() {
@ -526,19 +503,13 @@ class FileSystemPreferences extends AbstractPreferences {
* parent node and name. This constructor, called from childSpi, * parent node and name. This constructor, called from childSpi,
* is used to make every node except for the two //roots. * is used to make every node except for the two //roots.
*/ */
@SuppressWarnings("removal")
private FileSystemPreferences(FileSystemPreferences parent, String name) { private FileSystemPreferences(FileSystemPreferences parent, String name) {
super(parent, name); super(parent, name);
isUserNode = parent.isUserNode; isUserNode = parent.isUserNode;
dir = new File(parent.dir, dirName(name)); dir = new File(parent.dir, dirName(name));
prefsFile = new File(dir, "prefs.xml"); prefsFile = new File(dir, "prefs.xml");
tmpFile = new File(dir, "prefs.tmp"); tmpFile = new File(dir, "prefs.tmp");
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
newNode = !dir.exists(); newNode = !dir.exists();
return null;
}
});
if (newNode) { if (newNode) {
// These 2 things guarantee node will get written at next flush/sync // These 2 things guarantee node will get written at next flush/sync
prefsCache = new TreeMap<>(); prefsCache = new TreeMap<>();
@ -596,12 +567,7 @@ class FileSystemPreferences extends AbstractPreferences {
* fails, a BackingStoreException is thrown and both prefsCache and * fails, a BackingStoreException is thrown and both prefsCache and
* lastSyncTime are unaffected by the call. * lastSyncTime are unaffected by the call.
*/ */
@SuppressWarnings("removal")
private void loadCache() throws BackingStoreException { private void loadCache() throws BackingStoreException {
try {
AccessController.doPrivileged(
new PrivilegedExceptionAction<Void>() {
public Void run() throws BackingStoreException {
Map<String, String> m = new TreeMap<>(); Map<String, String> m = new TreeMap<>();
long newLastSyncTime = 0; long newLastSyncTime = 0;
try { try {
@ -627,12 +593,6 @@ class FileSystemPreferences extends AbstractPreferences {
// Attempt succeeded; update state // Attempt succeeded; update state
prefsCache = m; prefsCache = m;
lastSyncTime = newLastSyncTime; lastSyncTime = newLastSyncTime;
return null;
}
});
} catch (PrivilegedActionException e) {
throw (BackingStoreException) e.getException();
}
} }
/** /**
@ -644,12 +604,7 @@ class FileSystemPreferences extends AbstractPreferences {
* and lastSyncTime will be unaffected by this call. This call will * and lastSyncTime will be unaffected by this call. This call will
* NEVER leave prefsFile in a corrupt state. * NEVER leave prefsFile in a corrupt state.
*/ */
@SuppressWarnings("removal")
private void writeBackCache() throws BackingStoreException { private void writeBackCache() throws BackingStoreException {
try {
AccessController.doPrivileged(
new PrivilegedExceptionAction<Void>() {
public Void run() throws BackingStoreException {
try { try {
if (!dir.exists() && !dir.mkdirs()) if (!dir.exists() && !dir.mkdirs())
throw new BackingStoreException(dir + throw new BackingStoreException(dir +
@ -660,17 +615,11 @@ class FileSystemPreferences extends AbstractPreferences {
if (!tmpFile.renameTo(prefsFile)) if (!tmpFile.renameTo(prefsFile))
throw new BackingStoreException("Can't rename " + throw new BackingStoreException("Can't rename " +
tmpFile + " to " + prefsFile); tmpFile + " to " + prefsFile);
} catch(BackingStoreException e) {
throw e;
} catch(Exception e) { } catch(Exception e) {
if (e instanceof BackingStoreException)
throw (BackingStoreException)e;
throw new BackingStoreException(e); throw new BackingStoreException(e);
} }
return null;
}
});
} catch (PrivilegedActionException e) {
throw (BackingStoreException) e.getException();
}
} }
protected String[] keysSpi() { protected String[] keysSpi() {
@ -678,11 +627,7 @@ class FileSystemPreferences extends AbstractPreferences {
return prefsCache.keySet().toArray(new String[prefsCache.size()]); return prefsCache.keySet().toArray(new String[prefsCache.size()]);
} }
@SuppressWarnings("removal")
protected String[] childrenNamesSpi() { protected String[] childrenNamesSpi() {
return AccessController.doPrivileged(
new PrivilegedAction<String[]>() {
public String[] run() {
List<String> result = new ArrayList<>(); List<String> result = new ArrayList<>();
File[] dirContents = dir.listFiles(); File[] dirContents = dir.listFiles();
if (dirContents != null) { if (dirContents != null) {
@ -692,8 +637,6 @@ class FileSystemPreferences extends AbstractPreferences {
} }
return result.toArray(EMPTY_STRING_ARRAY); return result.toArray(EMPTY_STRING_ARRAY);
} }
});
}
private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final String[] EMPTY_STRING_ARRAY = new String[0];
@ -717,19 +660,14 @@ class FileSystemPreferences extends AbstractPreferences {
/** /**
* Called with file lock held (in addition to node locks). * Called with file lock held (in addition to node locks).
*/ */
@SuppressWarnings("removal")
protected void removeNodeSpi() throws BackingStoreException { protected void removeNodeSpi() throws BackingStoreException {
try {
AccessController.doPrivileged(
new PrivilegedExceptionAction<Void>() {
public Void run() throws BackingStoreException {
if (changeLog.contains(nodeCreate)) { if (changeLog.contains(nodeCreate)) {
changeLog.remove(nodeCreate); changeLog.remove(nodeCreate);
nodeCreate = null; nodeCreate = null;
return null; return;
} }
if (!dir.exists()) if (!dir.exists())
return null; return;
prefsFile.delete(); prefsFile.delete();
tmpFile.delete(); tmpFile.delete();
// dir should be empty now. If it's not, empty it // dir should be empty now. If it's not, empty it
@ -744,15 +682,8 @@ class FileSystemPreferences extends AbstractPreferences {
if (!dir.delete()) if (!dir.delete())
throw new BackingStoreException("Couldn't delete dir: " throw new BackingStoreException("Couldn't delete dir: "
+ dir); + dir);
return null;
}
});
} catch (PrivilegedActionException e) {
throw (BackingStoreException) e.getException();
}
} }
@SuppressWarnings("removal")
public synchronized void sync() throws BackingStoreException { public synchronized void sync() throws BackingStoreException {
boolean userNode = isUserNode(); boolean userNode = isUserNode();
boolean shared; boolean shared;
@ -765,12 +696,9 @@ class FileSystemPreferences extends AbstractPreferences {
shared = !isSystemRootWritable; shared = !isSystemRootWritable;
} }
synchronized (isUserNode()? userLockFile:systemLockFile) { synchronized (isUserNode()? userLockFile:systemLockFile) {
if (!lockFile(shared)) if (!lockFile(shared)) {
throw(new BackingStoreException("Couldn't get file lock.")); throw (new BackingStoreException("Couldn't get file lock."));
final Long newModTime = }
AccessController.doPrivileged(
new PrivilegedAction<Long>() {
public Long run() {
long nmt; long nmt;
if (isUserNode()) { if (isUserNode()) {
nmt = userRootModFile.lastModified(); nmt = userRootModFile.lastModified();
@ -779,44 +707,23 @@ class FileSystemPreferences extends AbstractPreferences {
nmt = systemRootModFile.lastModified(); nmt = systemRootModFile.lastModified();
isSystemRootModified = systemRootModTime == nmt; isSystemRootModified = systemRootModTime == nmt;
} }
return nmt; final long newModTime = nmt;
}
});
try { try {
super.sync(); super.sync();
AccessController.doPrivileged(new PrivilegedAction<Void>() {
public Void run() {
if (isUserNode()) { if (isUserNode()) {
userRootModTime = newModTime.longValue() + 1000; userRootModTime = newModTime + 1000;
userRootModFile.setLastModified(userRootModTime); userRootModFile.setLastModified(userRootModTime);
} else { } else {
systemRootModTime = newModTime.longValue() + 1000; systemRootModTime = newModTime + 1000;
systemRootModFile.setLastModified(systemRootModTime); systemRootModFile.setLastModified(systemRootModTime);
} }
return null;
}
});
} finally { } finally {
unlockFile(); unlockFile();
} }
} }
} }
@SuppressWarnings("removal")
protected void syncSpi() throws BackingStoreException { protected void syncSpi() throws BackingStoreException {
try {
AccessController.doPrivileged(
new PrivilegedExceptionAction<Void>() {
public Void run() throws BackingStoreException {
syncSpiPrivileged();
return null;
}
});
} catch (PrivilegedActionException e) {
throw (BackingStoreException) e.getException();
}
}
private void syncSpiPrivileged() throws BackingStoreException {
if (isRemoved()) if (isRemoved())
throw new IllegalStateException("Node has been removed"); throw new IllegalStateException("Node has been removed");
if (prefsCache == null) if (prefsCache == null)

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,6 @@ package java.util.prefs;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.util.logging.PlatformLogger; import sun.util.logging.PlatformLogger;
@ -50,13 +48,9 @@ class WindowsPreferences extends AbstractPreferences {
loadPrefsLib(); loadPrefsLib();
} }
@SuppressWarnings({"removal", "restricted"}) @SuppressWarnings("restricted")
private static void loadPrefsLib() { private static void loadPrefsLib() {
PrivilegedAction<Void> load = () -> {
System.loadLibrary("prefs"); System.loadLibrary("prefs");
return null;
};
AccessController.doPrivileged(load);
} }
/** /**