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.

Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • 3
    This is due to a bug: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6790382 – Kristof Neirynck Oct 28 '15 at 10:44
  • 1
    Preferences saved in a file as the [backing store](http://www.davidc.net/programming/java/java-preferences-using-file-backing-store) should avoid the issue entirely. There are situations where relying on end-users to change their [abominable registry](https://blog.codinghorror.com/was-the-windows-registry-a-good-idea/) is not a viable solution. – Dave Jarvis Dec 23 '16 at 02:36
  • 2
    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. – david.pfx Jan 03 '18 at 01:13

9 Answers9

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]
Robert Mark Bram
  • 8,104
  • 8
  • 52
  • 73
MKorsch
  • 3,822
  • 3
  • 16
  • 21
  • 8
    Is it possible to do this progmatically? – facetoe Oct 15 '13 at 06:20
  • 1
    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. – Raku Dec 04 '14 at 12:35
  • 13
    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? – avgvstvs Dec 23 '14 at 18:41
  • Well i can answer that one: java.util.prefs.Preferences default implementation on Windows saves User Preferences AND System Preferences to the Windows Registry – keuleJ Jan 02 '15 at 17:50
  • The steps 1-4 doesn't work for me. But running the reg file works. – Aiden Zhao Oct 02 '15 at 13:48
  • 5
    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. – El Mac Apr 06 '16 at 11:27
  • 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." – Alexo Po. May 25 '16 at 11:41
  • 16
    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\JavaSoft – gt124 Aug 13 '16 at 19:33
  • 2
    On Windows 10 still the right location for the Perfs folder is `HKEY_LOCAL_MACHINE\Software\JavaSoft` – Arthur Oct 10 '16 at 03:45
  • 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. – Jeff Lockhart Mar 09 '17 at 00:50
  • 2
    Just run the failing app once as Administrator, it will create the missing key automatically. No need to mess with the registry. – rustyx Mar 31 '17 at 19:27
  • This is not a solution because these things should be done programmatically rather than manually. – Eugene Kartoyev Jul 07 '18 at 18:00
75

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

HKEY_LOCAL_MACHINE\Software\JavaSoft\Prefs
Dennis Traub
  • 50,557
  • 7
  • 93
  • 108
  • 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. – moomoohk Jun 16 '13 at 01:24
  • 14
    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). – Brian Knoblauch Nov 27 '13 at 18:23
  • Error happens in Windows 10 as well, and this fix worked – TriumphST May 11 '16 at 21:07
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.

peterh
  • 18,404
  • 12
  • 87
  • 115
  • Thanks for such a deep analysis. [Issue 8139507](https://bugs.openjdk.java.net/browse/JDK-8139507), that you mentioned, says the bug is fixed in JDK 9. – realsonic Sep 28 '18 at 16:27
  • 3
    @realsonic. Adding to that: It seems Oracle finally got around to backporting this fix. It is [fixed in 8u202](https://bugs.openjdk.java.net/browse/JDK-8210913). (as of 30Sep2018 the latest release of Java 8 is u181 so the fix is backported but not yet in any released version) – peterh Sep 30 '18 at 09:06
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
Jawa
  • 2,336
  • 6
  • 34
  • 39
walkern
  • 337
  • 3
  • 2
  • 9
    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. – Scott Johnson Apr 15 '14 at 19:03
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.

Alexander Nozik
  • 440
  • 6
  • 11
  • 2
    Thanks, I would suggest others to try this, its the simplest solution :) – Aditya T Sep 08 '17 at 01:56
  • 1
    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. – K. B. Mar 01 '18 at 16:14
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.

razvanone
  • 1,351
  • 18
  • 27
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
Sohail Ahmed
  • 1,047
  • 1
  • 11
  • 27
1

This happened to me.

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

See: Java: java.util.Preferences Failing

Community
  • 1
  • 1
Wolsie
  • 144
  • 1
  • 13
  • Well, more precisely it is because there's a bug in the JDK. See the accepted answer on the link in your answer. – peterh Mar 05 '17 at 07:54
  • 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). – ddimitrov Nov 08 '19 at 04:55
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.

Alessandro Roaro
  • 4,665
  • 6
  • 29
  • 48