JDK-6572807 : (prefs) Vista virtualization breaks system node functionality for Preferences
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.util
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2007-06-22
  • Updated: 2011-02-16
  • Resolved: 2008-04-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description
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.