Skip to content

Split WindowsOSProcess into superclass with JNA/FFM subclasses - #3141

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:split-win-osproc
Apr 11, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:split-win-osproc

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 11, 2026 •

Copy link
Copy Markdown
Member
  • Extract common WindowsOSProcess abstract superclass with shared fields (private + setters), getters, and non-native methods (queryCommandLine, queryCwd, queryMatchingThreads, getThreadDetails, updateAttributes)
  • Rename existing WindowsOSProcess to WindowsOSProcessJNA extending the new superclass
  • Update WindowsOSProcessFFM to extend the new superclass
  • Add VersionHelpersFFM — FFM port of JNA's VersionHelpers using native VerSetConditionMask/VerifyVersionInfoW from kernel32, replacing the os.version string-parsing workaround
  • Add OSVERSIONINFOEX struct layout and VER_*/WIN32_WINNT_* constants to WinNTFFM
  • Add VerSetConditionMask and VerifyVersionInfoW bindings to Kernel32FFM
  • Remove unnecessary TOKEN_DUPLICATE from OpenProcessToken calls in both JNA and FFM — only TOKEN_QUERY is needed for GetTokenInformation
  • Replace magic 0x0008 with TOKEN_QUERY constant import in FFM

Summary by CodeRabbit

  • New Features

    • Added Windows version-detection helpers (Vista, 7, 8, 8.1, 10) and Server detection.
    • Added alternative native bindings/backends to improve Windows API access.
  • Refactor

    • Restructured Windows process handling to support multiple backends and improved process info retrieval (affinity, bitness, path, arguments, user/group, CWD, environment) with safer fallbacks.

@coderabbitai

coderabbitai Bot commented Apr 11, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd612d3c-b80b-4926-a4e6-3e2c7fb5df0e

📥 Commits

Reviewing files that changed from the base of the PR and between a912a56 and 305379f.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
🔇 Additional comments (15)
oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java (1)

46-82: FFM versioning constants and OSVERSIONINFOEX layout look correct.

The added VER_*/WIN32_WINNT_* constants plus computed offsets are coherent with the new VersionHelpersFFM call pattern and remove magic-number usage cleanly.

oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java (2)

55-75: IsWindowsVersionOrGreater implementation is solid.

The struct initialization, condition-mask composition, and VerifyVersionInfoW invocation are consistent and correctly scoped to the requested fields.


115-136: IsWindowsServer error-path handling is correctly implemented.

Good distinction between “condition not met” (ERROR_OLD_WIN_VERSION) and unexpected API failure before deciding server status.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java (6)

38-48: LGTM!

The conversion to an abstract base class with protected static constants is well-structured. This allows both JNA and FFM subclasses to share the common configuration flags while keeping the implementation details properly encapsulated. Based on learnings, changes to platform-specific subpackages like this one are not considered public API breaks.


80-106: LGTM!

The protected constructor and accessor methods are appropriately designed for an abstract base class. The constructor correctly delegates initialization and the protected accessors (getOs(), getCwdCmdEnv()) provide clean access patterns for subclasses without exposing internal fields directly.


296-336: LGTM!

The defensive null handling is well-designed:

  • pcb == null → marks process INVALID and returns early (pcb provides essential metrics like name, priority, timestamps)
  • wts == null → gracefully skips WTS-derived fields (path, threadCount, virtualSize, etc.) since these are supplementary

This ensures subclasses (WindowsOSProcessJNA, WindowsOSProcessFFM) can safely call super.updateAttributes() and rely on the return value to determine whether to proceed with native-specific updates.


338-363: LGTM!

The protected setters provide controlled mutation for subclasses to update private fields after native-specific queries (WOW64 bitness check, executable path lookup). This is a clean design that maintains encapsulation while enabling the JNA/FFM implementations to complete attribute population.


389-436: LGTM!

The abstract query hooks and static default helpers establish a clean contract:

  • Subclasses implement native-specific logic (queryArguments, queryUserInfo, queryGroupInfo, queryCwdCommandlineEnvironment)
  • Static helpers (defaultCwdCommandlineEnvironment, defaultPair) provide consistent fallbacks using Constants.UNKNOWN

This design keeps the memoization logic in the base class while delegating platform-specific retrieval to implementations.


62-62: LGTM!

Initializing path to an empty string ensures getPath() never returns null, even when WTS data is unavailable or the native path query fails. This is consistent with the defensive handling throughout the class.

oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java (6)

27-27: LGTM!

Good improvements:

  • TOKEN_QUERY constant import replaces the magic literal 0x0008, improving readability
  • VersionHelpersFFM provides native Windows version detection via VerSetConditionMask/VerifyVersionInfoW, eliminating string-parsing workarounds
  • Class properly extends the new abstract WindowsOSProcess base class

