Skip to content

Commit

Permalink
Checking the existence of a registry value throws an exception if the…
Browse files Browse the repository at this point in the history
… key does not exist
  • Loading branch information
matthiasblaesing committed Nov 16, 2018
1 parent 5f6fbe5 commit 15d6208
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Features

Bug Fixes
---------
* [#1036](https://github.com/java-native-access/jna/issues/1036): `Advapi32Util.registryValueExists` called on non existig key raises exception instead of returning `false` - [@matthiasblaesing](https://github.com/matthiasblaesing).

This comment has been minimized.

Copy link
@dblock

dblock Nov 18, 2018

Member

typo: existing

This comment has been minimized.

Copy link
@matthiasblaesing

matthiasblaesing Nov 19, 2018

Author Member

fixed


Release 5.1.0
=============
Expand Down
19 changes: 9 additions & 10 deletions contrib/platform/src/com/sun/jna/platform/win32/Advapi32Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,7 @@ public static boolean registryKeyExists(HKEY root, String key, int samDesiredExt
* Value name.
* @return True if the value exists.
*/
public static boolean registryValueExists(HKEY root, String key,
String value) {
public static boolean registryValueExists(HKEY root, String key, String value) {
return registryValueExists(root, key, value, 0);
}

Expand All @@ -631,15 +630,15 @@ public static boolean registryValueExists(HKEY root, String key,
HKEYByReference phkKey = new HKEYByReference();
int rc = Advapi32.INSTANCE.RegOpenKeyEx(root, key, 0, WinNT.KEY_READ | samDesiredExtra,
phkKey);
switch (rc) {
case W32Errors.ERROR_SUCCESS:
break;
case W32Errors.ERROR_FILE_NOT_FOUND:
return false;
default:
throw new Win32Exception(rc);
}
try {
switch (rc) {
case W32Errors.ERROR_SUCCESS:
break;
case W32Errors.ERROR_FILE_NOT_FOUND:
return false;
default:
throw new Win32Exception(rc);
}
IntByReference lpcbData = new IntByReference();
IntByReference lpType = new IntByReference();
rc = Advapi32.INSTANCE.RegQueryValueEx(phkKey.getValue(), value, 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ public void testRegistryValueExists() {
"Software\\Microsoft", "KeyDoesNotExist"));
assertTrue(Advapi32Util.registryValueExists(WinReg.HKEY_LOCAL_MACHINE,
"SYSTEM\\CurrentControlSet\\Control", "SystemBootDevice"));
assertFalse(Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "FAIL", "Path"));
}

public void testRegistryValueExistsSamExtra() {
Expand Down

0 comments on commit 15d6208

Please # to comment.