Issue
Existing code is working perfectly fine with JDK11 installed. Same lines of code is throwing below error in JDK16
java.lang.reflect.InaccessibleObjectException: Unable to make private static native long[] java.util.prefs.WindowsPreferences.WindowsRegOpenKey(long,byte[],int) accessible: module java.prefs does not "opens java.util.prefs" to unnamed module @3f803fae
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:357)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
When code is migrated from Java8 to Java9, WinRegistry.java file is modified with some of the methods' input parameter(s) type from int to long
Solution
Reading/Writing from/to Windows Registry is much simpler with Advapi32Util.java
With this JNA APIs one can easily read the Registry Keys, Values and also can set Registry with new key and value.
I used following APIs to fetch Registry value of a key with path to the registry key as below
Advapi32Util.registryGetStringValue(WinReg.HKEY_LOCAL_MACHINE, registry_path, value_of)
Also, the children key(s) under specific path can be fetched from below API
Advapi32Util.registryGetKeys(HKEY root, String keyPath)
Answered By - Sangamesh_V