提交 ca251265 编写于 作者: J jlahoda

8139507: WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs

Summary: Making Preferences.systemRoot/userRoot lazy on Windows, to avoid warnings for system root when only user root was requested; reducing synchronization while creating the Preferences.
Reviewed-by: alanb
上级 edf68627
/*
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2011, 2018, 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
......@@ -47,27 +47,39 @@ class MacOSXPreferences extends AbstractPreferences {
private final String path;
// User root and system root nodes
private static MacOSXPreferences userRoot = null;
private static MacOSXPreferences systemRoot = null;
private static volatile MacOSXPreferences userRoot;
private static volatile MacOSXPreferences systemRoot;
// Returns user root node, creating it if necessary.
// Called by MacOSXPreferencesFactory
static synchronized Preferences getUserRoot() {
if (userRoot == null) {
userRoot = new MacOSXPreferences(true);
static Preferences getUserRoot() {
MacOSXPreferences root = userRoot;
if (root == null) {
synchronized (MacOSXPreferences.class) {
root = userRoot;
if (root == null) {
userRoot = root = new MacOSXPreferences(true);
}
}
}
return userRoot;
return root;
}
// Returns system root node, creating it if necessary.
// Called by MacOSXPreferencesFactory
static synchronized Preferences getSystemRoot() {
if (systemRoot == null) {
systemRoot = new MacOSXPreferences(false);
static Preferences getSystemRoot() {
MacOSXPreferences root = systemRoot;
if (root == null) {
synchronized (MacOSXPreferences.class) {
root = systemRoot;
if (root == null) {
systemRoot = root = new MacOSXPreferences(false);
}
}
}
return systemRoot;
return root;
}
......
/*
* Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
......@@ -88,14 +88,20 @@ class FileSystemPreferences extends AbstractPreferences {
/**
* The user root.
*/
static Preferences userRoot = null;
private static volatile Preferences userRoot;
static synchronized Preferences getUserRoot() {
if (userRoot == null) {
setupUserRoot();
userRoot = new FileSystemPreferences(true);
static Preferences getUserRoot() {
Preferences root = userRoot;
if (root == null) {
synchronized (FileSystemPreferences.class) {
root = userRoot;
if (root == null) {
setupUserRoot();
userRoot = root = new FileSystemPreferences(true);
}
}
}
return userRoot;
return root;
}
private static void setupUserRoot() {
......@@ -149,14 +155,20 @@ class FileSystemPreferences extends AbstractPreferences {
/**
* The system root.
*/
static Preferences systemRoot;
private static volatile Preferences systemRoot;
static synchronized Preferences getSystemRoot() {
if (systemRoot == null) {
setupSystemRoot();
systemRoot = new FileSystemPreferences(false);
static Preferences getSystemRoot() {
Preferences root = systemRoot;
if (root == null) {
synchronized (FileSystemPreferences.class) {
root = systemRoot;
if (root == null) {
setupSystemRoot();
systemRoot = root = new FileSystemPreferences(false);
}
}
}
return systemRoot;
return root;
}
private static void setupSystemRoot() {
......
/*
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
......@@ -82,14 +82,40 @@ class WindowsPreferences extends AbstractPreferences{
/**
* User root node.
*/
static final Preferences userRoot =
new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
private static volatile Preferences userRoot;
static Preferences getUserRoot() {
Preferences root = userRoot;
if (root == null) {
synchronized (WindowsPreferences.class) {
root = userRoot;
if (root == null) {
root = new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
userRoot = root;
}
}
}
return root;
}
/**
* System root node.
*/
static final Preferences systemRoot =
new WindowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
private static volatile Preferences systemRoot;
static Preferences getSystemRoot() {
Preferences root = systemRoot;
if (root == null) {
synchronized (WindowsPreferences.class) {
root = systemRoot;
if (root == null) {
root = new WindowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);
systemRoot = root;
}
}
}
return root;
}
/* Windows error codes. */
private static final int ERROR_SUCCESS = 0;
......
/*
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2000, 2018, 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
......@@ -39,13 +39,13 @@ class WindowsPreferencesFactory implements PreferencesFactory {
* Returns WindowsPreferences.userRoot
*/
public Preferences userRoot() {
return WindowsPreferences.userRoot;
return WindowsPreferences.getUserRoot();
}
/**
* Returns WindowsPreferences.systemRoot
*/
public Preferences systemRoot() {
return WindowsPreferences.systemRoot;
return WindowsPreferences.getSystemRoot();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册