Skip to content

Align remaining JNA/FFM/native-free backend divergences - #3480

Merged
dbwiddis merged 8 commits into
oshi:masterfrom
dbwiddis:backend-consistency-cleanups
Jul 18, 2026
Merged

dbwiddis merged 8 commits into
oshi:masterfrom
dbwiddis:backend-consistency-cleanups

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 18, 2026 •

Copy link
Copy Markdown
Member

Final sweep of JNA↔FFM (and native-free) backend divergences found in the consistency audit, ahead of 7.4.1. Each fix aligns a backend to the correct behavior of its twin; every commit is one fix.

Native-free Linux

  • LinuxHWDiskStoreNF disk type. The native-free backend only read queue/rotational (HDD/SSD) and left everything else "". Now mirrors the udev-based backends' detectDiskType: reads removable (→ Removable), then rotational (→ SSD/HDD), else Unknown.

Windows — default (JNA) backend

  • DeviceTree buffer truncation. MAX_PATH is a character count but the CM registry properties are UTF-16; the buffer was allocated as MAX_PATH bytes, truncating device friendly-names/descriptions/manufacturer strings longer than ~130 characters. Now allocates MAX_PATH * 2 bytes, matching the FFM backend.

Windows — FFM backend

  • WmiQueryHandlerFFM gave up when COM was already initialized. initCOM() returns false on RPC_E_CHANGED_MODE (another module already CoInitializeEx'd a different apartment model) — COM is still usable, but FFM early-returned an empty result. Now it proceeds with the query like the JNA backend, and only uninitializes COM it actually initialized.
  • WindowsInternetProtocolStatsFFM returned null on a failed stats query, where the JNA backend returns a zeroed TcpStats/UdpStats. Callers don't null-check, so this was an NPE risk. Now returns a zeroed object.
  • isCurrentX86 used the PROCESSOR_ARCHITECTURE env var, which reflects the process (WOW64) architecture — a 32-bit JVM on 64-bit Windows would misreport the OS and all processes as 32-bit. Now calls GetNativeSystemInfo (the true machine architecture), matching the JNA backend.
  • PerfDataUtilFFM didn't retry the first-sample PDH race. The JNA backend retries PdhCollectQueryData up to 3× with exponential backoff on PDH_NO_DATA; FFM collected once and returned empty counters. Now retries to match.

Summary by CodeRabbit

  • New Features

    • Improved disk classification on Linux, including removable disks and more accurate SSD/HDD detection (falls back to “Unknown” when indeterminate).
    • Improved Windows architecture detection to better reflect the actual native machine type.
  • Bug Fixes

    • Improved reliability of Windows performance counter collection by retrying when initial data is unavailable.
    • WMI queries now proceed even when COM initialization reports it wasn’t performed for this call.
    • Windows network statistics now return safe zero values instead of null on failures.
    • Prevented truncation of longer Windows device node names and descriptions.

@coderabbitai

coderabbitai Bot commented Jul 18, 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

Run ID: 43914f06-370d-4c4a-9682-37ade506e8f3

📥 Commits

Reviewing files that changed from the base of the PR and between 6a8b331 and 346372f.

📒 Files selected for processing (1)
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsFFM.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsFFM.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

The changes refine Linux disk-type detection and update Windows native integrations for PDH retries, COM handling, network-stat fallbacks, architecture detection, wider device-property reads, and release notes.

Changes

Linux disk detection

Layer / File(s) Summary
Sysfs disk-type classification
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
Disk enumeration now detects Removable, SSD, HDD, or Unknown using sysfs attributes.

Windows FFM query handling

Layer / File(s) Summary
PDH collection retry
oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/PdhFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfDataUtilFFM.java
PDH counter collection retries PDH_NO_DATA up to three times with exponential backoff for regular and wildcard queries.
WMI COM-mode handling
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryHandlerFFM.java
Both WMI query paths continue after initCOM() reports an existing incompatible COM apartment and avoid uninitializing COM they did not initialize.

Windows FFM platform behavior

Layer / File(s) Summary
Native architecture detection
oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
x86 detection now reads the native processor architecture through GetNativeSystemInfo.
Non-null network statistics fallbacks
oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsFFM.java
TCP and UDP statistics methods return zero-value structures when native queries fail.

Windows device-tree reading

Layer / File(s) Summary
Device property buffer sizing
oshi-core/src/main/java/oshi/driver/windows/DeviceTree.java
Device-node property reads use buffers and size references of MAX_PATH * 2 bytes.

Release notes

Layer / File(s) Summary
Changelog entry
CHANGELOG.md
The 7.4.1 improvements section records PR #3480 and its backend fixes.

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

Sequence Diagram(s)

sequenceDiagram
  participant queryCounters
  participant collectQueryDataWithRetry
  participant PdhCollectQueryData
  queryCounters->>collectQueryDataWithRetry: collect query data
  collectQueryDataWithRetry->>PdhCollectQueryData: call collection
  PdhCollectQueryData-->>collectQueryDataWithRetry: return PDH_NO_DATA or status
  collectQueryDataWithRetry->>PdhCollectQueryData: retry with exponential backoff
  collectQueryDataWithRetry-->>queryCounters: enforce successful collection
Loading

Possibly related PRs

Poem

A rabbit sees disks spin and glow,
While native queries retry below.
COM stays calm, wide strings grow,
Zero stats keep the numbers in tow.
“Hop onward!” says the bunny bright.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 summarizes the PR’s main goal of aligning behavioral differences across JNA, FFM, and native-free backends.
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.

@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-ffm/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsFFM.java`:
- Around line 43-64: Update getTCPv4Stats, getTCPv6Stats, getUDPv4Stats, and
getUDPv6Stats to handle null results from the IPHlpAPIUtilFFM calls, returning
the corresponding ZERO_TCP_STATS or ZERO_UDP_STATS fallback and preserving error
logging instead of propagating 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: b4cdd814-7b8c-4a82-907d-df92b1c7f4bb

📥 Commits

Reviewing files that changed from the base of the PR and between f0f6547 and b891bc0.

📒 Files selected for processing (7)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/PdhFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfDataUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/DeviceTree.java
📜 Review details
⏰ Context from checks skipped due to timeout. (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryHandlerFFM.java
  • oshi-core/src/main/java/oshi/driver/windows/DeviceTree.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/PdhFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfDataUtilFFM.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsInternetProtocolStatsFFM.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/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
🔇 Additional comments (10)
oshi-core/src/main/java/oshi/driver/windows/DeviceTree.java (1)

2-2: LGTM!

Also applies to: 72-75

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

23-23: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfDataUtilFFM.java (4)

16-16: LGTM!


111-112: LGTM!


147-158: LGTM!


341-342: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryHandlerFFM.java (2)

136-139: LGTM!


311-314: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java (1)

62-62: LGTM!

Also applies to: 100-119

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

457-468: LGTM!

@codecov

codecov Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 51.42857% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.73%. Comparing base (f0f6547) to head (346372f).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
.../platform/linux/nativefree/LinuxHWDiskStoreNF.java 40.00% 3 Missing and 3 partials ⚠️
...re/os/windows/WindowsInternetProtocolStatsFFM.java 60.00% 0 Missing and 4 partials ⚠️
...software/os/windows/WindowsOperatingSystemFFM.java 33.33% 1 Missing and 3 partials ⚠️
...shi/ffm/util/platform/windows/PerfDataUtilFFM.java 66.66% 2 Missing and 1 partial ⚠️

❗ There is a different number of reports uploaded between BASE (f0f6547) and HEAD (346372f). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (f0f6547) HEAD (346372f)
solaris 1 0
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3480      +/-   ##
============================================
- Coverage     75.14%   68.73%   -6.41%     
  Complexity       76       76              
============================================
  Files           589      589              
  Lines         21532    21553      +21     
  Branches       3606     3615       +9     
============================================
- Hits          16180    14815    -1365     
- Misses         3385     4949    +1564     
+ Partials       1967     1789     -178     
Flag Coverage Δ
freebsd 27.66% <0.00%> (-0.03%) ⬇️
linux 32.22% <11.42%> (-0.02%) ⬇️
macos 32.74% <0.00%> (-0.08%) ⬇️
openbsd 26.96% <0.00%> (-0.03%) ⬇️
solaris ?
windows 40.89% <40.00%> (-0.04%) ⬇️

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.

@dbwiddis
dbwiddis merged commit 1e49a16 into oshi:master Jul 18, 2026
19 of 20 checks passed
@dbwiddis
dbwiddis deleted the backend-consistency-cleanups branch July 18, 2026 06:58
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