Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6572807

(prefs) Vista virtualization breaks system node functionality for Preferences

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • 7
    • 6
    • core-libs
    • x86
    • windows_vista

      FULL PRODUCT VERSION :
      java version "1.6.0_01"
      Java(TM) SE Runtime Environment (build 1.6.0_01-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.0.6000]

      Windows Vista Home Premium


      A DESCRIPTION OF THE PROBLEM :
      A Preferences node obtained via java.util.prefs.Preferences.systemNodeForPackage() on Windows Vista does not save data as expected. It either writes to a user-specific location or fails entirely with a BackingStoreException, depending on how Java was launched. If Java was launched from the command line or by double clicking a Jar, the system node actually writes to a user-specific location, thanks to Vista's compatibility virtualization. If Java was launched using an EXE launcher which includes a Vista manifest that specifies a "requestedExecutionLevel", Vista turns off virtualization and attempting to use the system node causes a BackingStoreException. In both cases the preferences are not saved in a way that can be shared by multiple users.

      I discovered this problem when attempting to build an installation package and EXE launcher for my Java application using Advanced Installer. There is additional information from the Advanced Installer support team at:

      http://www.advancedinstaller.com/forums/viewtopic.php?t=2660


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1) Compile the attached code and create an executable Jar.

      2) Double click the Jar.

      3) Open the "regedit" program.

      4) Search for "com.pensamos" to locate the saved preferences. Note that the registry keys are all user-specific and contain "VirtualStore" in the path indicating that they have been virtualized.

      ... optional ...

      5) Build an EXE launcher which includes a Vista manifest that specifies "requestedExecutionLevel". This can be done easily with Advanced Installer. See http://www.advancedinstaller.com/forums/viewtopic.php?t=2660

      6) Double click the EXE launcher. Note the BackingStoreException.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      No exceptions are shown and values are stored in a registry path that can be shared by all users (e.g., not containing "VirtualStore").

      ACTUAL -
      Registry data is either stored in a user-specific location or not stored at all.


      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      java.util.prefs.BackingStoreException: flush(): Backing store not available.
      at java.util.prefs.WindowsPreferences.flush(Unknown Source)
      at SetDummyPref.main(SetDummyPref.java:16)


      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      ======= SetDummyPref.java =======

      import java.io.*;
      import java.util.prefs.*;
      import javax.swing.*;

      public class SetDummyPref {

          public static void main (String[] arg) {
              String message;

              // attempt to set a preference

              try {
                  String path = "/com.pensamos/dummyPref";
                  final Preferences prefs = Preferences.systemRoot().node(path);
                  prefs.putLong("dummyKey", System.currentTimeMillis());
                  prefs.flush();
                  message = "Success!";
              }

              // extract stack trace from exception
              
              catch (Exception e) {
                  StringWriter sw = new StringWriter();
                  e.printStackTrace(new PrintWriter(sw));
                  message = sw.toString();
              }
              
              // print the result;
              
              message = System.getProperty("java.runtime.version") + "\n\n" + message;
              JTextArea ta = new JTextArea(message);
              JScrollPane sp = new JScrollPane(ta);
              JFrame f = new JFrame();
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              f.getContentPane().add(sp);
              f.pack();
              f.setVisible(true);
              f.toFront();
          }

      }


      ======= SetDummyPref.mf =======

      Manifest-Version: Version 1.0
      Main-Class: SetDummyPref

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use the file system for shared preferences instead of Java Preferences API.

            sherman Xueming Shen
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: