Skip to content

Introduce common WmiQueryExecutor interface and WmiUtil - #3266

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:refactor/wmi-common-interface
May 18, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:refactor/wmi-common-interface

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 18, 2026 •

Copy link
Copy Markdown
Member

Partial fix for #3257

Adds shared WMI infrastructure to oshi-common enabling consolidation of the 21 duplicated JNA/FFM WMI driver pairs.

New in oshi-common:

  • WmiQuery<T> — common query class
  • WmiResult<T> — common result interface
  • WmiQueryExecutor — common handler interface
  • WmiConstants — CIM/VT type constants
  • WmiUtil — typed result extraction helpers (getString, getUint32, getUint64, etc.)

New adapters:

  • WmiQueryExecutorJNA (oshi-core) — wraps WmiQueryHandler
  • WmiQueryExecutorFFM (oshi-core-ffm) — wraps WmiQueryHandlerFFM

Proof of concept:

  • Win32DiskDrive.queryDiskDrive(WmiQueryExecutor) added to the common base class

The existing WmiQueryHandler class and its extensibility pattern (used in oshi-demo for COM init customization) are preserved unchanged. A follow-up PR will migrate the remaining 20 drivers and their callers.

Summary by CodeRabbit

  • Refactor

    • Standardized Windows WMI query infrastructure for more consistent, maintainable system data retrieval.
    • Introduced common result and executor abstractions enabling multiple backend implementations.
  • New Features

    • Added robust, typed utilities for extracting and converting WMI values (strings, dates, integers, floats, references).
    • Improved disk drive query pathway for more reliable hardware reporting.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f20161d4-4124-43c0-91e5-cedcbe87ba72

📥 Commits

Reviewing files that changed from the base of the PR and between 5c8376e and 282df4f.

📒 Files selected for processing (8)
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryExecutorFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryExecutorJNA.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryExecutorFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java
  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryExecutorJNA.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 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/WmiResult.java
🔇 Additional comments (1)
oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java (1)

1-45: LGTM!


📝 Walkthrough

Walkthrough

This PR adds a common Windows WMI abstraction: type constants, WmiQuery/WmiResult/WmiQueryExecutor contracts, WmiUtil typed accessors, platform adapters for JNA/FFM, and a Win32DiskDrive helper that uses the new query executor.

Changes

Common WMI Query Abstraction

Layer / File(s) Summary
WMI Query/Result Contracts and Type Constants
oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java, oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java, oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java, oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQueryExecutor.java
WmiConstants defines WMI/CIM and COM variant type identifiers. WmiQuery encapsulates query definitions (namespace, class, property enum). WmiResult specifies the result handling interface. WmiQueryExecutor defines the query execution contract for platform implementations.
WMI Type Conversion and Query Utilities
oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java
WmiUtil provides namespace constants, query-to-string builder, and typed accessor methods for extracting and validating WMI property values (string, datetime, references, unsigned/signed integers, float) with CIM/VT type checking and sensible defaults.
Platform-Specific Executor Implementations
oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryExecutorJNA.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryExecutorFFM.java
WmiQueryExecutorJNA and WmiQueryExecutorFFM each implement WmiQueryExecutor by adapting their platform handlers and wrapping platform-specific results into the common WmiResult interface.
Win32DiskDrive Query Helper
oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java
Win32DiskDrive.queryDiskDrive() constructs a WmiQuery for Win32_DiskDrive with DiskDriveProperty and delegates execution to WmiQueryExecutor, demonstrating the new abstraction pattern.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related issues

Possibly related PRs

  • oshi/oshi#3173: Uses the new common WMI abstractions for Win32LogicalDisk migration to the enum-based query/result pattern.
  • oshi/oshi#3174: Builds JNA/FFM driver query entrypoints and tests on top of the common WmiQuery/WmiResult model.

Poem

🐰 In fields of code the rabbit hops with glee,
WMI queries sing in tidy harmony.
Constants, queries, results all bound in thread,
Adapters join the orchestra ahead.
Hooray — the disk drive helper hums with me!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 63.27% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and concisely summarizes the main change: introducing a common WmiQueryExecutor interface and WmiUtil utilities. It captures the primary objective without being vague or overly generic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (4)
oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java (1)

35-39: ⚡ Quick win

Consider validating constructor parameters.

The constructor accepts three parameters but does not validate them for null. If callers pass null values, errors will occur later during query execution rather than at construction time.

