Skip to content

Synchronize the disk and file store refresh paths - #3653

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:filestore-disk-sync
Aug 18, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:filestore-disk-sync

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 18, 2026 •

Copy link
Copy Markdown
Member

Second chunk of the updateAttributes() consistency arc begun in #3586, taking the disk and file store implementations. Also fixes a latent race introduced with the space invariant in #3651.

The standard, now settled

#3586 established the pattern on BsdOSProcess and BsdOSThread: the lock goes on the method that writes the fields, and no suppression is kept beside it. Its open question was whether Sonar's java:S3078 was syntactic and would re-fire under the lock. It does not — Sonar reports 0 open issues and Coverity is clean, with no S3078 or VOLATILE_ATOMICITY suppressions left anywhere in the tree. So this is the standard rather than a proposal, and the remaining chunks can follow it without re-deciding.

Before this PR, 3 of ~45 implementations used it. After, 14.

The latent race (first commit)

setSpace assigned each volatile and then read it back to bound the next:

this.totalSpace  = Math.max(0L, totalSpace);
this.freeSpace   = Math.min(Math.max(0L, freeSpace),   this.totalSpace);
this.usableSpace = Math.min(Math.max(0L, usableSpace), this.freeSpace);

So the method that exists to guarantee usable <= free <= total was itself a read-modify-write, and two concurrent refreshes could interleave to violate it:

A: total = 100
A: free  = min(50, 100) = 50
B: total = 10
A: usable = min(30, this.freeSpace = 50) = 30
   -> total=10, free=50, usable=30, and free > total

Computing the three into locals and assigning once removes the read-back entirely, so the clamps bound values from a single reading regardless of what else is writing. This stands on its own and is separated as the first commit.

File stores: one file, ten implementations

#3651 made AbstractOSFileStore the sole writer of the mutable fields — no platform class assigns them — so locking its three update* entry points covers every implementation at once. setSpace stays private, reached only from those three, and therefore needs no lock of its own.

Disks: no such choke point

Eight of the eleven HWDiskStore platform classes write the counters directly, so each takes the lock on its own updateAttributes(). That matches AixHWDiskStore, synchronized since #3586 and the only one until now; its monotonic clamps (if (stats.xfers > getReads())) are read-modify-writes that the lock now protects on every platform rather than one.

Locking safety

Two things checked rather than assumed, since this is where the arc could go wrong:

  • No implementation acquires a second lock inside the method body — no nested synchronized, no explicit Lock.
  • No caller holds a lock across the call. Every store.updateAttributes() site is a freshly constructed store inside a getDisks()-style factory.

So there is no lock-ordering hazard to reason about.

Documentation

OSFileStore was one of two interfaces with no thread-safety contract at all — OSProcess, OSThread, NetworkIF and HWDiskStore already carried the externally-synchronize paragraph. It now states that, the space ordering it guarantees, and the prefer-the-full-list advice the others give. PowerSource, the other one, comes with the network chunk.

Not included

The shared monotonic(long, long) hoist, unifying AixHWDiskStore's inline clamps with BsdOSProcess.monotonic. Those sit in different chunks, and the clamps are now lock-protected either way; it belongs wherever the process/thread work lands.

Verification

Full gate and -Perror-prone clean, all tests passing. synchronized is not part of the method signature, so japicmp is unaffected. No CHANGELOG entry: this fixes a race no OSHI-internal caller can reach, and the rest is documentation.

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability when disk statistics are refreshed concurrently across supported Linux, macOS, Windows, BSD, and Solaris platforms.
    • Prevented inconsistent file-store space values during simultaneous updates, preserving nonnegative and properly ordered totals.
  • Documentation

    • Clarified file-store space-value behavior, including sampling and value-clamping guarantees.
    • Added guidance for safely retrieving and refreshing file-store attributes in multithreaded applications.

…itten

