Improve error handling in OpenProcess method : Windows32Exception - The parameter is incorrect #1700 #1701
+20
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I found the Windows code path that throws in getProcessFilePath(HWND) and implemented a defensive fix so your logs won’t fill with Win32Exceptions anymore. Now, when OpenProcess fails with ERROR_INVALID_PARAMETER (87), it is treated like ACCESS_DENIED: we either retry with PROCESS_QUERY_LIMITED_INFORMATION, or return an empty path if access still fails. This covers the race where a PID disappears between enumeration and open, or other transient/unsupported cases.
In contrib/platform/src/com/sun/jna/platform/WindowUtils.java, updated W32WindowUtils.getProcessFilePath:
On first OpenProcess failure, if GetLastError() is ACCESS_DENIED or INVALID_PARAMETER, we attempt PROCESS_QUERY_LIMITED_INFORMATION.
If the second OpenProcess also fails with ACCESS_DENIED or INVALID_PARAMETER, we return an empty string instead of throwing.
Only other error codes still throw a Win32Exception.