🛡️ Proposed validation
 public WmiQuery(String nameSpace, String wmiClassName, Class<T> propertyEnum) {
+    if (nameSpace == null || wmiClassName == null || propertyEnum == null) {
+        throw new IllegalArgumentException("WmiQuery parameters cannot be null");
+    }
     this.nameSpace = nameSpace;
     this.wmiClassName = wmiClassName;
     this.propertyEnum = propertyEnum;
 }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java`
around lines 35 - 39, Validate constructor parameters in WmiQuery by checking
nameSpace, wmiClassName, and propertyEnum for null and throwing a clear
exception (e.g., NullPointerException or IllegalArgumentException) if any are
null; update the WmiQuery(String nameSpace, String wmiClassName, Class<T>
propertyEnum) constructor to perform these non-null checks and assign only after
validation so callers fail fast with a descriptive message identifying the
missing parameter.
oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java (2)

87-93: ⚡ Quick win

getDateString returns empty string for UNIX_EPOCH.

Lines 89-91 return an empty string when the parsed datetime equals Constants.UNIX_EPOCH. This is consistent with the pattern of returning empty strings for null values, but the Javadoc at line 85 says "The stored value if non-null, an empty-string otherwise" which doesn't mention the epoch case. Consider updating the Javadoc to clarify this behavior.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java` around
lines 87 - 93, Update the Javadoc for WmiUtil.getDateString to explicitly state
that it returns the stored value if non-null and non-epoch, and returns an empty
string for null or when the parsed datetime equals Constants.UNIX_EPOCH;
reference the method name getDateString and the helper getDateTime plus
Constants.UNIX_EPOCH so reviewers can locate the logic that treats the epoch as
an empty value.

50-59: ⚡ Quick win

Add validation to handle empty property enums in queryToString.

The method accesses props[0] at line 53 without verifying the enum has constants. If a WmiQuery is instantiated with an empty enum (where getEnumConstants() returns an empty array), this will throw ArrayIndexOutOfBoundsException. Although all existing enums in the codebase contain at least one constant, this defensive check would prevent potential issues from future code changes.

Suggested fix location
public static <T extends Enum<T>> String queryToString(WmiQuery<T> query) {
    T[] props = query.getPropertyEnum().getEnumConstants();
    if (props.length == 0) {
        throw new IllegalArgumentException("Property enum must contain at least one constant");
    }
    StringBuilder sb = new StringBuilder("SELECT ");
    sb.append(props[0].name());
    for (int i = 1; i < props.length; i++) {
        sb.append(',').append(props[i].name());
    }
    sb.append(" FROM ").append(query.getWmiClassName());
    return sb.toString();
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java` around
lines 50 - 59, The method queryToString in WmiUtil reads props[0] without
checking that the enum returned by query.getPropertyEnum().getEnumConstants() is
non-empty; add a defensive check that the array length is > 0 and throw a clear
IllegalArgumentException (or similar) if empty so we avoid
ArrayIndexOutOfBoundsException; update queryToString to retrieve T[] props =
query.getPropertyEnum().getEnumConstants(), validate props.length > 0, then
proceed to build the SELECT... FROM using props[0].name() and the existing loop.
oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java (1)

21-28: ⚡ Quick win

Consider documenting behavior for invalid indices.

The getValue method does not specify what happens when index is out of bounds (e.g., negative or >= getResultCount()). Documenting the expected behavior (throw exception, return null, etc.) would help implementers and callers understand the contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java`
around lines 21 - 28, Update the Javadoc for WmiResult#getValue(T property, int
index) to document behavior for invalid indices: state that index must be in the
range 0 .. getResultCount()-1 and that passing a negative index or an index >=
getResultCount() will result in an IndexOutOfBoundsException (or explicitly
state null-return behavior if you prefer that contract instead), and mention
that callers should use getResultCount() to validate indices before calling
getValue.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java`:
- Around line 35-39: Validate constructor parameters in WmiQuery by checking
nameSpace, wmiClassName, and propertyEnum for null and throwing a clear
exception (e.g., NullPointerException or IllegalArgumentException) if any are
null; update the WmiQuery(String nameSpace, String wmiClassName, Class<T>
propertyEnum) constructor to perform these non-null checks and assign only after
validation so callers fail fast with a descriptive message identifying the
missing parameter.

In `@oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java`:
- Around line 21-28: Update the Javadoc for WmiResult#getValue(T property, int
index) to document behavior for invalid indices: state that index must be in the
range 0 .. getResultCount()-1 and that passing a negative index or an index >=
getResultCount() will result in an IndexOutOfBoundsException (or explicitly
state null-return behavior if you prefer that contract instead), and mention
that callers should use getResultCount() to validate indices before calling
getValue.

In `@oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java`:
- Around line 87-93: Update the Javadoc for WmiUtil.getDateString to explicitly
state that it returns the stored value if non-null and non-epoch, and returns an
empty string for null or when the parsed datetime equals Constants.UNIX_EPOCH;
reference the method name getDateString and the helper getDateTime plus
Constants.UNIX_EPOCH so reviewers can locate the logic that treats the epoch as
an empty value.
- Around line 50-59: The method queryToString in WmiUtil reads props[0] without
checking that the enum returned by query.getPropertyEnum().getEnumConstants() is
non-empty; add a defensive check that the array length is > 0 and throw a clear
IllegalArgumentException (or similar) if empty so we avoid
ArrayIndexOutOfBoundsException; update queryToString to retrieve T[] props =
query.getPropertyEnum().getEnumConstants(), validate props.length > 0, then
proceed to build the SELECT... FROM using props[0].name() and the existing loop.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a095e3d3-7c12-4a6f-8da2-291cfd98d73b

📥 Commits

Reviewing files that changed from the base of the PR and between 352acbc and acbe7d5.

📒 Files selected for processing (8)
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryExecutorFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryExecutorJNA.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). (11)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 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/WmiQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java
🔇 Additional comments (5)
oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java (1)

1-40: LGTM!

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

1-88: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryExecutorFFM.java (1)

1-86: LGTM!

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

52-55: ⚡ Quick win

COM initialization is properly handled by all callers. The Javadoc requirement that "User should have already initialized COM" at line 49 is correctly enforced and followed throughout the codebase. All call sites either explicitly initialize COM or receive handlers that are pre-initialized. This is consistent with the parallel implementations in Win32DiskDriveJNA and Win32DiskDriveFFM, which use the same pattern.

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

43-45: 💤 Low value

The static createInstance() method is already well-documented; no changes required.

The interface already includes comprehensive Javadoc (lines 35-42) that clearly explains the factory contract: it directs callers to platform-specific implementations (WmiQueryExecutorJNA for JNA, WmiQueryExecutorFFM for FFM). This static method serves as a documented entry point that defines the factory pattern contract for the interface. Keeping it provides valuable documentation of the expected usage pattern and is consistent with the architecture.

@codecov

codecov Bot commented May 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.15%. Comparing base (352acbc) to head (282df4f).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...shi/util/platform/windows/WmiQueryExecutorJNA.java 0.00% 18 Missing ⚠️
.../java/oshi/driver/common/windows/wmi/WmiQuery.java 0.00% 10 Missing ⚠️
...oshi/driver/common/windows/wmi/Win32DiskDrive.java 0.00% 2 Missing ⚠️
...hi/driver/common/windows/wmi/WmiQueryExecutor.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3266      +/-   ##
============================================
- Coverage     74.36%   74.15%   -0.22%     
  Complexity       73       73              
============================================
  Files           401      404       +3     
  Lines         16039    16070      +31     
  Branches       2555     2556       +1     
============================================
- Hits          11928    11916      -12     
- Misses         2626     2661      +35     
- Partials       1485     1493       +8     
Flag Coverage Δ
linux 38.68% <0.00%> (-0.05%) ⬇️
macos 39.25% <0.00%> (-0.09%) ⬇️
windows 47.03% <0.00%> (-0.17%) ⬇️

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.

@dbwiddis
dbwiddis force-pushed the refactor/wmi-common-interface branch 2 times, most recently from bb0c321 to 5c8376e Compare May 18, 2026 20:45

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryExecutorJNA.java`:
- Around line 25-27: Constructor WmiQueryExecutorJNA and public methods that
accept a query need fail-fast null checks: add explicit null validation (e.g.,
Objects.requireNonNull or if (x==null) throw new NullPointerException("...")) in
the WmiQueryExecutorJNA(WmiQueryHandler handler) constructor for parameter
handler and in the public query-taking method(s) (the executeQuery/other method
around lines 54-57 that accepts String query) to validate query and throw a
clear NPE message; reference the WmiQueryExecutorJNA class, its constructor
WmiQueryExecutorJNA(WmiQueryHandler handler), and the public method that accepts
String query when applying these checks.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 646724f2-003f-4c51-af56-72042052b069

