Skip to content

Migrate Windows software OS classes to common/JNA/FFM pattern - #3177

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:migrate-windows-os
Apr 20, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:migrate-windows-os

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Migrates the remaining Windows software OS classes (OSThread, OSProcess, and supporting classes) to the three-tier common/JNA/FFM architecture pattern.

Changes

oshi-common (new/modified)

  • WindowsOSThread (new): Abstract superclass with shared fields, getters, and state mapping logic
  • WindowsOSProcess (new): Abstract superclass with shared process fields/getters and update logic; native-dependent methods are abstract
  • WtsInfo (new): Standalone data holder extracted from ProcessWtsData inner class

oshi-core (new/modified)

  • WindowsOSThreadJNA (new): JNA implementation extending common WindowsOSThread
  • WindowsOSProcessJNA (rewritten): Now extends common WindowsOSProcess, implements all abstract methods
  • WindowsFileSystem → WindowsFileSystemJNA (renamed)
  • WindowsInstalledApps → WindowsInstalledAppsJNA (renamed)
  • WindowsInternetProtocolStats → WindowsInternetProtocolStatsJNA (renamed)
  • WindowsNetworkParams → WindowsNetworkParamsJNA (renamed)
  • Updated WindowsOperatingSystem and ProcessWtsData imports

oshi-core-java25 (new/modified)

  • WindowsOSThreadFFM (new): FFM implementation extending common WindowsOSThread
  • WindowsOSProcessFFM (rewritten): Now extends common WindowsOSProcess, implements all abstract methods
  • Added getCurrentThread() override to WindowsOperatingSystemFFM

Smoke Test

Removing the build-helper-maven-plugin source copy from oshi-core-java25 now leaves only 5 remaining dependencies on oshi-core:

  1. WindowsOperatingSystem — FFM extends it (needs common superclass extraction)
  2. ProcessWtsData — JNA-dependent registry reader
  3. PlatformEnum (deprecated) — can switch to oshi.util.PlatformEnum
  4. oshi.driver.mac.disk.Fsstat — JNA-based
  5. oshi.driver.mac.net.NetStat — JNA-based

Testing

  • All existing tests pass on macOS
  • CI will validate Windows/Linux

Summary by CodeRabbit

  • Refactor

    • Consolidated Windows OS abstractions, unified JNA/FFM naming, and moved process/thread responsibilities into common base classes to support multiple native backends.
    • Renamed several Windows system utilities to JNA-specific variants for consistent behavior.
  • New Features

    • Added a shared Windows Terminal Services (WTS) process info data holder.
    • Introduced JNA/FFM-specific process and thread implementations with improved current-thread handling and enhanced command-line/attribute retrieval using registry → WMI → perf-counter fallbacks.

@coderabbitai

coderabbitai Bot commented Apr 20, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Extracts WTS process info into a new top-level WtsInfo data class, moves Windows process/thread logic into common abstract bases, and adds JNA and FFM concrete implementations with updated command-line/thread-query hooks and renamed JNA-specific utility classes. (30 words)

Changes

Cohort / File(s) Summary
WtsInfo Data Holder
oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
Added new public final immutable WtsInfo class with seven fields and getters; replaces former nested ProcessWtsData.WtsInfo.
Common Base Classes
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
Moved process/thread logic to common package; introduced abstract hooks (createOSThread, queryMatchingThreads, queryCommandLine), added MAX_WINDOWS_HANDLES, switched to generic OperatingSystem type, added setTcb/setName, and removed concrete per-class updateAttributes() implementations.
FFM Implementations
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java, .../WindowsOSThreadFFM.java, .../WindowsOperatingSystemFFM.java
Added FFM-based classes implementing hooks using registry-first then perf-counter fallbacks, updated command-line resolution, and construct WindowsOSThreadFFM; use top-level WtsInfo.
JNA Implementations
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java, .../WindowsOSThreadJNA.java
Added JNA-based classes implementing hooks with JNA perf/registry builders and WMI fallback; updateAttributes() now sources registry/perf maps and WTS WtsInfo; added createOSThread overrides.
JNA Class Renames
oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java, .../WindowsInstalledAppsJNA.java, .../WindowsInternetProtocolStatsJNA.java, .../WindowsNetworkParamsJNA.java
Renamed several Windows utility classes to *JNA variants; updated constructors, imports, and logger targets where applicable.
ProcessWtsData Migration
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
Removed nested WtsInfo class and switched APIs/instantiations to use top-level oshi.driver.common.windows.registry.WtsInfo; removed @Immutable import.
OS Integration & FileStore
oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java, oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
OS now returns JNA-suffixed implementations and imports shared WtsInfo; WindowsOSFileStoreJNA uses WindowsFileSystemJNA for volume discovery.
Changelog
CHANGELOG.md
Added 6.12.0 (in progress) entry documenting the FFM three-tier migration and related Windows class changes.

Sequence Diagram(s)

sequenceDiagram
  participant Common as WindowsOSProcess (common)
  participant Impl as Impl (JNA/FFM)
  participant Perf as PerfCounter/Registry
  participant WTS as ProcessWtsData (WTS)
  participant Threads as OSThread instances

  Common->>Impl: updateAttributes()
  Impl->>Perf: buildProcessMapFromRegistry(pids) or fallback to perf counters
  Perf-->>Impl: Map<pid, ProcessPerfCounterBlock>
  Impl->>WTS: queryProcessWtsMap(pids)
  WTS-->>Impl: Map<pid, WtsInfo>
  Impl->>Impl: setTcb(queryMatchingThreads(pids))
  Impl->>Threads: createOSThread(pid, tid, procName, pcb)
  Threads-->>Impl: thread.updateAttributes(procName, pcb)
  Impl-->>Common: updateAttributes(ProcessPerfCounterBlock, WtsInfo) per-process
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

A tiny WtsInfo takes the stage,
Threads find a common, wider page,
JNA and FFM step in time,
Hooks connect each thread and line,
New classes hum — welcome, good change!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 29.51% 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 'Migrate Windows software OS classes to common/JNA/FFM pattern' directly and clearly summarizes the main architectural refactoring across all modified files.

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

✨ Finishing Touches
✨ 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 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.74194% with 71 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.30%. Comparing base (af5b9f4) to head (1bab2e4).