setSpace assigned each volatile and then read it back to bound the next one, so
the method that exists to guarantee an ordering was itself a read-modify-write.
Two concurrent refreshes could interleave and leave a triple violating it:

    A: total = 100
    A: free  = min(50, 100) = 50
    B: total = 10
    A: usable = min(30, this.freeSpace = 50) = 30
       -> total=10, free=50, usable=30, and free > total

Compute the three into locals and assign once. The clamps then bound values from
a single reading, whatever else is writing concurrently.
Continues the updateAttributes() consistency arc from #3586, which established
the pattern on the BSD process and thread implementations: the lock goes on the
method that writes the fields, and no suppression is kept alongside it. Coverity
and Sonar are both clean on that shape now, so it is the standard rather than a
proposal.

The file store side needed only one file. #3651 made AbstractOSFileStore the
sole writer of the mutable fields -- no platform class assigns them -- so
locking its three update entry points covers all ten implementations at once.
setSpace stays private and is only reached from them, hence unlocked.

HWDiskStore has no such choke point: eight of its platform classes write the
counters directly, so each updateAttributes() takes the lock itself. That
matches AixHWDiskStore, which has been the only synchronized one since #3586 and
whose monotonic clamps are read-modify-writes that the lock now protects
everywhere rather than in one place.

Verified no implementation acquires a second lock inside the method, and that
every caller is a freshly constructed store inside a getDisks() factory holding
nothing, so there is no ordering hazard.

OSFileStore was one of two interfaces carrying no thread-safety contract; it now
states the externally-synchronize guidance the other four have, the space
ordering it guarantees, and the prefer-the-full-list advice. PowerSource, the
other, comes with the network chunk.
@coderabbitai

coderabbitai Bot commented Aug 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 Plus

Run ID: eba3b04a-9de4-4a02-adba-3898796752aa

📥 Commits

Reviewing files that changed from the base of the PR and between 7243d1d and 584b16d.

📒 Files selected for processing (12)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java

Included review availability: Your plan includes up to 8 reviews per rolling hour; 7 remain after this review.

📜 Recent review details
⏰ Context from checks skipped due to timeout. (12)
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Error Prone
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📓 Path-based instructions (5)
oshi-core-ffm/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

  • oshi-core-ffm may not reference com.sun.jna.**.

Files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
**/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/src/main/java/**/*.java: Javadoc. Every public and protected type and method needs javadoc.
Do not use fully-qualified class names in
code or in javadoc — including inside {@link ...}. Import the type and link the simple name.
New files get a current-year-only
header (Copyright 2026 The OSHI Project Contributors / SPDX-License-Identifier: MIT), even when
copied from an older file; spotless maintains end years on existing files.
Never add a line range to
config/checkstyle-suppressions.xml — a range breaks the moment anything above it shifts, including a
single added import, and the failure looks unrelated to the change that caused it.
new classes are
expected to declare one, and matching the annotation of the class you are modeling yours on is the
right default.
Do not reach for @Nullable to make a null return legal: the convention is a sentinel, not a
null
— Constants.UNKNOWN or "" for strings, an empty collection or array, and 0/-1/NaN
for numbers, whichever is outside the value's real range.
System calls are expensive, and callers poll. Values that are constant (CPU model,
serial number) or expensive-but-slow-changing are wrapped in
oshi.util.Memoizer.memoize(supplier, ...)

Files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
**

📄 CodeRabbit inference engine (AGENTS.md)

**: Do not add dependencies without discussion, and do not bump dependency versions by hand —
Renovate handles that.
Do not commit generated output, target/, or IDE files.

Files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
oshi-core/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-core/src/main/java/**/*.java: A behavior change to one is almost always a bug
unless the twin gets it too.

Files:

  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
oshi-common/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-common/src/main/java/**/*.java: Before writing any parsing helper, check whether ParseUtil already has one.
oshi-common may not reference com.sun.jna.**, java.lang.foreign.**, or any
System.load/loadLibrary. It must stay pure JDK.

Files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
🧠 Learnings (9)
📚 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/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
📚 Learning: 2026-08-02T23:56:23.866Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3565
File: oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java:51-56
Timestamp: 2026-08-02T23:56:23.866Z
Learning: For Java FFM bindings in the oshi-core-ffm module, assume a 64-bit JVM and 64-bit operating system. Do not flag 32-bit native ABI or memory-layout compatibility concerns, consistent with the project's JDK 25 support policy, unless that policy changes.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
📚 Learning: 2026-08-15T14:25:48.170Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3625
File: oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java:65-69
Timestamp: 2026-08-15T14:25:48.170Z
Learning: In OSHI Java code, treat `oshi.util.Util.isBlank(String)` as equivalent to `value == null || value.isEmpty()`: it does not consider whitespace-only strings blank. Do not report a behavior change when code replaces `!Util.isBlank(value)` with the equivalent `value != null && !value.isEmpty()` condition.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
📚 Learning: 2026-08-15T15:43:29.296Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3628
File: oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.java:108-108
Timestamp: 2026-08-15T15:43:29.296Z
Learning: In the OSHI Java codebase, use the sentinel-over-null convention at public API boundaries. Private helpers may return an explicitly JSpecify-annotated nullable value when the caller handles the missing result clearly and locally; callers must check for null before accessing the result. For example, methods such as lookupAccountBySid(String) may return String Nullable [] when queryUserSessions() performs the required null check.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
📚 Learning: 2026-08-15T15:59:20.875Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3629
File: oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:75-75
Timestamp: 2026-08-15T15:59:20.875Z
Learning: For OSHI backend twin classes whose filenames end in JNA.java or FFM.java, do not flag missing Javadoc on public forwarding constructors when config/checkstyle-suppressions.xml exempts them. Treat the documented abstract parent constructor as the contract location and avoid requiring duplicate Javadoc for the forwarded parameters.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.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/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.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/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/os/OSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
🔇 Additional comments (12)
oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java (1)

154-154: LGTM!

Also applies to: 172-172, 186-186, 203-211

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

20-29: LGTM!

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

121-121: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java (1)

45-45: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java (1)

102-102: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java (1)

114-114: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java (1)

73-73: LGTM!

oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (1)

85-85: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (1)

190-190: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java (1)

58-58: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java (1)

157-157: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java (1)

62-62: LGTM!


📝 Walkthrough

Walkthrough

The change synchronizes file-store and disk-store attribute updates across common, FFM, and JNA platform implementations. File-store space calculations now use local clamped values before publishing fields. The OSFileStore contract documents ordering and thread-safety behavior.

Changes

State refresh synchronization

Layer / File(s) Summary
File-store space update synchronization
oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java, oshi-common/src/main/java/oshi/software/os/OSFileStore.java
updateFrom, updateSpaceAndInodes, and updateSpace are synchronized. setSpace computes clamped values locally before assigning fields. Interface documentation describes ordering, sampling, and thread-safe update behavior.
Common platform disk updates
oshi-common/src/main/java/oshi/hardware/common/platform/{linux,unix,windows}/...
Linux, FreeBSD, NetBSD, OpenBSD, Solaris, and Windows updateAttributes() methods are synchronized. Existing statistics collection and return behavior remain unchanged.
Native platform disk updates
oshi-core-ffm/src/main/java/oshi/hardware/platform/{linux,mac}/..., oshi-core/src/main/java/oshi/hardware/platform/{linux,mac}/...
FFM and JNA updateAttributes() methods are synchronized. Existing refresh, cleanup, error handling, and return behavior remain unchanged.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 584b1

This change synchronizes disk and file-store refresh updates and documents their thread-safety contract; no actionable merge-blocking risk remains beyond normal checks and review.

Poem

A rabbit guards the stats tonight,
With synchronized paws held tight.
Disk numbers queue, then safely flow,
File-store values stay in order below.
Clamped and steady, row by row—
Hop, hop, refresh, and off we go!

🚥 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 clearly and concisely summarizes the main change: synchronizing disk and file store refresh paths.
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.

@codecov

codecov Bot commented Aug 18, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.18%. Comparing base (7243d1d) to head (584b16d).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3653      +/-   ##
============================================
- Coverage     80.27%   80.18%   -0.10%     
- Complexity     4083     4442     +359     
============================================
  Files           701      701              
  Lines         24762    24765       +3     
  Branches       4135     4135              
============================================
- Hits          19877    19857      -20     
- Misses         2731     2747      +16     
- Partials       2154     2161       +7     
Flag Coverage Δ
freebsd 34.35% <100.00%> (+<0.01%) ⬆️
linux 38.42% <100.00%> (-0.01%) ⬇️
macos 39.26% <100.00%> (-0.04%) ⬇️
solaris 35.06% <100.00%> (+<0.01%) ⬆️
windows 46.01% <100.00%> (+0.01%) ⬆️

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 6c9e190 into oshi:master Aug 18, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the filestore-disk-sync branch August 18, 2026 03:43
dbwiddis added a commit that referenced this pull request Aug 18, 2026
Third chunk of the updateAttributes() consistency arc, following #3653. Same
standard: the lock goes on the method that writes the fields, with no
suppression beside it.

NetworkIF has no shared writer, so six platforms take the lock on their own
updateAttributes(), which is where they assign the counters.

macOS is the exception and shows why the writer is the right target rather than
the public method. Its fields are written by updateNetworkStats(Map), reached
both from updateAttributes() and directly from the MacNetworkIfJNA and
MacNetworkIfFFM constructors, which populate an interface from a bulk query.
Locking only the public method would leave the constructor path unguarded, so
the lock goes on updateNetworkStats. That also keeps the native queryIFdata call
outside the lock, since updateAttributes queries first and writes after.

Every other platform reaches its writes from a constructor too -- the six
oshi-common bases from their own, and AIX and Solaris additionally from their
JNA and FFM subclasses -- and all of those go through the method now locked.
Verified no body acquires a second lock and no call site sits inside a
synchronized block, so there is no ordering hazard.

PowerSource was the last interface carrying no thread-safety contract. It gains
the externally-synchronize paragraph the other five have, plus the one way it
genuinely differs: a failed update leaves the source unchanged, because it
assigns nothing unless it finds a source matching this one's name.

With this the arc covers every refreshable type except OSProcess and OSThread.
dbwiddis added a commit that referenced this pull request Aug 18, 2026
Final chunk of the updateAttributes() consistency arc begun in #3586, after
#3653 and #3654. Every refreshable type is now covered.

This is the phase the arc flagged as highest risk, for two reasons that both
turned out to be answered by locking the writer rather than the public method.

Where a class writes its fields in an overload -- AIX process, and Windows
process and thread -- the lock goes there, matching what #3586 did for the BSD
pair. That is not a stylistic choice: every one of those overloads is called
from a subclass constructor doing bulk population, so locking only the public
no-arg would leave the list-building path unguarded while appearing to cover it.

It also keeps the expensive work outside the lock. The Windows twins do all
their registry, performance counter and WTS querying in the public method before
delegating, so no WMI or COM call happens under the monitor -- verified, not
assumed. The BSD pair likewise spawns ps outside it.

Where a class writes inline instead, with no separate writer to target --
Solaris process and thread, Linux process and thread, AIX thread, and both macOS
process backends -- the no-arg takes the lock and its queries come with it.
macOS interleaves proc_pidinfo, proc_pidpath and getpwuid with the assignments,
so there is nothing to separate; this matches the six NetworkIF platforms in
#3654.

WindowsOSThreadJNA and WindowsOSThreadFFM need nothing: they write no fields and
delegate to the base overload now locked.

Verified no locked body acquires a second lock, so there is no ordering hazard.

Not included: hoisting BsdOSProcess.monotonic to share with AixHWDiskStore's
inline clamps, the arc's last open item. Both are now lock-protected, so it is
purely a duplication question, and it needs a home neutral to both hierarchies.
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