Groovy Shell warning "Could not open/create prefs root node ..."
Asked Answered
M

9

195

I tried to open the Groovy Shell (groovysh) on Windows 8 and got the following output:

java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs 
at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

After printing the above message the shell started as expected.

Metaprotein answered 7/5, 2013 at 20:35 Comment(3)
This is due to a bug: bugs.java.com/bugdatabase/view_bug.do?bug_id=6790382Racklin
Preferences saved in a file as the backing store should avoid the issue entirely. There are situations where relying on end-users to change their abominable registry is not a viable solution.Rapt
It's a known Java bug still around on WIndows 10 and update 112. Just run the program once from an elevated prompt and it goes away.Stewartstewed
H
336

Dennis answer is correct. However I would like to explain the solution in a bit more detailed way (for Windows User):

  1. Go into your Start Menu and type regedit into the search field.
  2. Navigate to path HKEY_LOCAL_MACHINE\Software\JavaSoft (Windows 10 seems to now have this here: HKEY_LOCAL_MACHINE\Software\WOW6432Node\JavaSoft)
  3. Right click on the JavaSoft folder and click on New -> Key
  4. Name the new Key Prefs and everything should work.

Alternatively, save and execute a *.reg file with the following content:

Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs]
Hirokohiroshi answered 9/7, 2013 at 15:58 Comment(12)
Is it possible to do this progmatically?Falsecard
Probably not easily, because it requires administrator privileges, at least in enterprise environments with an Active Directory domain set up. Reading the preferences from HKEY_CURRENT_USER instead of HKEY_LOCAL_MACHINE might work though.Foremast
I can confirm it won't work if done under HKEY_CURRENT_USER. A better question, why on earth is a Java-based product tying itself to the Windows Registry?Anjanetteanjela
Well i can answer that one: java.util.prefs.Preferences default implementation on Windows saves User Preferences AND System Preferences to the Windows RegistryFlavour
The steps 1-4 doesn't work for me. But running the reg file works.Cardholder
It's not possible for a consumer application to require the user to go and fiddle with the registry. Why does Java always implement half-solutions like this.Bogeyman
Moreover, sometimes just creating of registry key is not enough, because Java applications are run with restricted permissions to registry (at least it possible in Windows8). So I've found this: "Go to key HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs. Right click to set permissions. Check a mark in the Full Control check box for the user(s) that need executing your application."Wilke
My Windows 10 install has both key paths indicated above, fixing my installation required adding the Prefs to the HKEY_LOCAL_MACHINE\Software\JavaSoft not the HKEY_LOCAL_MACHINE\Software\WOW6432Node\JavaSoftHetaerism
On Windows 10 still the right location for the Perfs folder is HKEY_LOCAL_MACHINE\Software\JavaSoftCist
WOW6432Node is for 32-bit programs (in this case Java) on 64-bit Windows, not dependent on Windows 10. The other path is for 32-bit Windows or 64-bit programs on 64-bit Windows.Lagan
Just run the failing app once as Administrator, it will create the missing key automatically. No need to mess with the registry.Durra
This is not a solution because these things should be done programmatically rather than manually.Histogram
M
75

I was able to resolve the problem by manually creating the following registry key:

HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs
Metaprotein answered 7/5, 2013 at 20:35 Comment(3)
Would you mind telling me the exact process? I work mainly on Mac but I'm getting this error when I run my program on Windows and I'd like to know how to fix it.Pavlov
I'm seeing this on software that we sell. An automatic/programmatic fix would be better if you've got one of those too. Telling my end users to jump into regedit is a scary prospect. Is there a way to get Java to do this automagically on Windows 8.1 (which is the only platform I see the error on).Garret
Error happens in Windows 10 as well, and this fix workedNibbs
D
49

This is actually a JDK bug. It has been reported several times over the years, but only in 8139507 was it finally taken seriously by Oracle.

The problem was in the JDK source code for WindowsPreferences.java. In this class, both nodes userRoot and systemRoot were declared static as in:

/**
 * User root node.
 */