Also applies to: 48-48, 56-64


66-70: LGTM!

The constructor correctly delegates to the superclass. Accepting WindowsOperatingSystem (rather than WindowsOperatingSystemFFM) is type-safe since WindowsOperatingSystemFFM extends WindowsOperatingSystem, allowing polymorphic instantiation from WindowsOperatingSystemFFM.getChildProcesses().


90-123: LGTM!

The updateAttributes override correctly:

  1. Delegates to super.updateAttributes(pcb, wts) first, returning early if the parent marks the process INVALID
  2. Performs FFM-specific updates (WOW64 bitness check, executable path query) using protected setters
  3. Uses try-finally to ensure the process handle is closed
  4. FFM calls return error indicators (boolean/Optional) rather than throwing, so explicit exception handling isn't needed here

Based on learnings, the intentional failure-handling pattern is preserved—failures are signaled via return value.


125-132: LGTM!

The queryArguments() implementation correctly overrides the abstract method, using Shell32FFM.CommandLineToArgv to parse the command line into arguments.


134-196: LGTM!

The queryUserInfo() and queryGroupInfo() implementations:

  • Use TOKEN_QUERY constant (sufficient for GetTokenInformation, removing unnecessary TOKEN_DUPLICATE)
  • Return defaultPair() for consistency with the parent class helper
  • Properly handle resource cleanup in finally blocks (checking hToken != null && address != 0)
  • Appropriately log warnings on failures (these are query methods, not updateAttributes)

261-346: LGTM!

The queryCwdCommandlineEnvironment() implementation correctly overrides the abstract method with comprehensive defensive checks. Each failure path returns defaultCwdCommandlineEnvironment(), and the process handle is properly closed in the finally block.


📝 Walkthrough

Walkthrough

Converted WindowsOSProcess into an abstract superclass and added JNA and FFM concrete subclasses; added FFM downcalls for VerSetConditionMask/VerifyVersionInfoW, a VersionHelpersFFM utility, OSVERSIONINFOEX layout and version constants, and updated process instantiation to use the JNA backend.

Changes

Cohort / File(s) Summary
Changelog
CHANGELOG.md
Added entry for PR #3141 describing WindowsOSProcess refactor, JNA/FFM subclasses, VersionHelpersFFM, and removal of TOKEN_DUPLICATE.
Kernel32 FFM
oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
Added FFM downcalls and public wrappers: VerSetConditionMask(long,int,byte) -> long and VerifyVersionInfoW(MemorySegment,int,long) -> boolean; adjusted imports for JAVA_BYTE.
WinNT FFM
oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
Added version/product constants (VER_*, WIN32_WINNT_*, VER_NT_WORKSTATION), declared StructLayout OSVERSIONINFOEX, and exposed precomputed offsets for major/minor/SP/product type fields.
Version Helpers (FFM)
oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
New final utility class with IsWindowsVersionOrGreater(...), convenience checks (Vista,7,8,8.1,10) and IsWindowsServer() using VerSetConditionMask and VerifyVersionInfoW.
WindowsOSProcess (abstract)
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
Made class abstract, reduced constructor visibility to protected, removed native/JNA implementations, added protected setters/accessors and abstract hooks: queryArguments, queryUserInfo, queryGroupInfo, queryCwdCommandlineEnvironment.
FFM Process Implementation
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
Now extends WindowsOSProcess; constructor updated to accept WindowsOperatingSystem; delegates main attribute updates to superclass and retains FFM-specific extras; token access switched to TOKEN_QUERY; several methods changed to protected overrides.
JNA Process Implementation
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
Added new JNA-backed subclass implementing affinity retrieval, updateAttributes (WOW64 detection, path retrieval), argument parsing, token-based user/group queries, and remote-memory reads for CWD/commandline/environment.
Process Factory Update
oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
Now instantiates WindowsOSProcessJNA in processMapToList instead of the previous concrete WindowsOSProcess; minor import/copyright update.

Sequence Diagram(s)

sequenceDiagram
    participant App as Caller
    participant VH as VersionHelpersFFM
    participant Arena as Arena
    participant WinNT as WinNTFFM
    participant K32 as Kernel32FFM

    App->>VH: IsWindowsVersionOrGreater(major, minor, sp)
    VH->>Arena: allocate OSVERSIONINFOEX, zero-fill
    VH->>WinNT: set dwOSVersionInfoSize, major, minor, servicePack
    VH->>K32: VerSetConditionMask(condMask, VER_MAJORVERSION, VER_GREATER_EQUAL)
    K32-->>VH: updatedCond
    VH->>K32: VerSetConditionMask(... VER_MINORVERSION ...)
    K32-->>VH: updatedCond
    VH->>K32: VerSetConditionMask(... VER_SERVICEPACKMAJOR ...)
    K32-->>VH: updatedCond
    VH->>K32: VerifyVersionInfoW(lpVersionInformation, dwTypeMask, dwlConditionMask)
    K32-->>VH: success/fail
    VH-->>App: boolean result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐇 I hopped through structs and downcalls bright,

