Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Features

Bug Fixes
---------
* [#1700](https://github.com/java-native-access/jna/issues/1700): Windows: treat `ERROR_INVALID_PARAMETER` from `OpenProcess` in `c.s.j.p.WindowUtils#getProcessFilePath` like `ERROR_ACCESS_DENIED` to avoid spurious `Win32Exception` when enumerating windows whose processes have exited or are otherwise inaccessible - [marktech0813](https://github.com/marktech0813).


Release 5.18.1
Expand Down Expand Up @@ -1465,4 +1466,4 @@ Bug Fixes
* Ensure native libraries are only loaded once until released
* Properly handle NULL when the return value is a Structure
* Proper conversion to wchar_t on linux
* Copy full length of Java strings to C strings instead of stopping when a NUL character is encountered
* Copy full length of Java strings to C strings instead of stopping when a NUL character is encountered
33 changes: 18 additions & 15 deletions contrib/platform/src/com/sun/jna/platform/WindowUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1298,22 +1298,25 @@ public String getProcessFilePath(final HWND hwnd) {
pid.getValue());

if (process == null) {
if(Kernel32.INSTANCE.GetLastError() != WinNT.ERROR_ACCESS_DENIED) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
} else {
process = Kernel32.INSTANCE.OpenProcess(
WinNT.PROCESS_QUERY_LIMITED_INFORMATION,
false,
pid.getValue());

if (process == null) {
if (Kernel32.INSTANCE.GetLastError() != WinNT.ERROR_ACCESS_DENIED) {
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
} else {
// Ignore windows, that can't be accessed
return "";
switch (Kernel32.INSTANCE.GetLastError()) {
case WinNT.ERROR_ACCESS_DENIED:
case WinError.ERROR_INVALID_PARAMETER:
process = Kernel32.INSTANCE.OpenProcess(
WinNT.PROCESS_QUERY_LIMITED_INFORMATION,
false,
pid.getValue());
if (process != null) {
break;
}
}
switch (Kernel32.INSTANCE.GetLastError()) {
case WinNT.ERROR_ACCESS_DENIED:
case WinError.ERROR_INVALID_PARAMETER:
// Ignore windows, that can't be accessed
return "";
}
/* if above didn't already break or return, fall through to default */
default:
throw new Win32Exception(Kernel32.INSTANCE.GetLastError());
}
}

Expand Down