Skip to content

Migrate Win32LogicalDisk WMI driver to common/JNA/FFM pattern - #3173

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:wmi-driver-migration
Apr 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:wmi-driver-migration

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 18, 2026 •

Copy link
Copy Markdown
Member
  • Pilot migration for WMI drivers, following the same pattern established for PerfMon and registry drivers
  • Moves LogicalDiskProperty enum and shared WHERE clause logic to oshi-common (oshi.driver.common.windows.wmi.Win32LogicalDisk)
  • Creates Win32LogicalDiskJNA in oshi-core with JNA query method
  • Rewrites Win32LogicalDiskFFM in oshi-core-java25 using new enum-based WmiQuery/WmiResult pattern that mirrors the JNA API
  • Creates WbemcliUtilFFM with WmiQuery, WmiResult, and populateRow (mirrors JNA's WbemcliUtil)
  • Creates WmiUtilFFM with type-safe getters (mirrors JNA's WmiUtil)
  • Rewrites WmiQueryHandlerFFM to mirror JNA's WmiQueryHandler API
  • Updates WindowsFileSystemFFM to use enum-based WmiResult
  • Adds WmiComparisonTest in oshi-benchmark comparing JNA vs FFM results
  • Extracts ComparisonAssertions shared test utility from duplicated helpers

Summary by CodeRabbit

  • Tests

    • Added Windows-only WMI comparison tests and a shared ratio-based assertion helper for more consistent test validations.
  • Refactor

    • Consolidated logical-disk WMI handling into a shared driver layer and unified native/query implementations.
    • Added FFM-based WMI query/result utilities with typed accessors and modernized query handling; filesystem volume retrieval now uses the unified WMI framework.
  • Documentation

    • Added package-level Javadoc for WMI driver utilities.
  • Chores

    • Updated module exports, changelog, and test Java compiler settings.

@coderabbitai

coderabbitai Bot commented Apr 18, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Introduced shared Win32LogicalDisk types and WHERE-builder; added FFM WMI query/result primitives and typed accessors; migrated JNA/FFM logical-disk drivers to the common enum; centralized test ratio assertions; added Windows-only WMI comparison tests; exported the new common WMI package.

Changes

Cohort / File(s) Summary
Test Assertion Utilities
oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java, oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java, oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
Added package-private ComparisonAssertions with assertWithinRatio overloads; tests now statically import and use it; removed local helper implementations; simplified one GPU-engine assertion branch.
WMI Comparison Test
oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
Added Windows-only JUnit tests comparing JNA vs FFM Win32_LogicalDisk results (unfiltered, local-only, name-filtered) using property-specific checks and ratio tolerances.
Common WMI Base & Exports
oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java, oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java, oshi-common/src/main/java/module-info.java
Added shared Win32LogicalDisk type: WIN32_LOGICAL_DISK, LogicalDiskProperty enum, and buildWmiClassNameWithWhere(...); added package docs and exported package in module-info.
FFM WMI Primitives
oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java, oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java, oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
Implemented generic WmiQuery<T>/WmiResult<T>, populateRow converting Variants to Java values, typed accessors in WmiUtilFFM, and enum-driven queryWMI(...); refactored COM/init/timeout handling and related APIs.
FFM Logical Disk / Consumers
oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java, oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
Refactored FFM logical-disk to extend common base and return WmiResult<LogicalDiskProperty>; removed local DTO and row-mapper; switched to WmiUtilFFM accessors.
JNA Logical Disk Migration
oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java, oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java, oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java, oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk (removed)
Removed old Windows-package Win32LogicalDisk; added Win32LogicalDiskJNA extending common base; updated callers/tests to use JNA variant while reusing the common enum.
Changelog & Build
CHANGELOG.md, oshi-benchmark/pom.xml
Added changelog entry for Win32LogicalDisk migration and new utilities; set test compiler source/target to Java 25 in benchmark POM.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Tests / Consumer
    participant QH as WmiQueryHandlerFFM
    participant BU as WbemcliUtilFFM
    participant IWO as IWbemClassObjectFFM

    Test->>QH: queryWMI(WmiQuery<T>)
    Note over QH: Build "SELECT <props> FROM <class> [WHERE ...]" using enum
    QH->>IWO: Execute WQL, iterate rows (respecting wmiTimeout)
    IWO-->>QH: row MemorySegment (pObject)
    QH->>BU: populateRow(pObject, arena, WmiResult<T>)
    loop per property
        BU->>IWO: IWbemClassObjectFFM.get(property)
        IWO-->>BU: Variant MemorySegment
        BU->>BU: convert VT -> Java value and store in WmiResult
        BU->>IWO: Variant.clear() (finally)
    end
    BU-->>QH: populated row stored
    QH-->>Test: WmiResult<T>
    Test->>WmiUtilFFM: getString/getUint64/... (result, prop, index)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 I hopped through WMI rows with a twitch and a grin,

enums and WHERE clauses tucked neat in my bin,
FFM turned variants into tidy Java treats,
JNA and tests now compare fields down to the beats,
carrot in paw — merge time, let the gardens win.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.38% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: migrating Win32LogicalDisk WMI driver to follow a common/JNA/FFM architectural pattern across multiple modules.

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

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

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

❤️ Share

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

@codecov

codecov Bot commented Apr 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 47.52852% with 138 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.45%. Comparing base (7536db8) to head (f901820).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...in/java/oshi/util/platform/windows/WmiUtilFFM.java 18.46% 43 Missing and 10 partials ⚠️
...oshi/util/platform/windows/WmiQueryHandlerFFM.java 43.37% 36 Missing and 11 partials ⚠️
...ava/oshi/util/platform/windows/WbemcliUtilFFM.java 58.75% 29 Missing and 4 partials ⚠️
...hi/driver/common/windows/wmi/Win32LogicalDisk.java 76.92% 2 Missing and 1 partial ⚠️
...oshi/software/os/windows/WindowsFileSystemFFM.java 83.33% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3173      +/-   ##
==========================================
- Coverage   58.68%   58.45%   -0.23%     
==========================================
  Files         346      349       +3     
  Lines       17859    18006     +147     
  Branches     3159     3180      +21     
==========================================
+ Hits        10480    10525      +45     
- Misses       5820     5904      +84     
- Partials     1559     1577      +18     
Flag Coverage Δ
linux 25.58% <0.00%> (-0.18%) ⬇️
macos 28.79% <0.00%> (-0.25%) ⬇️
windows 33.34% <47.52%> (-0.03%) ⬇️

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.

Actionable comments posted: 6

Caution

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

⚠️ Outside diff range comments (1)
oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java (1)

183-186: ⚠️ Potential issue | 🟡 Minor

Keep GPU engine comparison to empty/non-empty only.

The exact instance list can change between the JNA and FFM queries, so this assertion can be flaky even when both implementations are correct. Based on learnings, GPU engine PDH instance counts are highly volatile and should only compare whether both results are empty or both are non-empty.

Proposed fix
         Pair<List<String>, Map<GpuEngineProperty, List<Long>>> jna = GpuInformationJNA.queryGpuEngineCounters();
         Pair<List<String>, Map<GpuEngineProperty, List<Long>>> ffm = GpuInformationFFM.queryGpuEngineCounters();
         assertThat(ffm.getA().isEmpty()).as("GPU engine instances empty").isEqualTo(jna.getA().isEmpty());
-        if (!jna.getA().isEmpty()) {
-            assertThat(ffm.getA()).as("GPU engine instances").containsExactlyInAnyOrderElementsOf(jna.getA());
-        }
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`
around lines 183 - 186, The test currently compares GPU engine instance lists
for equality which is flaky; update PerfmonComparisonTest to only assert empty
vs non-empty parity: keep the existing assertion comparing ffm.getA().isEmpty()
to jna.getA().isEmpty(), and remove the conditional block that calls
assertThat(ffm.getA()).containsExactlyInAnyOrderElementsOf(jna.getA()) (and its
surrounding if (!jna.getA().isEmpty()) ), so the test only verifies both are
empty or both non-empty using ffm, jna, and getA().
🧹 Nitpick comments (2)
oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java (1)

93-110: testLogicalDiskNameFilter silently passes when there are no logical disks.

If all.getResultCount() == 0, the test returns without any assertion and is reported as green. On a Windows host that is expected to always have at least one logical disk, an empty result is itself a signal something is wrong. Prefer Assumptions.assumeTrue(all.getResultCount() > 0, ...) so the test is reported as skipped rather than passed, or just let the subsequent isGreaterThan(0) assertion fail.

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

In `@oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java` around
lines 93 - 110, The test testLogicalDiskNameFilter currently returns early when
all.getResultCount() == 0 which makes the test silently pass; replace the early
return with a JUnit assumption so the test is skipped instead of green: import
org.junit.jupiter.api.Assumptions and change the if-check to
Assumptions.assumeTrue(all.getResultCount() > 0, "No logical disks found"); this
keeps the rest of the assertions (including
jna.getResultCount().isGreaterThan(0)) intact and ensures failures are surfaced
correctly.
oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java (1)

36-36: Minor: requireNonNull swallows the root cause.

WmiQueryHandler.createInstance() returns null only after logging a reflective-construction failure for a custom subclass; wrapping it in Objects.requireNonNull(...) raises a bare NPE here with no context for the caller. Consider passing a message (e.g. "WmiQueryHandler.createInstance() returned null") so failures surface meaningfully. Same applies to Win32LogicalDiskFFM.queryLogicalDisk (line 35).

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

In `@oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java` at
line 36, Replace the naked Objects.requireNonNull(...) call so failures surface
with context: capture the result of WmiQueryHandler.createInstance() into a
local variable and use Objects.requireNonNull(instance,
"WmiQueryHandler.createInstance() returned null") before calling queryWMI in
Win32LogicalDiskJNA (the return expression that calls queryWMI) and make the
identical change in Win32LogicalDiskFFM.queryLogicalDisk; this ensures a
descriptive message is included if createInstance() returns null.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`:
- Around line 36-91: The tests compare JNA vs FFM rows by index which can be
flaky because WMI row order is not guaranteed; update testLogicalDiskUnfiltered
and testLogicalDiskLocalOnly to first build maps keyed by NAME using
WmiUtil.getString(jna, LogicalDiskProperty.NAME, i) and
WmiUtilFFM.getString(ffm, LogicalDiskProperty.NAME, i), then iterate the
intersection of keys and assert field-by-field (DESCRIPTION, FILESYSTEM,
VOLUMENAME, PROVIDERNAME, DRIVETYPE via getUint32, ACCESS via getUint16, SIZE
and FREESPACE via getUint64) by looking up values by name, failing fast with
clear messages for missing keys and using assertWithinRatio for FREESPACE
tolerance as before.

In
`@oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java`:
- Around line 37-48: The WQL built by buildWmiClassNameWithWhere has an
operator-precedence bug when both localOnly and nameToMatch are used: the
appended "AND Name=..." only binds to the last OR term. Fix by grouping the
DriveType predicates (either wrap the existing "DriveType = 2 OR DriveType = 3
OR DriveType = 6" in parentheses or replace them with "DriveType IN (2,3,6)") so
the Name filter applies to the entire DriveType expression; additionally,
sanitize or escape embedded double-quotes in nameToMatch before interpolating to
avoid breaking the query.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java`:
- Around line 128-135: The add method currently allows a VT_NULL (or CIM_EMPTY)
value to become the stored type and "lock" the property; change the guards so
you only set vtTypeMap when the incoming vtType is not VT_NULL and only set
cimTypeMap when the incoming cimType is not CIM_EMPTY. Concretely, update the
vtType branch in add(...) to check vtType != WbemcliFFM.VT_NULL (instead of just
!= 0) before calling vtTypeMap.put(...) and only when the existing
vtTypeMap.get(property) is VT_NULL/empty; likewise change the cimType branch to
require cimType != WbemcliFFM.CIM_EMPTY before putting into cimTypeMap so
null/empty variants never overwrite an established non-empty type.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java`:
- Around line 444-445: The setter setWmiTimeout currently assigns any int to the
wmiTimeout field allowing invalid values (0 or < -1) to be used at runtime; add
the same validation used by the static configuration to reject 0 and values less
than -1, and throw an IllegalArgumentException (with a clear message) instead of
assigning an invalid value so future WMI queries cannot be broken by bad runtime
configuration; update setWmiTimeout to validate the incoming wmiTimeout
parameter before setting the field (referencing the setWmiTimeout method and the
wmiTimeout field) and add/adjust tests to cover invalid inputs.
- Around line 107-193: The failure cache currently uses failedWmiClassNames
keyed only by query.getWmiClassName(), which suppresses queries for the same
class in different namespaces; update the cache to include the namespace (e.g.,
use a composite key like query.getNameSpace() + "|" + query.getWmiClassName() or
a small record/tuple) and change all checks and adds (the contains check near
the top and the failedWmiClassNames.add(...) calls in the catch and error paths)
to use this composite key so failures are scoped by namespace as well as class.

In `@oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java`:
- Around line 196-205: The getInt helper currently only accepts VariantFFM.VT_I4
and throws for other valid integer VT types; update getInt (used by populateRow)
to accept VariantFFM.VT_INT, VT_I2, and VT_UI1 in addition to VT_I4 and convert
the stored Object to an int using Number.intValue() (or similar safe casting)
instead of a direct cast to (int), keeping the existing ClassCastException for
unsupported vt types and retaining the error message format that references
property.name(), result.getCIMType(property), and result.getVtType(property).

---

Outside diff comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`:
- Around line 183-186: The test currently compares GPU engine instance lists for
equality which is flaky; update PerfmonComparisonTest to only assert empty vs
non-empty parity: keep the existing assertion comparing ffm.getA().isEmpty() to
jna.getA().isEmpty(), and remove the conditional block that calls
assertThat(ffm.getA()).containsExactlyInAnyOrderElementsOf(jna.getA()) (and its
surrounding if (!jna.getA().isEmpty()) ), so the test only verifies both are
empty or both non-empty using ffm, jna, and getA().

---

Nitpick comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`:
- Around line 93-110: The test testLogicalDiskNameFilter currently returns early
when all.getResultCount() == 0 which makes the test silently pass; replace the
early return with a JUnit assumption so the test is skipped instead of green:
import org.junit.jupiter.api.Assumptions and change the if-check to
Assumptions.assumeTrue(all.getResultCount() > 0, "No logical disks found"); this
keeps the rest of the assertions (including
jna.getResultCount().isGreaterThan(0)) intact and ensures failures are surfaced
correctly.

In `@oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java`:
- Line 36: Replace the naked Objects.requireNonNull(...) call so failures
surface with context: capture the result of WmiQueryHandler.createInstance()
into a local variable and use Objects.requireNonNull(instance,
"WmiQueryHandler.createInstance() returned null") before calling queryWMI in
Win32LogicalDiskJNA (the return expression that calls queryWMI) and make the
identical change in Win32LogicalDiskFFM.queryLogicalDisk; this ensures a
descriptive message is included if createInstance() returns null.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cfd9e08f-b398-4fcc-b0db-bafc66f87ea4

📥 Commits

Reviewing files that changed from the base of the PR and between 7536db8 and acf62e8.

📒 Files selected for processing (16)
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.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: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (11)
📚 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/driver/common/windows/wmi/package-info.java
  • oshi-common/src/main/java/module-info.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.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/driver/common/windows/wmi/package-info.java
  • oshi-common/src/main/java/module-info.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/wmi/package-info.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.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-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.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/WindowsFileSystem.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.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/WindowsFileSystem.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/WindowsFileSystem.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/WindowsFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.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/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
🔇 Additional comments (5)
oshi-common/src/main/java/module-info.java (1)

26-26: LGTM: shared WMI package is exported.

This aligns with the common-driver split and allows the JNA/FFM modules to consume the shared logical disk types.

oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java (1)

17-35: LGTM: shared ratio assertion helper is clean.

The zero handling and centralized failure messages make the comparison tests easier to maintain.

oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java (1)

5-8: LGTM: package documentation matches the new shared WMI layer.

Clear and consistent with the JNA/FFM split.

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

218-218: LGTM: Windows filesystem now consumes the JNA logical disk driver explicitly.

The common enum plus JNA-specific query entry point fits the migration pattern.

oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java (1)

8-8: LGTM: shared assertion import removes duplicated helper logic.

This keeps ratio-based comparison behavior consistent across benchmark tests.

@dbwiddis
dbwiddis force-pushed the wmi-driver-migration branch from acf62e8 to bbd7fb6 Compare April 18, 2026 22:49

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java (2)

444-446: ⚠️ Potential issue | 🟡 Minor

setWmiTimeout still accepts invalid values at runtime.

The static block at lines 41-43 rejects 0 and values < -1 for globalTimeout, but the runtime setter installs any int unchecked. Bad values leaking in here will either make subsequent IEnumWbemClassObjectFFM.next(..., wmiTimeout, ...) calls return immediately (0) or behave unpredictably (< -1). Mirror the static validation here and throw IllegalArgumentException for the same invalid inputs.

🤖 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/util/platform/windows/WmiQueryHandlerFFM.java`
around lines 444 - 446, The setter setWmiTimeout currently assigns any int to
the this.wmiTimeout field; mirror the static block’s validation by rejecting 0
and any value < -1 and instead throw IllegalArgumentException for those inputs.
Update setWmiTimeout(int wmiTimeout) to validate the argument (allowing -1 and
positive values only), throw IllegalArgumentException with a clear message on
invalid values, and otherwise assign to this.wmiTimeout so subsequent
IEnumWbemClassObjectFFM.next(..., wmiTimeout, ...) calls don’t receive invalid
timeouts.

109-193: ⚠️ Potential issue | 🟡 Minor

Failed-query cache key still omits namespace.

The new enum-typed queryWMI(WmiQuery<T>) path caches and checks failures using only query.getWmiClassName(). Because WmiQuery supports a custom namespace (see WbemcliUtilFFM.WmiQuery#setNameSpace), a failure for class Foo in one namespace will permanently suppress a legitimate query for class Foo in a different namespace on the same handler instance. The fix is the same as previously proposed — include the namespace in the cache key for both the contains check and every failedWmiClassNames.add(...) call in this method.

🤖 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/util/platform/windows/WmiQueryHandlerFFM.java`
around lines 109 - 193, The cache key for failedWmiClassNames in the enum-typed
query path omits namespace; update the queryWMI(WmiQuery<T>) method so the
contains check and every failedWmiClassNames.add(...) call use a composite key
that includes query.getNameSpace() and query.getWmiClassName() (e.g., namespace
+ delimiter + className) or call a new helper like
makeFailedKey(query.getNameSpace(), query.getWmiClassName()), ensuring all
occurrences in this method (the initial if (failedWmiClassNames.contains(...))
check and each place that adds to failedWmiClassNames) are changed to the
composite key.
🧹 Nitpick comments (1)
oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java (1)

107-302: Consider extracting the shared COM/query scaffolding.

The two queryWMI overloads (lines 107-202 and 230-302) now duplicate a substantial block: COM init, IWbemLocatorFFM.create, connectServer, CoSetProxyBlanket, execQuery, the next loop, nested safeRelease finally chains, and matching failure-cache handling. The only real differences are (a) how the WQL string is built and (b) how each row is turned into a result. A single private helper taking the WQL builder and a row-consumer would eliminate ~90 lines of copy/paste and keep future fixes (e.g., the namespace cache-key fix above) in one place.

🤖 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/util/platform/windows/WmiQueryHandlerFFM.java`
around lines 107 - 302, Extract the duplicated COM/query scaffolding into a
private helper (e.g., executeWmiQuery or runWmiQuery) that accepts namespace,
wmiClassName, a Supplier<String> or Function<String,String> to build the WQL
string (used by the enum-based query and the generic query) and a row handler
(for the enum variant use WbemcliUtilFFM.populateRow via a lambda, for the
generic variant pass the TriConsumer rowProcessor). Move COM init/unInit,
IWbemLocatorFFM.create, IWbemLocatorFFM.connectServer,
Ole32FFM.CoSetProxyBlanket, IWbemServicesFFM.execQuery, the
IEnumWbemClassObjectFFM.next loop, IUnknownFFM.safeRelease finally chains, and
failedWmiClassNames handling into that helper and have both queryWMI overloads
call it with their specific WQL builder and row processor.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java`:
- Around line 165-202: The switch in WbemcliUtilFFM currently drops unhandled
VARIANTs (e.g., VT_I8, VT_UI8, VT_UI2, VT_UI4, VT_I1) while recording their real
vt in vtTypeMap; update the switch to explicitly handle at least VT_I8 and
VT_UI8 by calling the appropriate oshi.ffm.windows.com.VariantFFM
long/unsigned-long getters and passing those Long values into result.add (use
the same vt constant for signed/unsigned 64-bit cases), add handlers for
VT_UI2/VT_UI4/VT_I1 to convert to int where appropriate using VariantFFM
getters, and change the default branch to call
result.add(oshi.ffm.windows.com.VariantFFM.VT_EMPTY, cimType, property, null) so
unknown types store null without locking the real vt in vtTypeMap.

---

Duplicate comments:
In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java`:
- Around line 444-446: The setter setWmiTimeout currently assigns any int to the
this.wmiTimeout field; mirror the static block’s validation by rejecting 0 and
any value < -1 and instead throw IllegalArgumentException for those inputs.
Update setWmiTimeout(int wmiTimeout) to validate the argument (allowing -1 and
positive values only), throw IllegalArgumentException with a clear message on
invalid values, and otherwise assign to this.wmiTimeout so subsequent
IEnumWbemClassObjectFFM.next(..., wmiTimeout, ...) calls don’t receive invalid
timeouts.
- Around line 109-193: The cache key for failedWmiClassNames in the enum-typed
query path omits namespace; update the queryWMI(WmiQuery<T>) method so the
contains check and every failedWmiClassNames.add(...) call use a composite key
that includes query.getNameSpace() and query.getWmiClassName() (e.g., namespace
+ delimiter + className) or call a new helper like
makeFailedKey(query.getNameSpace(), query.getWmiClassName()), ensuring all
occurrences in this method (the initial if (failedWmiClassNames.contains(...))
check and each place that adds to failedWmiClassNames) are changed to the
composite key.

---

Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java`:
- Around line 107-302: Extract the duplicated COM/query scaffolding into a
private helper (e.g., executeWmiQuery or runWmiQuery) that accepts namespace,
wmiClassName, a Supplier<String> or Function<String,String> to build the WQL
string (used by the enum-based query and the generic query) and a row handler
(for the enum variant use WbemcliUtilFFM.populateRow via a lambda, for the
generic variant pass the TriConsumer rowProcessor). Move COM init/unInit,
IWbemLocatorFFM.create, IWbemLocatorFFM.connectServer,
Ole32FFM.CoSetProxyBlanket, IWbemServicesFFM.execQuery, the
IEnumWbemClassObjectFFM.next loop, IUnknownFFM.safeRelease finally chains, and
failedWmiClassNames handling into that helper and have both queryWMI overloads
call it with their specific WQL builder and row processor.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2e446130-ecb9-4ed9-a426-57ce280ec9f7

📥 Commits

Reviewing files that changed from the base of the PR and between acf62e8 and bbd7fb6.

📒 Files selected for processing (17)
  • CHANGELOG.md
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
✅ Files skipped from review due to trivial changes (7)
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-common/src/main/java/module-info.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.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). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (10)
📚 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-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.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-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.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/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
🔇 Additional comments (3)
oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java (1)

8-8: LGTM!

Clean extraction — the static import replaces the removed local assertWithinRatio helpers, and the shared ComparisonAssertions class provides matching (long, long, double, String) and (double, double, double, String) overloads so existing call sites (e.g., line 197) resolve unchanged.

oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java (1)

20-37: LGTM — clean migration to the shared common class.

Win32LogicalDiskFFM now reduces to a thin FFM-specific façade that reuses the shared WHERE-clause logic and the new enum-driven WmiQuery/WmiResult infrastructure. The Objects.requireNonNull guard is defensive (since createInstance() never returns null today), but it is harmless and future-proof.

oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java (1)

155-206: No action needed. The VariantFFM.clear() method already guards against NULL variants with an explicit check (if (variant == null || variant.equals(MemorySegment.NULL))) before invoking the native VariantClear downcall. When get() fails and returns a NULL variant, the finally block safely calls clear() which returns early without crashing.

			> Likely an incorrect or invalid review comment.

@dbwiddis
dbwiddis force-pushed the wmi-driver-migration branch 2 times, most recently from 32290f1 to 867ae44 Compare April 18, 2026 23:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

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

Inline comments:
In
`@oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java`:
- Around line 44-46: The WQL WHERE string-building in Win32LogicalDisk currently
only escapes double quotes; modify the code that appends the Name filter (the
wmiClassName construction in class Win32LogicalDisk) to first escape
backslashes, then escape double quotes and single quotes in nameToMatch (in that
order) before appending, so all WQL string-literal special characters are
handled; ensure the replacements are applied to nameToMatch prior to building
the " WHERE/ AND Name="..." fragment so backslashes don’t undo subsequent
escapes.

In
`@oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java`:
- Around line 46-47: The wmiTimeout field in WmiQueryHandlerFFM is updated via
setWmiTimeout() and read by query loops without synchronization, so change its
declaration to be volatile to ensure visibility across threads; keep the
existing synchronized handling for comThreading as-is, and only update the field
declaration for wmiTimeout (referenced by wmiTimeout and setWmiTimeout() in
class WmiQueryHandlerFFM) to use the volatile modifier so runtime timeout
updates are reliably seen by other threads.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 793821c4-cc7e-4207-aad4-10510b8505ad

📥 Commits

Reviewing files that changed from the base of the PR and between 32290f1 and 867ae44.

📒 Files selected for processing (18)
  • CHANGELOG.md
  • oshi-benchmark/pom.xml
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
✅ Files skipped from review due to trivial changes (6)
  • oshi-benchmark/pom.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
🚧 Files skipped from review as they are similar to previous changes (4)
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.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). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (17)
📓 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-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-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.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-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.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/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.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/wmi/Win32LogicalDisk.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

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

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.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/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
🔇 Additional comments (8)
oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java (1)

17-35: LGTM: shared ratio assertion is clear and reusable.

The zero handling and absolute min/max ratio comparison preserve the intended tolerance semantics while removing duplicated test helpers.

oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java (1)

128-137: LGTM: row population preserves usable type metadata.

Skipping null/empty VT values before locking the property type, plus falling back to VT_EMPTY for unknown variants, keeps later rows able to establish a supported type.

Also applies to: 155-223

oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java (2)

8-8: LGTM: shared tolerance helper removes duplicate test code.

The static import keeps call sites readable while centralizing the ratio edge-case handling.

Also applies to: 193-198


178-184: LGTM: GPU engine comparison avoids volatile instance lists.

Checking only whether both implementations return empty/non-empty results avoids flaky count or instance-name assertions. Based on learnings, GPU engine PDH instance counts are highly volatile and the only reliable assertion is that both are empty or both are non-empty.

oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java (1)

33-38: LGTM: JNA driver follows the shared query pattern.

The method reuses the common WHERE builder and returns the enum-keyed JNA WmiResult without extra translation.

oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java (1)

40-42: LGTM: local-drive predicates are grouped correctly.

The parentheses ensure a later AND Name=... filter applies to the whole DriveType expression.

oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java (2)

40-64: LGTM: name-keyed comparison avoids WMI row-order assumptions.

Mapping both result sets by NAME before comparing properties makes the test more stable and produces clearer failures.

Also applies to: 103-117


67-101: LGTM: filtered/local logical-disk scenarios are covered.

The local-only and name-filter cases exercise the shared WHERE builder from both JNA and FFM paths.

@dbwiddis
dbwiddis force-pushed the wmi-driver-migration branch from 867ae44 to cefeb1c Compare April 18, 2026 23:22

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java`:
- Around line 116-123: getUint64 currently only handles CIM_UINT64 values stored
as VT_BSTR, but populateRow can store VT_I8/VT_UI8 as Long, so update getUint64
to accept numeric Long/Number values too: in
WbemcliUtilFFM.getUint64(WbemcliUtilFFM.WmiResult<T> result, T property, int
index) after retrieving Object o, if o is an instance of Number (or Long) return
((Number)o).longValue(); otherwise keep the existing branch that checks
result.getCIMType(property) == WbemcliFFM.CIM_UINT64 &&
result.getVtType(property) == VariantFFM.VT_BSTR and parse the String with
ParseUtil.parseLongOrDefault; leave the null check and default 0L behavior
unchanged so both string and numeric variants populated by populateRow are
readable.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 374ff8b7-3150-4a5c-b9e3-7a4ec0a64e85

📥 Commits

Reviewing files that changed from the base of the PR and between 867ae44 and cefeb1c.

📒 Files selected for processing (18)
  • CHANGELOG.md
  • oshi-benchmark/pom.xml
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
✅ Files skipped from review due to trivial changes (7)
  • oshi-benchmark/pom.xml
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-common/src/main/java/module-info.java
  • CHANGELOG.md
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.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, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (17)
📓 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java:44-46
Timestamp: 2026-04-18T23:21:41.153Z
Learning: In OSHI's `Win32LogicalDisk.buildWmiClassNameWithWhere` (oshi-common), the `nameToMatch` parameter is always internally controlled (e.g., a drive name from a prior WMI query result), not arbitrary user input. Do not flag missing WQL escape sequences (backslash, single-quote) as a bug — the project maintainer (dbwiddis) confirmed only the existing double-quote escaping is needed.
📚 Learning: 2026-04-18T23:21:41.153Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java:44-46
Timestamp: 2026-04-18T23:21:41.153Z
Learning: In OSHI's `Win32LogicalDisk.buildWmiClassNameWithWhere` (oshi-common), the `nameToMatch` parameter is always internally controlled (e.g., a drive name from a prior WMI query result), not arbitrary user input. Do not flag missing WQL escape sequences (backslash, single-quote) as a bug — the project maintainer (dbwiddis) confirmed only the existing double-quote escaping is needed.

Applied to files:

  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.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-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java

- Move LogicalDiskProperty enum and shared WHERE clause logic to
  oshi-common (oshi.driver.common.windows.wmi.Win32LogicalDisk)
- Create Win32LogicalDiskJNA in oshi-core with JNA query method
- Rewrite Win32LogicalDiskFFM in oshi-core-java25 using new
  WbemcliUtilFFM.WmiQuery/WmiResult pattern (mirrors JNA API)
- Create WbemcliUtilFFM with WmiQuery, WmiResult, and populateRow
- Create WmiUtilFFM with getString/getUint64/getUint32/getUint16 helpers
- Rewrite WmiQueryHandlerFFM to mirror JNA WmiQueryHandler API
- Update WindowsFileSystemFFM to use enum-based WmiResult
- Add WmiComparisonTest in oshi-benchmark comparing JNA vs FFM results
- Extract ComparisonAssertions shared test utility from duplicated
helpers
- Fix WHERE clause operator precedence when localOnly + nameToMatch
- Fix VT_NULL/CIM_EMPTY type locking in WbemcliUtilFFM.WmiResult.add
- Accept VT_INT/VT_I2/VT_UI1 in WmiUtilFFM.getInt via Number.intValue()
- Add descriptive messages to requireNonNull in driver query methods
- Use map-based row comparison in WmiComparisonTest for nondeterministic
order
- Remove flaky GPU engine instance list comparison in
PerfmonComparisonTest
@dbwiddis
dbwiddis force-pushed the wmi-driver-migration branch from cefeb1c to f901820 Compare April 18, 2026 23:31

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

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

Inline comments:
In `@oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`:
- Around line 93-100: The current assertion only checks row 0 and can pass if
filtering is ignored; after obtaining results from
Win32LogicalDiskJNA.queryLogicalDisk and Win32LogicalDiskFFM.queryLogicalDisk
and asserting getResultCount() > 0, iterate over all result indices (0 ..
getResultCount()-1) and assert for each index that the NAME equals firstName for
both result sets: use WmiUtilFFM.getString(ffm, LogicalDiskProperty.NAME, i) for
the FFM results and the equivalent JNA accessor for the JNA results (e.g.,
WmiUtilJNA.getString or the JNA result's name getter) to ensure every returned
row is actually filtered to firstName.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

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

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 26390916-8b8d-49f5-a2fd-46cc8357da8f

📥 Commits

Reviewing files that changed from the base of the PR and between 867ae44 and f901820.

📒 Files selected for processing (18)
  • CHANGELOG.md
  • oshi-benchmark/pom.xml
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
💤 Files with no reviewable changes (1)
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDisk.java
✅ Files skipped from review due to trivial changes (8)
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/package-info.java
  • oshi-common/src/main/java/module-info.java
  • oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java
  • CHANGELOG.md
  • oshi-benchmark/pom.xml
  • oshi-core-java25/src/main/java/oshi/software/os/windows/WindowsFileSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java
  • oshi-core/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskJNA.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiUtilFFM.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). (1)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (18)
📓 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.
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java:44-46
Timestamp: 2026-04-18T23:21:41.153Z
Learning: In OSHI's `Win32LogicalDisk.buildWmiClassNameWithWhere` (oshi-common), the `nameToMatch` parameter is always internally controlled (e.g., a drive name from a prior WMI query result), not arbitrary user input. Do not flag missing WQL escape sequences (backslash, single-quote) as a bug — the project maintainer (dbwiddis) confirmed only the existing double-quote escaping is needed.
📚 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-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.

Applied to files:

  • oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java
📚 Learning: 2026-04-18T23:21:41.153Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3173
File: oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32LogicalDisk.java:44-46
Timestamp: 2026-04-18T23:21:41.153Z
Learning: In OSHI's `Win32LogicalDisk.buildWmiClassNameWithWhere` (oshi-common), the `nameToMatch` parameter is always internally controlled (e.g., a drive name from a prior WMI query result), not arbitrary user input. Do not flag missing WQL escape sequences (backslash, single-quote) as a bug — the project maintainer (dbwiddis) confirmed only the existing double-quote escaping is needed.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.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/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.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/driver/windows/wmi/Win32LogicalDiskFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-04-11T05:51:52.684Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:52.684Z
Learning: In OSHI's `LinuxGpuStats` (oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGpuStats.java), the abstract `nvml*` methods (nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) are contractually expected to return `-1` (long or double) on failure. The base class applies `if (val >= 0)` guards before using any NVML result and falls through to sysfs/hwmon paths when negative. Subclasses (LinuxGpuStatsJNA, LinuxGpuStatsFFM) correctly pass through the -1 sentinel unchanged — do not flag this as a missing clamp or contract violation.

Applied to files:

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

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.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/util/platform/windows/WbemcliUtilFFM.java
🔇 Additional comments (10)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)

8-8: LGTM — shared ratio assertions are a clean consolidation.

Routing these calls through ComparisonAssertions.assertWithinRatio keeps the comparison behavior consistent across benchmark tests.

oshi-benchmark/src/test/java/oshi/comparison/ComparisonAssertions.java (1)

12-35: LGTM — the helper covers the important edge cases.

The zero handling and symmetric min / max comparison make the shared assertion safe for the existing tolerance-style comparisons.

oshi-core-java25/src/main/java/oshi/driver/windows/wmi/Win32LogicalDiskFFM.java (1)

32-36: LGTM — this matches the common/JNA query pattern.

The method now builds the shared enum-based query and delegates to the typed FFM handler, keeping the FFM driver aligned with Win32LogicalDiskJNA.

oshi-core-java25/src/main/java/oshi/util/platform/windows/WmiQueryHandlerFFM.java (3)

38-56: LGTM — mutable query state is handled safely here.

wmiTimeout and securityInitialized are visible across threads, while comThreading remains behind synchronized accessors.


107-201: LGTM — the enum-based WMI path is cohesive and resource-safe.

The query construction, row population, COM release ordering, and failure handling are consistent with the new WbemcliUtilFFM.WmiQuery / WmiResult model.


329-356: LGTM — COM initialization keeps the fallback threading flow intact.

The retry through switchComThreadingFrom(...) and process-wide security initialization handling look aligned with the intended handler behavior.

oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java (1)

103-117: LGTM — keying by NAME avoids row-order flakiness.

The map helpers make the JNA/FFM comparison independent of WMI result ordering.

oshi-core-java25/src/main/java/oshi/util/platform/windows/WbemcliUtilFFM.java (3)

35-79: LGTM — the query wrapper mirrors the JNA shape cleanly.

The namespace, class name, and enum property type are captured with a minimal API suitable for the typed handler.


86-144: LGTM — result typing avoids the null-first-row trap.

add(...) only establishes VT/CIM metadata from meaningful non-empty values, while still preserving row-aligned property values.


155-224: LGTM — VARIANT extraction is broad and fails soft for unsupported types.

The integer-family coverage and VT_EMPTY default keep downstream typed getters from being locked to an unsupported VARIANT type.

@dbwiddis
dbwiddis merged commit 828817d into oshi:master Apr 18, 2026
16 of 17 checks passed
@dbwiddis
dbwiddis deleted the wmi-driver-migration branch April 18, 2026 23:41
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