(prefs) Inconsistent Preferences storage between 32- and 64-bit Java runtimes

XMLWordPrintable

    • x86
    • windows_7

      FULL PRODUCT VERSION :
      C:\Users\Jim>java -version
      java version "1.6.0_29"
      Java(TM) SE Runtime Environment (build 1.6.0_29-b11)
      Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 6.1, Java SE 6 Update 29

      A DESCRIPTION OF THE PROBLEM :
      If both 32-bit and 64-bit Java programs are installed on a Windows 7 64-bit system, the Preferences API uses two different locations to store preferences values:

      Under the 64-bit JVM:
      HKEY_LOCAL_MACHINE\Software\Javasoft\Prefs
      Under the 32-bit JVM:
      HKEY_LOCAL_MACHINE\Software\Wow6432Node\Javasoft\Prefs
      This means that programs running under the 32-bit Nebeans IDE behave differently than programs running in the default 64-bit environment outside the IDE.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      On 64-bit Win 7, with 64-bit Java installed...
      1) Create a program that writes a system Preferences value.
      2) Create a command prompt window with admin privs
      3) From command window, invoke java program created in step 1 above to set preferences value
      4) Create program to read preference value.
      5) Run program from a non-privileged command line, it will successfully retrieve value set in step #3
      6) Run program from step #4 from within Netbeans IDE. It will fail to read the value from step #3.



      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I would expect the Preferences API to work consistently over both 32-bit and 64-bit Java.
      ACTUAL -
      Prefrences set with the 32-bit JVM can only be read by applications running with the 32-bit JVM. Values set with the 64-bit JVM can only be read by the 64-bit JVM.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Logged by Netbeans IDE in response by attempt to read preference value that was set by external program running as admin:

      WARNING: Could not create windows registry node Software\JavaSoft\Prefs\prefsexample at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
      Jan 16, 2012 4:40:10 PM java.util.prefs.WindowsPreferences WindowsRegOpenKey1
      WARNING: Trying to recreate Windows registry node Software\JavaSoft\Prefs\prefsexample at root 0x80000002.
      Jan 16, 2012 4:40:10 PM java.util.prefs.WindowsPreferences openKey
      WARNING: Could not open windows registry node Software\JavaSoft\Prefs\prefsexample at root 0x80000002. Windows RegOpenKey(...) returned error code 2.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------

      public class MyPreferences {
           Preferences prefs = Preferences.systemNodeForPackage (getClass ());
             
           void putValue(String key, String val) {
               prefs.put(key, val);
           }
           String getValue(String key) {
               String result = prefs.get(key, null);
               return result;
           }
      }
      public class PrefReader {

          /**
           * @param args the command line arguments
           */
          public static void main(String[] args) {
              MyPreferences myPrefs = new MyPreferences();
              String resultString = myPrefs.getValue("TEST");
              System.out.println("The result is: "+resultString);
          }
      }

      public class PrefWriter {

          public static void main(String[] args) {
              // TODO code application logic here
              MyPreferences myPrefs = new MyPreferences();
              myPrefs.putValue("TEST", "This is a test");
              System.out.println("TEST is now updated.");
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Invoke the netbeans IDE with admin privs, and run the set value programs from within the IDE to create a duplicate set of preferences values (or change the path to use 32-bit JVM).

        1. PrefWriter.java
          0.3 kB
        2. PrefWriter.java
          0.3 kB
        3. PrefReader.java
          0.3 kB
        4. PrefReader.java
          0.3 kB
        5. MyPreferences.java
          0.3 kB
        6. MyPreferences.java
          0.3 kB

            Assignee:
            Brian Burkhalter
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: