Skip to content

Remove redundant WMI forwarding-shim classes (Sonar S9149) - #3608

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:remove-wmi-forwarding-shims
Aug 13, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:remove-wmi-forwarding-shims

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Resolves 22 of the 27 open Sonar findings on master (all java:S9149).

Deletes 14 classes (7 JNA + 7 FFM) in oshi.driver.windows.wmi that existed only to redeclare the same static methods from their oshi-common base classes verbatim — MSFTStorage{JNA,FFM}, OhmHardware{JNA,FFM}, OhmSensor{JNA,FFM}, Win32DiskDrive{JNA,FFM}, Win32DiskDriveToDiskPartition{JNA,FFM}, Win32DiskPartition{JNA,FFM}, Win32LogicalDiskToPartition{JNA,FFM}. All callers (3 JNA platform classes, 3 FFM platform classes, 1 test) now reference the shared base classes in oshi.driver.common.windows.wmi directly.

The two LinuxPowerSource{FFM,JNA}.getPowerSources() findings are different: those have their own udev-based implementation that intentionally hides the base class's sysfs-only fallback. Suppressed with NOSONAR rather than renamed, since the method name is a cross-platform convention shared by all PowerSource implementations.

Test plan

  • ./mvnw clean spotless:apply sortpom:sort checkstyle:check install -Perror-prone -DskipTests forbiddenapis:check javadoc:javadoc: BUILD SUCCESS, 0 warnings, 0 errors
  • No remaining references to deleted classes: grep -rn 'MSFTStorageJNA\|MSFTStorageFFM\|OhmHardwareJNA\|OhmHardwareFFM\|OhmSensorJNA\|OhmSensorFFM\|Win32DiskDriveJNA\|Win32DiskDriveFFM\|Win32DiskDriveToDiskPartitionJNA\|Win32DiskDriveToDiskPartitionFFM\|Win32DiskPartitionJNA\|Win32DiskPartitionFFM\|Win32LogicalDiskToPartitionJNA\|Win32LogicalDiskToPartitionFFM' --include='*.java' . returns empty

Summary by CodeRabbit

  • Refactor

    • Consolidated Windows storage, disk, partition, volume, and sensor discovery on shared WMI query implementations.
    • Removed platform-specific query wrappers without changing disk, volume, sensor, or power-source behavior.
    • Updated Windows hardware discovery and validation to use the unified query APIs.
  • Chores

    • Added static-analysis suppressions for unchanged power-source overrides.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 9c4db6c7-f51e-4471-9f3f-4d46e106a461

📥 Commits

Reviewing files that changed from the base of the PR and between bc8c4b8 and 67efde4.

📒 Files selected for processing (1)
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Error Prone
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

The change removes redundant Windows WMI FFM and JNA wrappers. Disk, storage-volume, sensor, test, and benchmark callers now use common WMI query classes. Linux power-source methods receive Sonar suppression annotations.

Changes

Windows WMI migration

Layer / File(s) Summary
Common disk and storage queries
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupFFM.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupJNA.java
FFM and JNA disk and logical-volume implementations now call common disk and MSFTStorage WMI APIs. The platform-specific wrapper classes were removed.
Common sensor queries
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsSensorsFFM.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsSensorsJNA.java
Windows sensor implementations now call shared OhmHardware and OhmSensor APIs. The platform-specific sensor wrappers were removed.
Validation and static-analysis updates
oshi-core/src/test/java/oshi/driver/windows/wmi/WMIDriversTest.java, oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java, oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java
WMI tests and comparison tests now use common storage, disk, partition, and sensor query classes. Sonar suppression annotations were added to both Linux power-source overrides.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Mergeability Score: ⚪ Minimal · up to 67efd

The change removes redundant forwarding classes and updates callers to use shared implementations, with validation reported successful and no actionable merge-blocking risk remaining beyond normal checks.

Possibly related PRs

  • oshi/oshi#3173: Establishes the common WMI migration pattern used here.
  • oshi/oshi#3270: Completes related removal of redundant JNA and FFM WMI wrappers.
  • oshi/oshi#3546: Refactors logical-volume-group use of shared MSFT WMI APIs.

Poem

A rabbit checks the WMI trail,
Shared queries replace each wrapper shell.
Disks and sensors follow one way,
Tests confirm the path today.
“Hop onward!” says the rabbit.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% 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 clearly identifies the removal of redundant WMI forwarding-shim classes and states the related Sonar rule.
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.
✨ 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.

@dbwiddis
dbwiddis force-pushed the remove-wmi-forwarding-shims branch from e186448 to bc8c4b8 Compare August 13, 2026 18:31
@codecov

codecov Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.76%. Comparing base (be260d7) to head (67efde4).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3608      +/-   ##
============================================
- Coverage     79.88%   79.76%   -0.12%     
  Complexity       76       76              
============================================
  Files           710      710              
  Lines         24242    24240       -2     
  Branches       4057     4057              
============================================
- Hits          19366    19336      -30     
- Misses         2715     2742      +27     
- Partials       2161     2162       +1     
Flag Coverage Δ
linux 37.65% <0.00%> (+0.04%) ⬆️
macos 38.47% <0.00%> (+0.01%) ⬆️
windows 45.29% <100.00%> (-0.05%) ⬇️

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

☔ View full report in Codecov by Harness.
📢 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.

Delete 14 classes (7 JNA + 7 FFM) in oshi.driver.windows.wmi that
existed only to redeclare the same static methods from their
oshi-common base classes verbatim. Repoint all callers (3 JNA, 3 FFM,
1 test) directly at the shared base classes instead.

The two LinuxPowerSource getPowerSources() findings are different:
those have their own udev-based implementation that intentionally
hides the base class's sysfs-only fallback. Suppressed with NOSONAR
rather than renamed, since the method name is a cross-platform
convention shared by all PowerSource implementations.

Resolves 22 of the 27 open Sonar findings on master.
@dbwiddis
dbwiddis force-pushed the remove-wmi-forwarding-shims branch from bc8c4b8 to 67efde4 Compare August 13, 2026 18:55
@dbwiddis
dbwiddis merged commit 4d00f2e into oshi:master Aug 13, 2026
17 checks passed
@dbwiddis
dbwiddis deleted the remove-wmi-forwarding-shims branch August 13, 2026 19:02
dbwiddis added a commit that referenced this pull request Aug 16, 2026
Everything sat under "Bug Fixes and Improvements", which put the release's
headline change in the wrong place and left one entry carrying three
different kinds of change at once.

New Features: the JSpecify adoption, rewritten to lead with what a consumer
gets rather than what the sweep did to the build, and ParseUtil's new
getStringValueOrEmpty, which was a clause in the middle of that paragraph.

Behavior Changes: the null-to-sentinel list, promoted out of its sub-bullet.
Someone whose code tests those getters for null now has dead branches, and
that was the least visible thing in the section. #3616 moves here from Bug
Fixes, being the same kind of change.

Removals: #3608's 14 WMI forwarding shims, Util.isBlankOrUnknown and
ParseUtil.slash, with a note that they sit outside the semver-guaranteed API
and are listed only because removing them can break a compile.

Bug Fixes and Improvements keeps #3589 and #3611/#3612, gains the hardening
work split out of the JSpecify entry, and gains #3639, which had no entry at
all: the Windows GPU utilization path tested its cached tick sample for null
and then dereferenced it in a second read, so a concurrent poll could throw.

Dependency bumps get no entries; none changed anything user-visible.
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