📥 Commits

Reviewing files that changed from the base of the PR and between acbe7d5 and 5c8376e.

📒 Files selected for processing (8)
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryExecutorFFM.java
  • oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryExecutorJNA.java
🚧 Files skipped from review as they are similar to previous changes (7)
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQuery.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryExecutorFFM.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiQueryExecutor.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiResult.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiConstants.java
  • oshi-common/src/main/java/oshi/driver/common/windows/wmi/WmiUtil.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). (11)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Analyze (java)

@dbwiddis
dbwiddis force-pushed the refactor/wmi-common-interface branch from 5c8376e to 77125f0 Compare May 18, 2026 22:58
Add shared WMI infrastructure to oshi-common:
- WmiQuery<T>: common query class (namespace, className, propertyEnum)
- WmiResult<T>: common result interface (getValue, getResultCount, etc.)
- WmiQueryExecutor: common handler interface (queryWMI methods)
- WmiConstants: CIM/VT type constants
- WmiUtil: typed result extraction helpers (getString, getUint32, etc.)

Add platform adapters:
- WmiQueryExecutorJNA wraps WmiQueryHandler with JnaWmiResult adapter
- WmiQueryExecutorFFM wraps WmiQueryHandlerFFM with FfmWmiResult adapter

Migrate Win32DiskDrive.queryDiskDrive as proof of concept.

Follow-up PRs will migrate the remaining 20 driver classes and their
callers to use the common types.
@dbwiddis
dbwiddis force-pushed the refactor/wmi-common-interface branch from 77125f0 to 282df4f Compare May 18, 2026 22:59
@dbwiddis
dbwiddis merged commit ba85f3d into oshi:master May 18, 2026
19 of 20 checks passed
@dbwiddis
dbwiddis deleted the refactor/wmi-common-interface branch May 18, 2026 23:30
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