BullyWiiPlaza BullyWiiPlaza - 3 months ago 16
Java Question

Suppressing Java Preferences Systemroot Warning

How do I suppress the warning printed to the console by the following piece of code:

Preferences systemRoot = Preferences.systemRoot();


The warning is as follows (or similar):

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


Note:

I want to just ignore this warning by not printing anything to the console instead and not manually create a registry key or running the application as administrator.

Here is the method responsible for the warning:

private WindowsPreferences(int rootNativeHandle, byte[] rootDirectory) {
super(null, "");
int[] result =
WindowsRegCreateKeyEx1(rootNativeHandle, rootDirectory);
if (result[ERROR_CODE] != ERROR_SUCCESS) {
logger().warning("Could not open/create prefs root node " +
byteArrayToString(windowsAbsolutePath()) +
" at root 0x" + Integer.toHexString(rootNativeHandle()) +
". Windows RegCreateKeyEx(...) returned error code " +
result[ERROR_CODE] + ".");
isBackingStoreAvailable = false;
return;
}
// Check if a new node
newNode = (result[DISPOSITION] == REG_CREATED_NEW_KEY);
closeKey(result[NATIVE_HANDLE]);
}

Answer

I got it :)

PlatformLogger platformLogger = PlatformLogger.getLogger("java.util.prefs");
platformLogger.setLevel(PlatformLogger.Level.OFF);

Alternatively this.

Comments