Files with missing lines Patch % Lines
.../oshi/software/os/windows/WindowsOSProcessFFM.java 20.00% 18 Missing and 2 partials ⚠️
.../oshi/software/os/windows/WindowsOSProcessJNA.java 34.61% 14 Missing and 3 partials ⚠️
...re/os/windows/WindowsInternetProtocolStatsJNA.java 30.76% 9 Missing ⚠️
...i/software/common/os/windows/WindowsOSProcess.java 36.36% 5 Missing and 2 partials ⚠️
...a/oshi/software/os/windows/WindowsOSThreadFFM.java 28.57% 5 Missing ⚠️
...a/oshi/software/os/windows/WindowsOSThreadJNA.java 28.57% 5 Missing ⚠️
...hi/software/common/os/windows/WindowsOSThread.java 0.00% 2 Missing and 1 partial ⚠️
...software/os/windows/WindowsOperatingSystemFFM.java 66.66% 1 Missing and 1 partial ⚠️
...shi/software/os/windows/WindowsOSFileStoreJNA.java 0.00% 2 Missing ⚠️
...a/oshi/driver/common/windows/registry/WtsInfo.java 93.75% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3177   +/-   ##
=======================================
  Coverage   57.29%   57.30%           
=======================================
  Files         414      417    +3     
  Lines       19919    19973   +54     
  Branches     3496     3510   +14     
=======================================
+ Hits        11413    11445   +32     
- Misses       6786     6799   +13     
- Partials     1720     1729    +9     
Flag Coverage Δ
linux 23.13% <0.00%> (-0.06%) ⬇️
macos 25.96% <0.00%> (-0.07%) ⬇️
windows 34.65% <42.74%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

🧹 Nitpick comments (6)
oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java (1)

10-79: Optional: mark immutable data holder final.

All fields are already final and this is purely a data holder, so making the class final would prevent accidental inheritance. Very minor.

