Skip to content

Pull duplicated getter boilerplate into abstract base classes - #3275

Merged
dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:refactor/getter-boilerplate-to-abstract-classes
May 20, 2026
Merged

dbwiddis merged 4 commits into
oshi:masterfrom
dbwiddis:refactor/getter-boilerplate-to-abstract-classes

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Addresses Issue 2 (Getter Boilerplate Not in Abstract Base Classes) from #3274.

Moves duplicated fields, getters, and helper methods from platform-specific subclasses into their respective abstract base classes, eliminating ~1,500 lines of duplicated code across 3 interfaces and 20 subclasses.

Changes

OSFileStore (commit 1)

  • Pulled logicalVolume, description, fsType, freeSpace, usableSpace, totalSpace, freeInodes, totalInodes fields + getters + updateFrom/updateSpaceAndInodes/updateSpace helpers into AbstractOSFileStore
  • Simplified 7 subclasses (Aix, FreeBSD, OpenBSD, Solaris, Linux, Mac, Windows)

NetworkIF (commit 2)

  • Pulled bytesRecv, bytesSent, packetsRecv, packetsSent, inErrors, outErrors, inDrops, collisions, speed, timeStamp fields + getters + protected setters into AbstractNetworkIF
  • Simplified 7 subclasses (Aix, Solaris, BSD, Linux, Mac, Windows JNA, Windows FFM)
  • Platform-specific fields (ifType, ndisPhysicalMediumType, connectorPresent, ifAlias, ifOperStatus) remain in subclasses

HWDiskStore (commit 3)

  • Pulled reads, readBytes, writes, writeBytes, currentQueueLength, transferTime, timeStamp, partitionList fields + getters + protected setters + setDiskStats bulk setter into AbstractHWDiskStore
  • Simplified 6 subclasses (Aix, FreeBSD, OpenBSD, Solaris, Linux, Mac, Windows)

Testing

  • All existing tests pass
  • Full verification: spotless:apply, checkstyle:check, install, forbiddenapis:check, javadoc:javadoc all green
  • No public API changes — all method signatures preserved

Net impact

  • -1,786 lines of duplicated code removed
  • +598 lines consolidated in abstract base classes
  • Net reduction: ~1,188 lines

Summary by CodeRabbit

  • Refactor
    • Consolidated disk I/O statistics, partitions, network interface metrics, and filesystem metadata/space/inode metrics into common base classes; platform implementations now use inherited state.
  • Tests
    • Added unit tests for disk-store and file-store base behaviors and updates.
    • Relaxed benchmark uptime assertion tolerance to allow minor clock differences.

Review Change Stack

dbwiddis added 3 commits May 19, 2026 23:50
Move logicalVolume, description, fsType, freeSpace, usableSpace,
totalSpace, freeInodes, and totalInodes fields plus their getters
and updateFrom/updateSpaceAndInodes/updateSpace helpers into the
abstract base class.

Simplifies 7 subclasses by removing ~57 lines of duplicated
fields+getters from each.

Closes partially: #3274
Move bytesRecv, bytesSent, packetsRecv, packetsSent, inErrors,
outErrors, inDrops, collisions, speed, and timeStamp fields plus
their getters and protected setters into the abstract base class.

Simplifies 7 subclasses by removing ~61 lines of duplicated
fields+getters from each. Platform-specific fields (ifType,
ndisPhysicalMediumType, connectorPresent, ifAlias, ifOperStatus)
remain in their respective subclasses.

Partial fix for #3274
Move reads, readBytes, writes, writeBytes, currentQueueLength,
transferTime, timeStamp, and partitionList fields plus their
getters, protected setters, and setDiskStats bulk setter into
the abstract base class.

Simplifies 6 subclasses by removing ~55 lines of duplicated
fields+getters from each. Platform-specific fields (CFKey enum,
DiskStats/PartitionMaps utilities) remain in their respective
subclasses.

Partial fix for #3274
@coderabbitai

