Skip to content

registryValueExists() throws exception if key does not exist #1036

@jansohn

Description

@jansohn

Checking the existence of a registry value throws an exception if the key does not exist:

Advapi32Util.registryValueExists(WinReg.HKEY_CURRENT_USER, "FAIL", "Path");

Stack trace:

com.sun.jna.platform.win32.Win32Exception: The handle is invalid.
	at com.sun.jna.platform.win32.Advapi32Util.registryValueExists(Advapi32Util.java:661)
	at com.sun.jna.platform.win32.Advapi32Util.registryValueExists(Advapi32Util.java:612)

I expected it to simply return false, especially as the exception occurs in the finally block when cleaning up. Can be worked around by first checking the existence of the registry key.

  • JNA 5.1.0
  • Oracle JDK 1.8.0_181 (64bit)
  • Windows 10 / Windows Server 2016 (64bit)

PS: I don't have a Google account and I don't want to create one. As there are no alternative ways to participate in the mailing list I directly created the issue here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions