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

Alan Bateman Alan.Bateman at oracle.com
Fri Jun 10 10:20:53 UTC 2016


On 08/06/2016 18:39, Jan Lahoda wrote:

> Hello,
>
> When starting JShell on Windows, one may see a message like this:
>
> ?vn 08, 2016 6:46:35 ODP. java.util.prefs.WindowsPreferences <init>
> WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs 
> at root 0 x80000002. Windows RegCreateKeyEx(...) returned error code 5.
>
> The problem, as far as I can understand, is that when the JShell tool 
> asks for the user Preferences (Preferences.userRoot()), not only the 
> user preferences get created, but also the system preferences get 
> created. And when the given (system) root node cannot be created (e.g. 
> due to permissions), the above warning is printed.
>
> As JShell does not need system Preferences, I don't think this warning 
> does not make much sense in the JShell context. My proposal is to 
> create both the user and system Preferences lazily on Windows, so 
> applications that only need user Preferences don't trigger the 
> warning. As far as I can tell, this is consistent with what the 
> FileSystemPreferences do:
> http://hg.openjdk.java.net/jdk9/dev/jdk/file/7f5b7acebffd/src/java.prefs/unix/classes/java/util/prefs/FileSystemPreferences.java#l160 
>
>
> Bugs:
> https://bugs.openjdk.java.net/browse/JDK-8139507
> https://bugs.openjdk.java.net/browse/JDK-8158292
>
> Webrev:
> http://cr.openjdk.java.net/~jlahoda/8139507/webrev.00/
>
> Not sure if there's a way to write a test for the behavior, I didn't 
> see an obvious way. Any suggestions on testing would be welcome!
>
I don't know if the prefs APIs is used much but I assume it would be 
better to not synchronized on the class and instead do something like:

     static volatile Preferences userRoot;

     static Preferences getUserRoot() {
         Preferences root = userRoot;
         if (root == null) {
             synchronized (Preferences.class) {
                 root = userRoot;
                 if (root == null) {
                     userRoot = root = new 
WindowsPreferences(USER_ROOT_NATIVE_HANDLE,
WINDOWS_ROOT_PATH);
                 }
             }
         }
         return root;
     }

I'm not sure that a test is possible for the scenario as it would be too 
fragile/dependent on whether the user running the test has privileges or 
not.

-Alan


More information about the core-libs-dev mailing list