Proposed tweak
-public class WtsInfo {
+public final class WtsInfo {

Also — if the project targets a Java version that supports it here (oshi-common), a record would collapse this nicely. Totally fine to keep as-is for consistency with other data holders in this module.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java`
around lines 10 - 79, Mark the WtsInfo data holder class as final to prevent
accidental inheritance: update the class declaration for WtsInfo so it is
declared final (e.g., public final class WtsInfo) while leaving all existing
final fields and constructor unchanged; optionally consider converting to a Java
record if language level permits, but the immediate fix is to make the WtsInfo
class final.
oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java (1)

30-32: Nit: stale class name in Javadoc.

The Javadoc still references "WindowsNetworkParams" but the class is now WindowsNetworkParamsJNA. Totally optional to update.

Proposed tweak
 /**
- * WindowsNetworkParams class.
+ * WindowsNetworkParamsJNA class.
  */
🤖 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/WindowsNetworkParamsJNA.java`
around lines 30 - 32, Update the class Javadoc so the description matches the
actual class name: replace the stale "WindowsNetworkParams" reference with
"WindowsNetworkParamsJNA" in the Javadoc block above the WindowsNetworkParamsJNA
class declaration; ensure the short description and any `@author/`@since lines (if
present) consistently refer to WindowsNetworkParamsJNA.
oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java (1)

93-101: Nit: stale constructor Javadoc.

Javadoc still says "Constructor for WindowsFileSystem." Purely cosmetic.

Proposed tweak
     /**
      * <p>
-     * Constructor for WindowsFileSystem.
+     * Constructor for WindowsFileSystemJNA.
      * </p>
      */
     public WindowsFileSystemJNA() {
🤖 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/WindowsFileSystemJNA.java`
around lines 93 - 101, The constructor Javadoc for WindowsFileSystemJNA is stale
("Constructor for WindowsFileSystem"); update the JavaDoc above the
WindowsFileSystemJNA() constructor to accurately describe its purpose (e.g.,
mention setting the Windows error mode to avoid prompts for floppy/CD-ROM) and
retain reference to Kernel32.INSTANCE.SetErrorMode and SEM_FAILCRITICALERRORS so
readers know why the constructor exists.
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java (1)

182-188: Note that getCurrentProcess() can return null (consistent across all platform implementations).

getCurrentProcess() may return null when the process is not found. All platform implementations (JNA and FFM across Windows, macOS, Linux, BSD, and AIX) use the same pattern without guarding—calling proc.getThreadDetails() and proc.getProcessID() directly. While this will throw a NullPointerException if the current process cannot be retrieved, this appears to be an established design throughout the codebase. If you'd like to add a null guard for defensive robustness, your suggestion above is a good approach; otherwise, this matches the existing pattern.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java`
around lines 182 - 188, Guard against getCurrentProcess() returning null in
getCurrentThread(): call getCurrentProcess() once into a local (proc), call
getThreadId() for tid, and if proc is null return a fallback WindowsOSThreadFFM
using a sane default PID (e.g., 0) and tid; otherwise proceed to search
proc.getThreadDetails() and use proc.getProcessID() as before. Update
getCurrentThread() to use these symbols: getCurrentProcess(), getThreadId(),
proc.getThreadDetails(), proc.getProcessID(), and WindowsOSThreadFFM(...).
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java (1)

99-114: Nit: variable name pcb shadows the single-block meaning used elsewhere.

pcb here is a Map<Integer, ProcessPerfCounterBlock>, but in the protected updateAttributes(ProcessPerfCounterBlock pcb, WtsInfo wts) on line 117 the same name refers to a single block. Consider renaming the local map (e.g., pcbMap / perfMap) to match wts/wtsMap style elsewhere. Same applies to the sibling WindowsOSProcessJNA.updateAttributes().

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`
around lines 99 - 114, Local variable name pcb in
WindowsOSProcessFFM.updateAttributes() is a Map<Integer,
ProcessPerfCounterBlock> that conflicts with the single-block parameter name
used by the protected updateAttributes(ProcessPerfCounterBlock pcb, WtsInfo
wts); rename the local Map to pcbMap or perfMap (and update all references,
including the ternary when calling updateAttributes) to avoid shadowing, and
make the same rename in the sibling WindowsOSProcessJNA.updateAttributes() for
consistency (retain calls to
ProcessPerformanceDataFFM.buildProcessMapFromRegistry/buildProcessMapFromPerfCounters
and ProcessWtsData.queryProcessWtsMap as-is).
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java (1)

12-17: Optional: import java.util.Set instead of fully qualifying it.

Set isn't in the import list, so the abstract declaration on line 376 falls back to java.util.Set<Integer>. A one-line import would align with the neighboring Map/List/Collections imports.

♻️ Proposed change
 import java.util.Map;
+import java.util.Set;
 import java.util.function.Supplier;
-    protected abstract Map<Integer, ThreadPerfCounterBlock> queryMatchingThreads(java.util.Set<Integer> pids);
+    protected abstract Map<Integer, ThreadPerfCounterBlock> queryMatchingThreads(Set<Integer> pids);

Also applies to: 376-376

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java`
around lines 12 - 17, Add a one-line import for java.util.Set and update the
abstract declaration that currently uses the fully qualified
java.util.Set<Integer> to use the imported Set<Integer> instead; locate the
declaration in the WindowsOSProcess class (the abstract declaration currently
written as java.util.Set<Integer>) and replace the fully-qualified type with
Set<Integer> after adding import java.util.Set; this aligns imports with
List/Map/Collections and removes the fully-qualified reference.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java`:
- Around line 10-79: Mark the WtsInfo data holder class as final to prevent
accidental inheritance: update the class declaration for WtsInfo so it is
declared final (e.g., public final class WtsInfo) while leaving all existing
final fields and constructor unchanged; optionally consider converting to a Java
record if language level permits, but the immediate fix is to make the WtsInfo
class final.

In
`@oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java`:
- Around line 12-17: Add a one-line import for java.util.Set and update the
abstract declaration that currently uses the fully qualified
java.util.Set<Integer> to use the imported Set<Integer> instead; locate the
declaration in the WindowsOSProcess class (the abstract declaration currently
written as java.util.Set<Integer>) and replace the fully-qualified type with
Set<Integer> after adding import java.util.Set; this aligns imports with
List/Map/Collections and removes the fully-qualified reference.

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java`:
- Around line 182-188: Guard against getCurrentProcess() returning null in
getCurrentThread(): call getCurrentProcess() once into a local (proc), call
getThreadId() for tid, and if proc is null return a fallback WindowsOSThreadFFM
using a sane default PID (e.g., 0) and tid; otherwise proceed to search
proc.getThreadDetails() and use proc.getProcessID() as before. Update
getCurrentThread() to use these symbols: getCurrentProcess(), getThreadId(),
proc.getThreadDetails(), proc.getProcessID(), and WindowsOSThreadFFM(...).

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`:
- Around line 99-114: Local variable name pcb in
WindowsOSProcessFFM.updateAttributes() is a Map<Integer,
ProcessPerfCounterBlock> that conflicts with the single-block parameter name
used by the protected updateAttributes(ProcessPerfCounterBlock pcb, WtsInfo
wts); rename the local Map to pcbMap or perfMap (and update all references,
including the ternary when calling updateAttributes) to avoid shadowing, and
make the same rename in the sibling WindowsOSProcessJNA.updateAttributes() for
consistency (retain calls to
ProcessPerformanceDataFFM.buildProcessMapFromRegistry/buildProcessMapFromPerfCounters
and ProcessWtsData.queryProcessWtsMap as-is).

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java`:
- Around line 93-101: The constructor Javadoc for WindowsFileSystemJNA is stale
("Constructor for WindowsFileSystem"); update the JavaDoc above the
WindowsFileSystemJNA() constructor to accurately describe its purpose (e.g.,
mention setting the Windows error mode to avoid prompts for floppy/CD-ROM) and
retain reference to Kernel32.INSTANCE.SetErrorMode and SEM_FAILCRITICALERRORS so
readers know why the constructor exists.

In
`@oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java`:
- Around line 30-32: Update the class Javadoc so the description matches the
actual class name: replace the stale "WindowsNetworkParams" reference with
"WindowsNetworkParamsJNA" in the Javadoc block above the WindowsNetworkParamsJNA
class declaration; ensure the short description and any `@author/`@since lines (if
present) consistently refer to WindowsNetworkParamsJNA.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cd135b71-c221-4b30-a30d-f6fe5a73e76f

📥 Commits

Reviewing files that changed from the base of the PR and between af5b9f4 and e1d0946.

📒 Files selected for processing (15)
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.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). (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (15)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.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/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • 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/WindowsOSFileStoreJNA.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/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.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/software/os/windows/WindowsOperatingSystemFFM.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-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.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/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.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:

  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
🔇 Additional comments (12)
oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java (1)

12-20: LGTM — clean rename.

Class and constructor rename consistently applied; the added List import is correct for the return type.

oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java (1)

94-153: LGTM — clean extraction to common.

Null-guard on procName in updateAttributes (Line 114) is a nice addition over the prior behavior which only checked isEmpty(). getProcName() returning "" for a null name also keeps subclasses from having to special-case it.

One small inconsistency worth noting (purely cosmetic): some assignments use this.name / this.priority while others use bare name, state, etc. Not a bug, just unalike. Feel free to ignore.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java (1)

27-44: LGTM.

Consistent with the WindowsFileSystem → WindowsFileSystemJNA rename. Behavior unchanged.

oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java (1)

52-52: LGTM.

Rename applied consistently; stateLookup TCP state mappings are unchanged (1/12→CLOSED, 2→LISTEN, ..., 11→TIME_WAIT, default→UNKNOWN).

Also applies to: 219-247

oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java (1)

120-446: Clean rename pass — LGTM.

All constructor/factory references consistently updated to the *JNA variants, and the new top-level WtsInfo import replaces the removed nested type. Context snippets confirm the referenced JNA classes (WindowsFileSystemJNA, WindowsInternetProtocolStatsJNA, WindowsOSThreadJNA, WindowsInstalledAppsJNA) expose the expected constructors/static methods.

oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java (1)

22-101: Extraction to shared WtsInfo looks correct.

Both code paths (queryProcessWtsMapFromWTS and queryProcessWtsMapFromPerfMon) invoke the new top-level oshi.driver.common.windows.registry.WtsInfo with the same 7-arg order as the moved constructor, and the parameter types align (int, long, long, long, long, long).

oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java (1)

19-32: Implementation looks good.

The updateAttributes() override correctly delegates to the protected 2-arg helper, and the ternary guards against a null map before get(tid). Parallel structure with WindowsOSThreadFFM makes the JNA/FFM split easy to reason about.

oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java (1)

19-32: Mirrors the JNA implementation cleanly — LGTM.

Parallel to WindowsOSThreadJNA, routing through ThreadPerformanceDataFFM.buildThreadMapFromPerfCounters(pids, procName, threadNum). Nothing to flag.

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

148-175: Overrides line up with the new abstract hooks.

createOSThread, queryMatchingThreads, and queryCommandLine all match the signatures declared in the common WindowsOSProcess, and the command-line fallback chain (cwdCmdEnv → batch cache → WMI) mirrors the JNA path.

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

85-162: Symmetric with WindowsOSProcessFFM — looks good.

Command-line fallback chain, thread map query priority (registry → perf counters with process-name filter), and suspended-thread handling under USE_PROCSTATE_SUSPENDED are all mirrored between JNA and FFM. Nothing additional to flag here beyond the pcb local-variable naming nit noted on the FFM side.

oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java (2)

263-282: Abstraction split reads cleanly.

Hoisting the thread-map lookup behind queryMatchingThreads(...) and thread construction behind createOSThread(...) keeps the common class platform-agnostic while preserving the tcb-cache short-circuit. The this.name used when building OSThread instances is already populated via updateAttributes(...) in the constructor, so the invariant holds.


37-45: Relocation of MAX_WINDOWS_HANDLES is fine.

Moving this constant out of the (now renamed) WindowsFileSystem and into the common process class avoids a cross-module dependency from the abstract process onto a JNA-specific filesystem class. The ProgramFiles(x86) probe preserves the 32-bit vs. 64-bit handle cap semantics from the original implementation.

@dbwiddis
dbwiddis force-pushed the migrate-windows-os branch from e1d0946 to 3d1eb6e Compare April 20, 2026 06:16

@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.

🧹 Nitpick comments (4)
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java (1)

182-192: Consider orElseGet to avoid eagerly constructing the fallback thread.

orElse(new WindowsOSThreadFFM(...)) always allocates and runs the WindowsOSThreadFFM constructor — which invokes updateAttributes(null, null) and sets state to INVALID — even when findFirst() succeeds. Deferring via orElseGet keeps the common (hit) path allocation-free.

♻️ Proposed refactor
-        return proc.getThreadDetails().stream().filter(t -> t.getThreadId() == tid).findFirst()
-                .orElse(new WindowsOSThreadFFM(proc.getProcessID(), tid, null, null));
+        return proc.getThreadDetails().stream().filter(t -> t.getThreadId() == tid).findFirst()
+                .orElseGet(() -> new WindowsOSThreadFFM(proc.getProcessID(), tid, null, null));
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java`
around lines 182 - 192, The getCurrentThread() method eagerly constructs the
fallback WindowsOSThreadFFM via orElse(...), causing updateAttributes(null,
null) and INVALID state to run even when findFirst() succeeds; change the
terminal call to use orElseGet(...) with a Supplier that constructs the new
WindowsOSThreadFFM(proc.getProcessID(), tid, null, null) so the fallback object
is created lazily only when needed (modify the return expression in
getCurrentThread() to call orElseGet(() -> new WindowsOSThreadFFM(...))).
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java (1)

148-162: Optional: cache the memoized cwdCmdEnv command-line locally to avoid the double call.

getCwdCmdEnv().getB() is already memoized in the base class, so the cost is tiny, but calling it twice here reads slightly awkwardly. A local variable also mirrors the common pattern used in WindowsOSProcess.queryCwd().

♻️ Proposed refactor
     protected String queryCommandLine() {
-        if (!getCwdCmdEnv().getB().isEmpty()) {
-            return getCwdCmdEnv().getB();
-        }
+        String cmd = getCwdCmdEnv().getB();
+        if (!cmd.isEmpty()) {
+            return cmd;
+        }
         if (USE_BATCH_COMMANDLINE) {
             return Win32ProcessCachedJNA.getInstance().getCommandLine(getProcessID(), getStartTime());
         }
         WmiResult<CommandLineProperty> commandLineProcs = Win32ProcessJNA
                 .queryCommandLines(Collections.singleton(getProcessID()));
         if (commandLineProcs.getResultCount() > 0) {
             return WmiUtil.getString(commandLineProcs, CommandLineProperty.COMMANDLINE, 0);
         }
         return "";
     }
🤖 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 148 - 162, In queryCommandLine(), avoid calling
getCwdCmdEnv().getB() twice by caching it in a local variable; specifically, at
the top of the method assign String cwdCmd = getCwdCmdEnv().getB() and then
check cwdCmd.isEmpty() and return cwdCmd if not empty, leaving the rest of the
logic (USE_BATCH_COMMANDLINE ->
Win32ProcessCachedJNA.getInstance().getCommandLine(getProcessID(),
getStartTime()); else -> Win32ProcessJNA.queryCommandLines(...)) unchanged.
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java (1)

110-118: Nit: inconsistent this.name usage inside updateAttributes.

Line 115 writes name = pcb.getName(); while line 117 uses this.name = .... Since this class has no name parameter in scope, both are equivalent, but aligning both branches on this.name (or both without) makes the else-if/else pair easier to scan.

♻️ Proposed nit
-        } else if (pcb.getName().contains("/") || procName == null || procName.isEmpty()) {
-            name = pcb.getName();
-        } else {
-            this.name = procName + "/" + pcb.getName();
-        }
+        } else if (pcb.getName().contains("/") || procName == null || procName.isEmpty()) {
+            this.name = pcb.getName();
+        } else {
+            this.name = procName + "/" + pcb.getName();
+        }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java`
around lines 110 - 118, In WindowsOSThread.updateAttributes, the assignment in
the first branch uses the bare name variable while the else branch uses
this.name; change the first branch to assign this.name = pcb.getName() so both
branches consistently reference the instance field (keep references to
pcb.getName() and procName as-is).
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java (1)

162-175: Optional: same tiny redundancy as the JNA variant.

getCwdCmdEnv().getB() is called twice; a local captures it once and keeps both implementations symmetric. Memoization in the base already makes this negligible, but parity with the JNA side is nice.

♻️ Proposed refactor
     protected String queryCommandLine() {
-        if (!getCwdCmdEnv().getB().isEmpty()) {
-            return getCwdCmdEnv().getB();
-        }
+        String cmd = getCwdCmdEnv().getB();
+        if (!cmd.isEmpty()) {
+            return cmd;
+        }
         if (USE_BATCH_COMMANDLINE) {
             return Win32ProcessCachedFFM.getInstance().getCommandLine(getProcessID(), getStartTime());
         }
         var commandLineProcs = Win32ProcessFFM.queryCommandLines(Collections.singleton(getProcessID()));
         if (commandLineProcs.getResultCount() > 0) {
             return WmiUtilFFM.getString(commandLineProcs, CommandLineProperty.COMMANDLINE, 0);
         }
         return "";
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`
around lines 162 - 175, queryCommandLine() calls getCwdCmdEnv().getB() twice;
capture its result in a local variable (e.g., String cwdCmdEnvB) at the top of
the method and use that single variable in the first if-check to mirror the JNA
variant and avoid redundant calls; leave the rest of the method
(USE_BATCH_COMMANDLINE path using
Win32ProcessCachedFFM.getInstance().getCommandLine(getProcessID(),
getStartTime()) and the fallback using Win32ProcessFFM.queryCommandLines(...)
with WmiUtilFFM.getString(..., CommandLineProperty.COMMANDLINE, 0)) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java`:
- Around line 110-118: In WindowsOSThread.updateAttributes, the assignment in
the first branch uses the bare name variable while the else branch uses
this.name; change the first branch to assign this.name = pcb.getName() so both
branches consistently reference the instance field (keep references to
pcb.getName() and procName as-is).

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java`:
- Around line 182-192: The getCurrentThread() method eagerly constructs the
fallback WindowsOSThreadFFM via orElse(...), causing updateAttributes(null,
null) and INVALID state to run even when findFirst() succeeds; change the
terminal call to use orElseGet(...) with a Supplier that constructs the new
WindowsOSThreadFFM(proc.getProcessID(), tid, null, null) so the fallback object
is created lazily only when needed (modify the return expression in
getCurrentThread() to call orElseGet(() -> new WindowsOSThreadFFM(...))).

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`:
- Around line 162-175: queryCommandLine() calls getCwdCmdEnv().getB() twice;
capture its result in a local variable (e.g., String cwdCmdEnvB) at the top of
the method and use that single variable in the first if-check to mirror the JNA
variant and avoid redundant calls; leave the rest of the method
(USE_BATCH_COMMANDLINE path using
Win32ProcessCachedFFM.getInstance().getCommandLine(getProcessID(),
getStartTime()) and the fallback using Win32ProcessFFM.queryCommandLines(...)
with WmiUtilFFM.getString(..., CommandLineProperty.COMMANDLINE, 0)) unchanged.

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java`:
- Around line 148-162: In queryCommandLine(), avoid calling
getCwdCmdEnv().getB() twice by caching it in a local variable; specifically, at
the top of the method assign String cwdCmd = getCwdCmdEnv().getB() and then
check cwdCmd.isEmpty() and return cwdCmd if not empty, leaving the rest of the
logic (USE_BATCH_COMMANDLINE ->
Win32ProcessCachedJNA.getInstance().getCommandLine(getProcessID(),
getStartTime()); else -> Win32ProcessJNA.queryCommandLines(...)) unchanged.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4db87518-7a83-4823-8c9f-a67d01adf4d0

📥 Commits

Reviewing files that changed from the base of the PR and between e1d0946 and 3d1eb6e.

📒 Files selected for processing (16)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
✅ Files skipped from review due to trivial changes (3)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.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). (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (13)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.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-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.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-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/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.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/software/os/windows/WindowsOperatingSystemFFM.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-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.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
📚 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:

  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
🔇 Additional comments (7)
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java (1)

22-22: LGTM — clean import swap to the shared WtsInfo.

Constructor signature for the shared oshi.driver.common.windows.registry.WtsInfo matches the previous nested type (same 7 args), so both queryProcessWtsMapFromWTS and queryProcessWtsMapFromPerfMon construct it correctly.

oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java (1)

22-46: LGTM — clean abstract-base extraction.

The move to oshi.software.common.os.windows, the protected constructor, and the protected hook getProcName()/updateAttributes(procName, pcb) match the JNA/FFM subclass pattern used elsewhere in this PR. All previous getters and state-mapping logic are preserved unchanged.

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

85-146: LGTM — subclass hooks wired correctly.

updateAttributes() correctly handles both buildProcessMapFromRegistry returning null and the subsequent perf-counter fallback, guards setTcb behind USE_PROCSTATE_SUSPENDED, and null-checks both maps before delegating to the (pcb, wts) overload. createOSThread and queryMatchingThreads mirror the FFM counterpart, preserving parity.

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

99-160: LGTM — FFM subclass hooks symmetric with the JNA version.

updateAttributes(), createOSThread, and queryMatchingThreads track the JNA implementation 1:1 (registry-first with perf-counter fallback, USE_PROCSTATE_SUSPENDED-gated setTcb, null-safe delegation to the (pcb, wts) overload). Keeps JNA/FFM parity easy to audit.

oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java (3)

36-91: LGTM — solid extraction of the Windows process common layer.

A few things that stand out positively:

  • MAX_WINDOWS_HANDLES is now computed once in a static block here and used directly by get{Soft,Hard}OpenFileLimit(), eliminating the prior coupling to WindowsFileSystem.
  • Widening os from WindowsOperatingSystem to OperatingSystem is fine — only getBitness()/getProcessId() are used, both on the interface — and keeps this class portable across JNA/FFM OS subclasses.
  • The constructor still eagerly invokes updateAttributes(processMap.get(pid), processWtsMap.get(pid)), relying on the base overload that doesn't touch native handles — so subclasses' updateAttributes() no-arg override is only hit on explicit refresh, preserving constructor cost.

264-283: LGTM — clean abstract hook for thread creation.

getThreadDetails() now delegates per-thread instantiation to createOSThread(...), which is the right seam for the JNA/FFM split. The owning-process filter and parallel stream are preserved, so behavior is unchanged for callers.


362-384: LGTM — well-scoped subclass hooks.

setTcb, queryMatchingThreads, and queryCommandLine are the minimal surface needed for the JNA/FFM subclasses to drive their native queries while the base handles the shared bookkeeping. Keeps the common class free of JNA/FFM-specific imports as intended by the refactor.

@dbwiddis
dbwiddis force-pushed the migrate-windows-os branch from 3d1eb6e to c971cba Compare April 20, 2026 06:42

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java (1)

99-160: ⚠️ Potential issue | 🟠 Major

Mirror the null || isEmpty() fix here too.

Same concern as the JNA counterpart — updateAttributes() at line 105 and queryMatchingThreads() at line 156 only check == null before falling back to perf-counters, whereas WindowsOperatingSystem.processMapToList uses null || isEmpty(). Please apply the parallel fix so FFM and JNA refresh behavior stays in lock-step:

🛠️ Parallel diff
-        if (pcbMap == null) {
+        if (pcbMap == null || pcbMap.isEmpty()) {
             pcbMap = ProcessPerformanceDataFFM.buildProcessMapFromPerfCounters(pids);
         }
@@
         Map<Integer, ThreadPerfCounterBlock> threads = ThreadPerformanceDataFFM.buildThreadMapFromRegistry(pids);
-        if (threads == null) {
+        if (threads == null || threads.isEmpty()) {
             threads = ThreadPerformanceDataFFM.buildThreadMapFromPerfCounters(pids, this.getName(), -1);
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`
around lines 99 - 160, The FFM implementation only checks for null before
falling back to perf counters; update the null checks in updateAttributes() (use
the ProcessPerformanceDataFFM.buildProcessMapFromRegistry result) and in
queryMatchingThreads() (use ThreadPerformanceDataFFM.buildThreadMapFromRegistry
result) to treat empty maps the same as null by testing for (map == null ||
map.isEmpty()) and only then call the PerfCounters fallback, ensuring parity
with WindowsOperatingSystem.processMapToList.
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java (1)

85-146: ⚠️ Potential issue | 🟠 Major

Fallback condition differs from the batch path — consider matching null || isEmpty().

In WindowsOperatingSystem.processMapToList (lines 302 and 311), the registry → perf-counter fallback fires on map == null || map.isEmpty(). The per-process paths here only check == null:

  • Line 91: if (pcbMap == null) before falling back to buildProcessMapFromPerfCounters(pids)
  • Line 142: if (threads == null) before falling back to buildThreadMapFromPerfCounters(pids, getName(), -1)

Both buildProcessMapFromRegistry and buildThreadMapFromRegistry can return empty (non-null) maps when the requested PID(s) are absent from the registry snapshot or when PERFDATA is disabled. If an empty map is returned, the per-process updateAttributes() skips the WMI/perf-counter fallback, and super.updateAttributes(null, …) marks this process INVALID on refresh — even though a fresh batch snapshot with the same WMI/perf-counter fallback would have recovered it.

The same logic applies to WindowsOSProcessFFM.queryMatchingThreads().

🛠️ Suggested alignment with the batch path
     `@Override`
     public boolean updateAttributes() {
         Set<Integer> pids = Collections.singleton(this.getProcessID());
         // Get data from the registry if possible
         Map<Integer, ProcessPerfCounterBlock> pcbMap = ProcessPerformanceDataJNA.buildProcessMapFromRegistry(pids);
         // otherwise performance counters with WMI backup
-        if (pcbMap == null) {
+        if (pcbMap == null || pcbMap.isEmpty()) {
             pcbMap = ProcessPerformanceDataJNA.buildProcessMapFromPerfCounters(pids);
         }
@@
     `@Override`
     protected Map<Integer, ThreadPerfCounterBlock> queryMatchingThreads(Set<Integer> pids) {
         Map<Integer, ThreadPerfCounterBlock> threads = ThreadPerformanceDataJNA.buildThreadMapFromRegistry(pids);
-        if (threads == null) {
+        if (threads == null || threads.isEmpty()) {
             threads = ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters(pids, this.getName(), -1);
         }
         return threads;
     }
🤖 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 85 - 146, The fallback logic only checks for null, causing empty
registry maps to skip perf-counter fallbacks; change the checks in
WindowsOSProcessJNA.updateAttributes (where pcbMap is set via
ProcessPerformanceDataJNA.buildProcessMapFromRegistry) and in
queryMatchingThreads (where threads is set via
ThreadPerformanceDataJNA.buildThreadMapFromRegistry) to treat empty maps the
same as null (i.e., use map == null || map.isEmpty()) so you fall back to
ProcessPerformanceDataJNA.buildProcessMapFromPerfCounters and
ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters respectively; apply the
same null-or-empty check pattern to the analogous logic in
WindowsOSProcessFFM.queryMatchingThreads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`:
- Around line 99-160: The FFM implementation only checks for null before falling
back to perf counters; update the null checks in updateAttributes() (use the
ProcessPerformanceDataFFM.buildProcessMapFromRegistry result) and in
queryMatchingThreads() (use ThreadPerformanceDataFFM.buildThreadMapFromRegistry
result) to treat empty maps the same as null by testing for (map == null ||
map.isEmpty()) and only then call the PerfCounters fallback, ensuring parity
with WindowsOperatingSystem.processMapToList.

In `@oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java`:
- Around line 85-146: The fallback logic only checks for null, causing empty
registry maps to skip perf-counter fallbacks; change the checks in
WindowsOSProcessJNA.updateAttributes (where pcbMap is set via
ProcessPerformanceDataJNA.buildProcessMapFromRegistry) and in
queryMatchingThreads (where threads is set via
ThreadPerformanceDataJNA.buildThreadMapFromRegistry) to treat empty maps the
same as null (i.e., use map == null || map.isEmpty()) so you fall back to
ProcessPerformanceDataJNA.buildProcessMapFromPerfCounters and
ThreadPerformanceDataJNA.buildThreadMapFromPerfCounters respectively; apply the
same null-or-empty check pattern to the analogous logic in
WindowsOSProcessFFM.queryMatchingThreads.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5156df4b-bc7e-4c28-bcad-35549711c61a

📥 Commits

Reviewing files that changed from the base of the PR and between 3d1eb6e and c971cba.

📒 Files selected for processing (16)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
✅ Files skipped from review due to trivial changes (4)
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.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). (6)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.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/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.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/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

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-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

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-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.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/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.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/software/os/windows/WindowsOSProcessFFM.java
🔇 Additional comments (5)
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java (1)

22-22: Clean swap to the shared WtsInfo. 👋

Nice extraction — the shared oshi.driver.common.windows.registry.WtsInfo has an identical constructor and getter surface to the old nested class, so both queryProcessWtsMapFromWTS and queryProcessWtsMapFromPerfMon keep working unchanged. Welcome refactor.

oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java (1)

52-52: Rename + brace reformat — LGTM.

The class rename to WindowsInternetProtocolStatsJNA and the stateLookup reformat (added braces/indentation) leave the TCP-state mappings and default identical. No behavior change.

Also applies to: 219-247

oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java (1)

53-53: Factory/supplier swaps look consistent.

All call sites (installedAppsSupplier, getFileSystem, getInternetProtocolStats, getCurrentThread fallback, getNetworkParams) now point at the new *JNA classes, and each of those still extends the appropriate abstract base class (AbstractFileSystem, AbstractInternetProtocolStats, AbstractNetworkParams), so the return-type contracts are preserved. The WtsInfo import switch to oshi.driver.common.windows.registry.WtsInfo also lines up with the updated ProcessWtsData.queryProcessWtsMap signature.

Also applies to: 120-120, 236-236, 241-241, 371-371, 446-446

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

148-163: queryCommandLine() precedence reads cleanly — LGTM.

Nice mirror of the existing Win32-process command-line logic: PEB-derived value first, cached batch lookup under USE_BATCH_COMMANDLINE, WMI fallback with "" when the result set is empty. No null-safety concerns on WmiUtil.getString since getResultCount() > 0 gates the access.

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

162-176: FFM queryCommandLine() matches the JNA version — LGTM.

Precedence (PEB → batch-cached → WMI → "") is identical to WindowsOSProcessJNA.queryCommandLine, and the var inferred type on commandLineProcs keeps the FFM-specific WmiResult type local.

@dbwiddis
dbwiddis force-pushed the migrate-windows-os branch from c971cba to 60b9018 Compare April 20, 2026 07:04

@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.

🧹 Nitpick comments (1)
oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java (1)

108-114: Minor: setTcb runs before name is populated on first refresh.

When USE_PROCSTATE_SUSPENDED is set, setTcb(queryMatchingThreads(pids)) executes on line 109 prior to the protected updateAttributes(pcb, wts) call on line 112 that populates this.name. The perf-counter fallback in queryMatchingThreads at line 157 reads this.getName() with -1, so on the very first refresh of a freshly-constructed process where registry thread data is missing, the fallback will see an empty/stale name. The registry-first path is unaffected, and subsequent refreshes are fine — so the blast radius is narrow. Mentioning only because the JNA mirror has the same ordering and you may want to swap the order (or cache name from pcbMap.get(pid) first) in both if this corner matters.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`
around lines 108 - 114, The setTcb(queryMatchingThreads(pids)) call runs before
updateAttributes(...) so queryMatchingThreads may call this.getName() before
name is populated; to fix, populate/cache the process name first from
pcbMap.get(this.getProcessID()) (or call updateAttributes(...) for name) before
invoking setTcb, i.e., retrieve pcb = pcbMap == null ? null :
pcbMap.get(this.getProcessID()) (or extract pcb.processName) and ensure that
name is set/cached prior to calling setTcb(queryMatchingThreads(pids));
alternatively simply swap the order to call updateAttributes(pcb, wts) or at
least set the name field from pcb before calling setTcb to avoid the stale-name
perf-counter fallback in queryMatchingThreads.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java`:
- Around line 108-114: The setTcb(queryMatchingThreads(pids)) call runs before
updateAttributes(...) so queryMatchingThreads may call this.getName() before
name is populated; to fix, populate/cache the process name first from
pcbMap.get(this.getProcessID()) (or call updateAttributes(...) for name) before
invoking setTcb, i.e., retrieve pcb = pcbMap == null ? null :
pcbMap.get(this.getProcessID()) (or extract pcb.processName) and ensure that
name is set/cached prior to calling setTcb(queryMatchingThreads(pids));
alternatively simply swap the order to call updateAttributes(pcb, wts) or at
least set the name field from pcb before calling setTcb to avoid the stale-name
perf-counter fallback in queryMatchingThreads.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0fb98c58-d5e4-4849-b7d1-aacbf6143014

📥 Commits

Reviewing files that changed from the base of the PR and between c971cba and 60b9018.

📒 Files selected for processing (16)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
✅ Files skipped from review due to trivial changes (4)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (8)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.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). (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.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-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.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-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.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-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
📚 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
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • 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-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/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/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
🔇 Additional comments (4)
oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java (1)

53-446: *LGTM — clean swap to JNA types and shared WtsInfo.

The memoizer target (WindowsInstalledAppsJNA::queryInstalledApps), the three factory methods (getFileSystem, getInternetProtocolStats, getNetworkParams), the getCurrentThread() fallback (WindowsOSThreadJNA), and the shared oshi.driver.common.windows.registry.WtsInfo import all line up with the new constructor signatures and the common-package type. Nothing functionally changes here beyond the class-name migration.

oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java (1)

22-101: LGTM — migration to shared WtsInfo preserves behavior.

Both the WTS (lines 74-77) and WMI/PerfMon (lines 93-101) construction sites align with the new oshi.driver.common.windows.registry.WtsInfo 7-arg constructor ordering (name, path, threadCount, virtualSize, kernelTime, userTime, openFiles). The deletion of the nested immutable class and its @Immutable import are consistent with the common type taking over.

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

99-176: LGTM — overrides plug cleanly into the new common WindowsOSProcess hooks.

updateAttributes(), createOSThread(...), queryMatchingThreads(...), and queryCommandLine() all have signatures matching the abstract declarations in the common parent, and the registry→perf-counter fallbacks plus the cwd/batch/WMI precedence in queryCommandLine() mirror the prior concrete logic. Null handling on pcbMap.get(pid) / wts.get(pid) is safely absorbed by the protected updateAttributes(pcb, wts) in the parent.

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

85-163: LGTM — JNA overrides mirror the FFM side faithfully.

The four new overrides (updateAttributes(), createOSThread, queryMatchingThreads, queryCommandLine) match the abstract hooks on the common WindowsOSProcess and reproduce the registry→perf-counter and cwd→batch→WMI fallback chains consistently with WindowsOSProcessFFM. The import trim/additions look right and the shared WtsInfo flows through unchanged. The same setTcb-before-name ordering observation noted on the FFM file applies here too — no need to repeat the comment.

@dbwiddis
dbwiddis force-pushed the migrate-windows-os branch from 60b9018 to f1d3386 Compare April 20, 2026 07:30

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java (1)

263-271: ⚠️ Potential issue | 🟡 Minor

Normalize missing thread data before streaming.

queryMatchingThreads(...) is an abstract native-data hook and the JNA/FFM implementations can propagate an unavailable helper result. If it returns null, getThreadDetails() throws instead of returning an empty thread list.

🛡️ Proposed null-safe fallback
     public List<OSThread> getThreadDetails() {
         Map<Integer, ThreadPerfCounterBlock> threads = tcb == null
                 ? queryMatchingThreads(Collections.singleton(this.getProcessID()))
                 : tcb;
+        if (threads == null || threads.isEmpty()) {
+            return Collections.emptyList();
+        }
         return threads.entrySet().stream().parallel()
                 .filter(entry -> entry.getValue().getOwningProcessID() == this.getProcessID())
                 .map(entry -> createOSThread(getProcessID(), entry.getKey(), this.name, entry.getValue()))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java`
around lines 263 - 271, getThreadDetails currently assumes queryMatchingThreads
(the native-data hook) returns a non-null Map and will NPE if it returns null;
update getThreadDetails so that when tcb is null and queryMatchingThreads(...)
returns null you treat it as an empty Map (or emptyCollection) before streaming.
Concretely, in getThreadDetails check the result of
queryMatchingThreads(Collections.singleton(this.getProcessID())) and replace
null with Collections.emptyMap() (or an empty Map local variable), then proceed
to filter/map using that safe Map (references: getThreadDetails, tcb,
queryMatchingThreads, ThreadPerfCounterBlock, createOSThread).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java`:
- Around line 263-271: getThreadDetails currently assumes queryMatchingThreads
(the native-data hook) returns a non-null Map and will NPE if it returns null;
update getThreadDetails so that when tcb is null and queryMatchingThreads(...)
returns null you treat it as an empty Map (or emptyCollection) before streaming.
Concretely, in getThreadDetails check the result of
queryMatchingThreads(Collections.singleton(this.getProcessID())) and replace
null with Collections.emptyMap() (or an empty Map local variable), then proceed
to filter/map using that safe Map (references: getThreadDetails, tcb,
queryMatchingThreads, ThreadPerfCounterBlock, createOSThread).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4f76109e-bf4f-44ee-844f-267223944078

📥 Commits

Reviewing files that changed from the base of the PR and between 60b9018 and f1d3386.

📒 Files selected for processing (16)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
✅ Files skipped from review due to trivial changes (3)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/registry/WtsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSThread.java
🚧 Files skipped from review as they are similar to previous changes (8)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInstalledAppsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystemJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSThreadJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSThreadFFM.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). (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.
📚 Learning: 2026-04-08T00:58:10.736Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3125
File: oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:131-133
Timestamp: 2026-04-08T00:58:10.736Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceJNA.java` and `oshi-core-java25/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java`, the `getPowerSources()` method intentionally returns a singleton list wrapping a single `getPowerSource("System Battery")` call, and the enumeration loop short-circuits after the first eligible battery pack. This matches the longstanding JNA behavior and is not a bug. A broader refactor to support zero-or-more batteries across both implementations is planned for a later date. Do not flag this as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
📚 Learning: 2026-04-19T01:28:43.529Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:43.529Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.

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-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-18T22:53:49.248Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java:107-193
Timestamp: 2026-04-18T22:53:49.248Z
Learning: In OSHI's `WmiQueryHandlerFFM` (oshi-core-java25) and the JNA `WmiQueryHandler` (oshi-core), the `failedWmiClassNames` cache intentionally keys failures by WMI class name only (not namespace). This is a pre-existing, accepted pattern shared between both implementations. Do not flag this as a bug in future reviews — the project maintainer (dbwiddis) confirmed it does not impact callers and the added complexity of a composite namespace+class key is not warranted.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-18T03:18:03.725Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:03.725Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).

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-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.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/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.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/WindowsOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.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/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.java
📚 Learning: 2026-04-17T23:52:52.926Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java:47-58
Timestamp: 2026-04-17T23:52:52.926Z
Learning: In `oshi-common/src/main/java/oshi/driver/common/windows/perfmon/LoadAverage.java`, the `stopDaemon()` / `startDaemon()` lifecycle pattern (both `public synchronized` instance methods on the same monitor) is intentionally safe: `stopDaemon()` sets `loadAvgThread = null` immediately after `interrupt()`, and `startDaemon()` checks `loadAvgThread != null` under the same lock. Since both methods are synchronized on `this`, they cannot run concurrently, so no double-sampler race is possible. Do not flag this pattern as a race condition.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
📚 Learning: 2026-04-17T23:56:43.867Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java:287-298
Timestamp: 2026-04-17T23:56:43.867Z
Learning: In `oshi-core-java25/src/main/java/oshi/util/platform/windows/PerfDataUtilFFM.java`, the `queryWildcardCounters` method intentionally aborts and returns an empty Pair when any `addEnglishCounter` call fails. This is by design: the returned `Pair<List<String>, Map<T, List<Long>>>` requires strict parallel alignment between the instance list and each per-property value list. Aborting on failure preserves this alignment contract. This is different from `queryCounters` (non-wildcard), which gracefully skips individual failed counters since it returns a flat `Map<T, Long>` with no alignment constraint.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.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:

  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java
📚 Learning: 2026-04-17T23:43:33.461Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3168
File: oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java:0-0
Timestamp: 2026-04-17T23:43:33.461Z
Learning: In `oshi-core-java25/src/main/java/oshi/ffm/windows/PdhFFM.java`, the `PDH_RAW_COUNTER_LAYOUT` Java FFM struct layout must place `FirstValue` at byte offset 16 (not 12). The native MSVC compiler inserts 4 bytes of implicit alignment padding before the `LONGLONG FirstValue` field (after CStatus=4 bytes + FILETIME TimeStamp=8 bytes = 12 bytes), because LONGLONG requires 8-byte alignment. The total struct size is 40 bytes (with trailing padding). Do not use JAVA_LONG_UNALIGNED without explicit padding here, as that incorrectly places FirstValue at offset 12 and causes reads of garbage counter values.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.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/software/os/windows/WindowsOSProcessFFM.java
🔇 Additional comments (8)
oshi-core/src/main/java/oshi/driver/windows/registry/ProcessWtsData.java (1)

21-23: Shared WtsInfo wiring looks good.

The JNA WTS query now depends on the common immutable holder, and the constructor/accessor shape matches the existing call sites.

oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSProcess.java (1)

274-393: Good common/JNA/FFM extension seam.

The thread factory, matching-thread query, and command-line query hooks keep native-specific work out of the shared process base while preserving the common getters/update flow.

oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystem.java (2)

119-120: JNA class renames are wired consistently.

Installed apps, file system, IP stats, and network params now point at their JNA-specific implementations as expected.

Also applies to: 235-241, 444-446


317-326: Process/thread construction now uses the JNA implementations.

The shared WtsInfo map feeds WindowsOSProcessJNA, and the current-thread fallback correctly instantiates WindowsOSThreadJNA.

Also applies to: 367-371

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

152-180: FFM hook implementations align with the common base.

Thread creation, matching-thread lookup, and command-line precedence are implemented through the new abstract hooks without duplicating the shared process getters.


99-118: The public updateAttributes() implementation follows a valid pattern for Windows process queries. Unlike hardware-level FFM operations that manage native resources (like MacHWDiskStoreFFM's CFStringRef/DASessionRef cleanup), the process data helpers (ProcessPerformanceDataFFM.buildProcessMapFromRegistry/buildProcessMapFromPerfCounters, ProcessWtsData.queryProcessWtsMap) gracefully handle errors internally by returning null or empty Maps rather than throwing. This design is consistent with the JNA implementation (WindowsOSProcessJNA.updateAttributes()) and relies on the protected updateAttributes(pcb, wts) to determine final success/failure. No wrapper try-catch is needed here.

			> Likely an incorrect or invalid review comment.
oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java (2)

85-104: JNA attribute refresh follows the new common flow.

The registry-first/perf-counter fallback path now feeds the shared updateAttributes(pcb, wts) implementation and refreshes thread data only when suspended-state detection is enabled.


138-167: JNA-specific hooks are cleanly isolated.

The thread factory, matching-thread query, and command-line query supply the platform details expected by the common base.

- Rename WindowsFileSystem, WindowsInstalledApps,
WindowsInternetProtocolStats,
  WindowsNetworkParams to *JNA suffix in oshi-core
- Extract WindowsOSThread common superclass to oshi-common with shared
fields,
  getters, and state mapping logic; create WindowsOSThreadJNA and
WindowsOSThreadFFM
- Extract WindowsOSProcess common superclass to oshi-common with shared
fields,
  getters, and update logic; make native-dependent methods abstract
- Extract WtsInfo from ProcessWtsData inner class to standalone class in
oshi-common
- Rewrite WindowsOSProcessJNA and WindowsOSProcessFFM to extend common
superclass
- Add getCurrentThread() override to WindowsOperatingSystemFFM
@dbwiddis
dbwiddis force-pushed the migrate-windows-os branch from f1d3386 to 1bab2e4 Compare April 20, 2026 07:41
@dbwiddis
dbwiddis merged commit d1f9454 into oshi:master Apr 20, 2026
16 of 17 checks passed
@dbwiddis
dbwiddis deleted the migrate-windows-os branch April 20, 2026 14:59
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