coderabbitai Bot commented May 19, 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: 2ab7d5f6-3a38-4345-9515-8ca7e31ecee8

📥 Commits

Reviewing files that changed from the base of the PR and between 1136299 and b5dc937.

📒 Files selected for processing (6)
  • oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
  • oshi-common/src/test/java/oshi/hardware/common/AbstractHWDiskStoreTest.java
  • oshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.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). (9)
  • 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 11, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-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/software/common/AbstractOSFileStore.java
🔇 Additional comments (4)
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java (1)

356-357: LGTM!

oshi-common/src/test/java/oshi/hardware/common/AbstractHWDiskStoreTest.java (1)

1-93: LGTM!

oshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.java (1)

15-18: LGTM!

Also applies to: 20-45, 57-64, 75-84, 86-96, 98-112

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

24-32: LGTM!

Also applies to: 35-55, 63-70, 108-193


📝 Walkthrough

Walkthrough

This PR consolidates repeated state management across platform-specific hardware and software classes by promoting common disk I/O statistics, network interface metrics, and file-store metadata into their abstract base classes. Each platform (Linux, Mac, Windows, AIX, BSD, FreeBSD, OpenBSD, Solaris) now delegates storage and access through inherited setters instead of maintaining duplicate fields.

Changes

Disk I/O Statistics

Layer / File(s) Summary
AbstractHWDiskStore state contract
oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java
Adds private fields for reads/writes, byte counts, queue length, transfer time, timestamp, and partitions list; implements public stat getters and protected setters including setDiskStats and setPartitionList.
Linux disk store wiring
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
Initializes partition list via setPartitionList(...) in constructors and returns mutable partition list via a cast of getPartitions().
Platform disk implementations
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java, oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java, oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHWDiskStore.java, oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStore.java, oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java, oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHWDiskStore.java
Each removes local stat fields and overridden getters, updating metrics via inherited setters during attribute refresh and when populating partition lists.

Network Interface Statistics

Layer / File(s) Summary
AbstractNetworkIF state contract
oshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.java
Adds private long fields for bytes/packets/errors/drops/collisions/speed/timestamp; implements public getters and protected setters for each metric.
Platform network implementations
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java, oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.java, oshi-core/src/main/java/oshi/hardware/platform/unix/BsdNetworkIF.java, oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixNetworkIF.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java, oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java
Each removes local stat fields and getter overrides, populating metrics via inherited setters in updateAttributes().

File Store Metadata

Layer / File(s) Summary
AbstractOSFileStore extended contract
oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
Constructor expanded to accept logical volume, description, filesystem type, and space/inode metrics; adds public getters and protected update helpers (updateFrom, updateSpaceAndInodes, updateSpace).
Platform file store implementations
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java, oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java, oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java, oshi-core/src/main/java/oshi/software/os/unix/aix/AixOSFileStore.java, oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSFileStore.java, oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSFileStore.java, oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSFileStore.java, oshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.java
Each forwards filesystem attributes to superclass via expanded super(...) calls and uses inherited updateFrom/updateSpace helpers for attribute synchronization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • oshi/oshi#3148: Network interface metric consolidation refactor affecting macOS and other platform network implementations.
  • oshi/oshi#3057: File-store model extensions to AbstractOSFileStore and OSFileStore affecting platform file-store implementations.

Poem

🐰 I hopped through classes, fields set free,

Superclasses hold stats for all to see,
Setters in place, duplicates undone,
Tests confirm the work is neatly run,
A rabbit applauds refactor fun!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.91% 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 describes the main refactoring: consolidating duplicated getter/field boilerplate from platform-specific subclasses into abstract base classes across OSFileStore, NetworkIF, and HWDiskStore.
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.

Actionable comments posted: 3

🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.java (1)

15-23: ⚡ Quick win

Add direct coverage for the new shared update helpers.