I set condition masks by lamp and light.
A superclass now guides JNA and FFM friends,
Two paths for processes where the pathway bends.
Hooray for hops and tidy, shared ends! 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: splitting WindowsOSProcess into an abstract superclass with separate JNA and FFM implementations, which is the core refactoring objective of this PR.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 11, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.21%. Comparing base (595c918) to head (305379f).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3141      +/-   ##
============================================
+ Coverage     62.00%   62.21%   +0.21%     
  Complexity       12       12              
============================================
  Files            39       39              
  Lines          2329     2329              
  Branches        407      407              
============================================
+ Hits           1444     1449       +5     
+ Misses          776      770       -6     
- Partials        109      110       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java`:
- Around line 108-117: In IsWindowsServer(), after calling
Kernel32FFM.VerifyVersionInfoW(osvi, VER_PRODUCT_TYPE, dwlConditionMask) do not
unconditionally negate the result; instead, when VerifyVersionInfoW returns
false call Kernel32FFM.GetLastError() and compare it to ERROR_OLD_WIN_VERSION
(0x47E) — only interpret ERROR_OLD_WIN_VERSION as indicating the system is a
server and return true, otherwise treat it as an API failure and return a safe
fallback (false) and/or log the unexpected error code; update the logic around
VerifyVersionInfoW, GetLastError, and the ERROR_OLD_WIN_VERSION check in the
IsWindowsServer method.

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java`:
- Around line 92-98: The catch block in WindowsOSProcessJNA around
Kernel32Util.QueryFullProcessImageName is incorrectly marking the process
INVALID on failure; change it to treat the path lookup as best-effort by
removing the setState(State.INVALID) call and leaving the process state
untouched (optionally clear or leave the path as-is via setPath only on
success). Locate the try/catch that calls Kernel32Util.QueryFullProcessImageName
in WindowsOSProcessJNA (the block that follows super.updateAttributes(...)) and
ensure Win32Exception is caught but does not call setState; instead simply skip
setting the path or log/debug the exception.
- Around line 150-171: The queryGroupInfo() method can leak handles if an
exception occurs between OpenProcessToken(...) and the manual CloseHandle(...)
calls; update queryGroupInfo() to mirror queryUserInfo() by wrapping the token
operations in a try/catch/finally so that both the token handle and the process
handle are always closed (call Kernel32.INSTANCE.CloseHandle(token) and
Kernel32.INSTANCE.CloseHandle(pHandle) in finally), preserve existing error
logging (including checking for ERROR_ACCESS_DENIED) in the catch, and ensure
phToken resources are still closed via CloseableHANDLEByReference.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 441cef99-e1f2-46bc-b599-96e4416e72d5

📥 Commits

Reviewing files that changed from the base of the PR and between 595c918 and aaa593e.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
📚 Learning: 2026-04-06T04:45:51.516Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (1)
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java (1)

127-132: ⚠️ Potential issue | 🟡 Minor

GetLastError() called twice - second call may return stale or zero value.

On Line 127, the error code is correctly stored in error, but Line 130-131 calls GetLastError() again in the log statement. After the first call, GetLastError() is typically reset, so the second call may return 0 or a different value.

Suggested fix
                     } else {
                         int error = Kernel32.INSTANCE.GetLastError();
                         // Access denied errors are common. Fail silently.
                         if (error != WinError.ERROR_ACCESS_DENIED) {
                             LOG.error("Failed to get process token for process {}: {}", getProcessID(),
-                                    Kernel32.INSTANCE.GetLastError());
+                                    error);
                         }
                     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java`
around lines 127 - 132, The code in WindowsOSProcessJNA reads
Kernel32.INSTANCE.GetLastError() into the local variable error but then calls
GetLastError() again in the LOG.error message; replace the second call with the
saved error variable to avoid a stale/cleared value. Update the LOG.error
invocation that currently references Kernel32.INSTANCE.GetLastError() to use the
existing error variable (named error) and keep the access-denied check using
WinError.ERROR_ACCESS_DENIED unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java`:
- Around line 160-165: In queryGroupInfo within WindowsOSProcessJNA the code
calls Kernel32.INSTANCE.GetLastError() twice; capture the error once (already
assigned to the local variable error) and use that variable in the LOG.error
call instead of calling GetLastError() again so the logged value matches the
checked condition; update the LOG.error invocation that currently passes
Kernel32.INSTANCE.GetLastError() to pass the error variable.