static final Preferences userRoot =
     new WindowsPreferences(USER_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);

/**
 * System root node.
 */
static final Preferences systemRoot =
    new WindowsPreferences(SYSTEM_ROOT_NATIVE_HANDLE, WINDOWS_ROOT_PATH);

This means that the first time the class is referenced both static variables would be initiated and by this the Registry Key for HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs (= system tree) will be attempted to be created if it doesn't already exist.

So even if the user took every precaution in his own code and never touched or referenced the system tree, then the JVM would actually still try to instantiate systemRoot, thus causing the warning. It is an interesting subtle bug.

There's a fix committed to the JDK source in June 2016 and it is part of Java9 onwards. There's also a backport for Java8 which is in u202.

What you see is really a warning from the JDK's internal logger. It is not an exception. I believe that the warning can be safely ignored .... unless the user code is indeed wanting the system preferences, but that is very rarely the case.

Bonus info

The bug did not reveal itself in versions prior to Java 1.7.21, because up until then the JRE installer would create Registry key HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs for you and this would effectively hide the bug. On the other hand you've never really been required to run an installer in order to have a JRE on your machine, or at least this hasn't been Sun/Oracle's intent. As you may be aware Oracle has been distributing the JRE for Windows in .tar.gz format for many years.

Dermot answered 14/12, 2016 at 19:51 Comment(2)
Thanks for such a deep analysis. Issue 8139507, that you mentioned, says the bug is fixed in JDK 9.Adjure
@realsonic. Adding to that: It seems Oracle finally got around to backporting this fix. It is fixed in 8u202. (as of 30Sep2018 the latest release of Java 8 is u181 so the fix is backported but not yet in any released version)Dermot
O
32

If anyone is trying to solve this on a 64-bit version of Windows, you might need to create the following key:

HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Prefs
Obligate answered 27/12, 2013 at 9:28 Comment(1)
I got this error while using a 64-bit JVM on 64-bit Windows 7, and the solution that Dennis and MKorsch proposed worked just fine for me. Perhaps the Wow6432Node solution is for 32-bit JVMs on 64-bit Windows.Acrophobia
A
8

The problem is that simple console can't edit the registry. No need to edit the registry by hand, just launch the groovysh once with administrative priveleges. All subsequent launches work without error.

Ankylose answered 4/9, 2016 at 11:49 Comment(2)
Thanks, I would suggest others to try this, its the simplest solution :)Redhot
The easiest answer, should be on top.I had this warning executing JMeter tests, but I started once the jmeter.bat as Administrator and the warning is gone.Georama
T
2

Had a similar problem when starting apache jmeter on windows 8 64 bit:

[]apache-jmeter-2.13\bin>jmeter
java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs     at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.

Successfully used Dennis Traub solution, with Mkorsch explanations. Or you can create a file with the extension "reg" and write into it the following:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Prefs]

... then execute it.

Talipes answered 11/5, 2015 at 12:3 Comment(0)
C
1

I was getting the following message:

Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002

and it was gone after creating one of these registry keys, mine is 64 bit so I tried only that.

32 bit Windows
HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs

64 bit Windows
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\JavaSoft\Prefs
Cannot answered 18/6, 2016 at 12:14 Comment(0)
S
1

This happened to me.

Apparently it is because Java does not have permission to create registry keys.

See: Java: java.util.Preferences Failing

Saratov answered 25/10, 2016 at 7:47 Comment(2)
Well, more precisely it is because there's a bug in the JDK. See the accepted answer on the link in your answer.Dermot
It is not really a bug - machine-wide settings are only permitted to machine admin users. Use runas to run your application as local admin user and it will happily create the registry key under HKLM. What Java does not have is a mechanism to ask for elevated permisisons (i.e. ideally it would have invoked Windows UAC instead of failing - it is questionable whether that is universally good idea).Cyclopedia
C
0

The problem is indeed the register key that is missing. It can be created manually

OR

it can be created automagically by running the program as administrator once. That will give the program the permissions required, and when it will be ran as normal it will still work correctly.

Compeer answered 7/11, 2019 at 10:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.