This test only validates constructor-backed getters. The new cross-platform behavior is in updateFrom(...), updateSpaceAndInodes(...), and updateSpace(...), so a small test-only subclass that exposes those helpers would give much better regression coverage for the refactor.

Also applies to: 25-51

🤖 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/test/java/oshi/software/common/AbstractOSFileStoreTest.java`
around lines 15 - 23, Create a small test-only subclass inside
AbstractOSFileStoreTest that exposes the new shared helpers and invoke them
directly: instantiate via createFileStore() (or replace it) with an anonymous
subclass that overrides updateAttributes and adds public wrapper methods to call
updateFrom(...), updateSpaceAndInodes(...), and updateSpace(...); then write
assertions exercising each helper (e.g., different input combinations for
space/inode values and updateFrom merging semantics) to validate the
cross-platform behavior. Ensure tests call the subclass wrappers for updateFrom,
updateSpaceAndInodes, and updateSpace and assert the resulting getters
(total/usable/free/avail/inodes) reflect the expected updates.
🤖 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-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java`:
- Around line 27-35: AbstractHWDiskStore is `@ThreadSafe` but its mutable fields
(reads, readBytes, writes, writeBytes, currentQueueLength, transferTime,
timeStamp, partitionList) lack visibility guarantees; make each of these fields
volatile so unsynchronized getters/setters (and platform updateAttributes()
calls) see up-to-date values. Update the field declarations in class
AbstractHWDiskStore to declare the long fields and the partitionList field as
volatile (preserving their types), leaving existing getter/setter method
signatures unchanged.

In `@oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java`:
- Around line 24-32: The new mutable fields in AbstractOSFileStore
(logicalVolume, description, fsType, freeSpace, usableSpace, totalSpace,
freeInodes, totalInodes) are written by updateFrom/updateSpace* and read by
getters without synchronization; either protect them or drop `@ThreadSafe`. Fix by
introducing a single private final lock (e.g., private final Object
attributesLock = new Object()) in AbstractOSFileStore and wrap all writes
(inside updateFrom, updateSpace*, updateAttributes) in
synchronized(attributesLock) and wrap all corresponding getters to return values
inside synchronized(attributesLock) as well so callers see consistent snapshots;
alternatively apply the same protection with a ReentrantReadWriteLock if
finer-grained concurrency is desired.

In
`@oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java`:
- Around line 92-101: The Kstat2 mapping is shifted: you never assign the
inbound error field (ierrors) and as a result setCollisions, setInDrops,
setSpeed, and setTimeStamp read the wrong result slots; fix by inserting the
missing inbound-error assignment (call the proper setter for ierrors immediately
after setOutErrors using the next results index) and then increment the indices
used by setCollisions, setInDrops, setSpeed, and setTimeStamp by one so each
uses the correct results[] slot (i.e., move collisions, inDrops, speed,
timestamp reads one index higher than they currently are).

---

Nitpick comments:
In `@oshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.java`:
- Around line 15-23: Create a small test-only subclass inside
AbstractOSFileStoreTest that exposes the new shared helpers and invoke them
directly: instantiate via createFileStore() (or replace it) with an anonymous
subclass that overrides updateAttributes and adds public wrapper methods to call
updateFrom(...), updateSpaceAndInodes(...), and updateSpace(...); then write
assertions exercising each helper (e.g., different input combinations for
space/inode values and updateFrom merging semantics) to validate the
cross-platform behavior. Ensure tests call the subclass wrappers for updateFrom,
updateSpaceAndInodes, and updateSpace and assert the resulting getters
(total/usable/free/avail/inodes) reflect the expected updates.
🪄 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: bc997fcc-4f76-4699-b002-abe2f458b12b

📥 Commits

Reviewing files that changed from the base of the PR and between 47d2588 and 1136299.

📒 Files selected for processing (25)
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.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/common/os/linux/LinuxOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/BsdNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/aix/AixOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSFileStore.java
💤 Files with no reviewable changes (2)
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.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). (10)
  • 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: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 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/unix/BsdNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixNetworkIF.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSFileStore.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSFileStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSFileStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-core/src/main/java/oshi/software/os/unix/aix/AixOSFileStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHWDiskStore.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/software/common/AbstractOSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
🔇 Additional comments (13)
oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSFileStore.java (1)

20-21: LGTM!

Also applies to: 28-28

oshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.java (1)

54-63: LGTM!

Also applies to: 231-369

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

95-108: LGTM!

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

98-118: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/BsdNetworkIF.java (1)

54-67: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixNetworkIF.java (1)

70-79: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java (1)

106-143: LGTM!

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

99-100: LGTM!

Also applies to: 113-114, 121-123

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

72-75: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHWDiskStore.java (1)

48-66: LGTM!

Also applies to: 99-100

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

92-93: LGTM!

Also applies to: 108-114

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

43-58: LGTM!

Also applies to: 84-93, 131-133

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

48-58: LGTM!

Also applies to: 90-103

Comment on lines +24 to +32
private String logicalVolume;
private String description;
private String fsType;

private long freeSpace;
private long usableSpace;
private long totalSpace;
private long freeInodes;
private long totalInodes;

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.

⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift

Guard the new mutable metrics or drop the @ThreadSafe contract.

These fields are now shared state in the base class, but updateFrom(...) / updateSpace*() write them while the getters read them without any synchronization. Under the current @ThreadSafe annotation, callers can observe stale or mixed snapshots during updateAttributes(). Please either protect this state with a consistent synchronization strategy or relax the thread-safety contract here.

Also applies to: 108-193

🤖 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/software/common/AbstractOSFileStore.java`
around lines 24 - 32, The new mutable fields in AbstractOSFileStore
(logicalVolume, description, fsType, freeSpace, usableSpace, totalSpace,
freeInodes, totalInodes) are written by updateFrom/updateSpace* and read by
getters without synchronization; either protect them or drop `@ThreadSafe`. Fix by
introducing a single private final lock (e.g., private final Object
attributesLock = new Object()) in AbstractOSFileStore and wrap all writes
(inside updateFrom, updateSpace*, updateAttributes) in
synchronized(attributesLock) and wrap all corresponding getters to return values
inside synchronized(attributesLock) as well so callers see consistent snapshots;
alternatively apply the same protection with a ReentrantReadWriteLock if
finer-grained concurrency is desired.

@codecov

codecov Bot commented May 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.24324% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.63%. Comparing base (19c9a0c) to head (b5dc937).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
...hardware/platform/windows/WindowsNetworkIfJNA.java 52.63% 9 Missing ⚠️
...rdware/common/platform/linux/LinuxHWDiskStore.java 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3275      +/-   ##
============================================
+ Coverage     74.56%   74.63%   +0.07%     
  Complexity       73       73              
============================================
  Files           406      407       +1     
  Lines         16047    15958      -89     
  Branches       2554     2554              
============================================
- Hits          11965    11911      -54     
+ Misses         2602     2564      -38     
- Partials       1480     1483       +3     
Flag Coverage Δ
linux 39.49% <67.56%> (+0.71%) ⬆️
macos 40.14% <67.56%> (+0.72%) ⬆️
windows 48.08% <75.67%> (+0.72%) ⬆️

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.

- Make mutable fields volatile in AbstractHWDiskStore and
  AbstractOSFileStore to honor @threadsafe contract
- Fix SolarisNetworkIF.updateAttributes2(): ierrors (index 5) was
  skipped, causing collisions/inDrops/speed/timeStamp to read
  wrong result slots
- Add AbstractOSFileStoreTest coverage for updateFrom,
  updateSpaceAndInodes, and updateSpace helpers
- Add AbstractHWDiskStoreTest covering setDiskStats,
  setCurrentQueueLength, partitions, and toString
- Fix flaky NativeComparisonTest uptime comparison: allow 2s
  tolerance for clock resolution between JNA and FFM calls
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