---

Duplicate comments:
In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java`:
- Around line 127-132: The code in WindowsOSProcessJNA reads
Kernel32.INSTANCE.GetLastError() into the local variable error but then calls
GetLastError() again in the LOG.error message; replace the second call with the
saved error variable to avoid a stale/cleared value. Update the LOG.error
invocation that currently references Kernel32.INSTANCE.GetLastError() to use the
existing error variable (named error) and keep the access-denied check using
WinError.ERROR_ACCESS_DENIED unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c5acb6da-0214-44e7-83aa-4c279b2e4f6d

📥 Commits

Reviewing files that changed from the base of the PR and between aaa593e and a912a56.

📒 Files selected for processing (8)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/VersionHelpersFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (8)
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java
📚 Learning: 2026-04-10T22:44:32.055Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:32.055Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java
🔇 Additional comments (16)
oshi-core-java25/src/main/java/oshi/ffm/windows/Kernel32FFM.java (1)

487-531: LGTM!

The new VerSetConditionMask and VerifyVersionInfoW bindings follow the established patterns in this class: proper downcall setup, catch-all exception handling with debug logging, and safe default return values (0L and false respectively). The JAVA_BYTE import is correctly added to support the condition parameter.

oshi-core-java25/src/main/java/oshi/ffm/windows/WinNTFFM.java (1)

46-81: LGTM!

The version constants and OSVERSIONINFOEX struct layout are correctly defined:

  • VER_* flags match Windows SDK definitions
  • WIN32_WINNT_* constants correctly encode (major << 8 | minor)
  • The struct layout accounts for all 284 bytes with proper field types
  • Offset computations use the correct MemoryLayout API
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java (5)

27-27: Good improvement replacing magic number with constant.

Using TOKEN_QUERY constant import instead of the magic 0x0008 improves readability and maintainability.


59-70: LGTM!

The class properly extends WindowsOSProcess and the constructor correctly delegates to the superclass, eliminating duplicated initialization logic.


91-123: LGTM!

The updateAttributes implementation correctly:

  1. Delegates to super.updateAttributes(pcb, wts) first for shared logic
  2. Performs FFM-specific WOW64 bitness detection and path lookup only on success
  3. Uses protected setters (setBitness, setPath) to update state
  4. Returns validity based on state check

This follows the established failure-handling pattern per project learnings.


125-196: LGTM!

The protected method implementations (queryArguments, queryUserInfo, queryGroupInfo) properly:

  • Use the TOKEN_QUERY constant consistently
  • Return defaultPair() on failure paths
  • Handle resource cleanup in finally blocks
  • Log appropriate warnings for non-access-denied errors

261-346: LGTM!

The queryCwdCommandlineEnvironment implementation correctly handles memory reading with proper cleanup and falls back to defaultCwdCommandlineEnvironment() on any failure path.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java (4)

1-57: LGTM!

The class structure, imports, and constructor properly set up the JNA-based implementation extending the abstract WindowsOSProcess superclass.


59-73: LGTM!

The getAffinityMask implementation correctly opens the process handle, queries the affinity mask, and ensures cleanup via the finally block.


75-105: LGTM!

The updateAttributes implementation correctly:

  1. Calls super.updateAttributes(pcb, wts) first
  2. Performs JNA-specific WOW64 and path lookup
  3. Uses empty catch for Win32Exception as best-effort (per past review feedback)
  4. Ensures handle cleanup in finally

182-257: LGTM!

The queryCwdCommandlineEnvironment and readUnicodeString implementations correctly handle process memory reading with proper resource management via try-with-resources and finally blocks.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcess.java (5)

38-48: LGTM!

The refactoring to an abstract class with protected constructor and configuration flags is well-structured. Per project conventions, platform-specific subpackages are implementation detail, so this is not a breaking API change.


80-88: LGTM!

The protected constructor properly initializes shared state and delegates to updateAttributes. Subclasses will extend this with their native-specific initialization.


288-336: LGTM!

The updateAttributes implementation correctly:

  1. Returns false immediately when pcb is null, marking state as INVALID
  2. Populates WTS-derived fields only when wts is not null
  3. Sets state based on thread performance data when available
  4. Returns validity based on final state

This provides a clean contract for subclasses to extend with native-specific updates.


338-372: LGTM!

The protected setters and queryMatchingThreads helper provide appropriate hooks for subclasses to update process attributes after native queries.


389-436: LGTM!

The abstract method declarations clearly define the contract that subclasses must implement. The protected static default helpers (defaultCwdCommandlineEnvironment, defaultPair) provide consistent fallback values.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant