Skip to content

Use protected fields (not setters) in mutable common bases (NetworkIF, HWDiskStore, OSFileStore) - #3391

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:abstract-superclass-protected-fields
Jun 13, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:abstract-superclass-protected-fields

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 13, 2026 •

Copy link
Copy Markdown
Member

Summary

Aligns the mutable common value-bases with the AbstractOSProcess model — protected attribute fields assigned in place by each platform, rather than per-field setters. One commit per class.

  • AbstractNetworkIF — 10 stat fields → protected; 10 per-field setters removed; subclasses assign directly in updateNetworkStats().
  • AbstractHWDiskStore — 7 stat fields (volatile retained) + partitionList AtomicReference → protected; 7 per-field setters removed. Immutable identity fields (name/model/serial/size/diskType) stay final; the bulk setDiskStats(...)/setPartitionList(...) helpers are kept (Windows DiskStats mapping + multi-line/cross-instance factory call sites).
  • AbstractOSFileStore — mutable space/inode/type fields (volatile retained) → protected; identity fields stay private; the bulk updateFrom()/updateSpace*() helpers are kept (no per-field setters existed, so no subclass call sites change).
  • Each gets a per-file VisibilityModifier suppression.

Deliberately left unchanged (immutability applies): AbstractPowerSource is a fully-constructed all-args value object (private fields, no setters, no subclass field access — assigned only within the base ctor + updateAttributes()); flipping it would add a suppression for no benefit and unwind the factory. The pure value-object snapshots (UsbDevice/GraphicsCard/Display/Printer/SoundCard/Bluetooth) and the field-less Pattern-D bases are untouched.

No behavior change. Caught + fixed a latent issue while converting: a NetBSD setReads(reads) (local named like the field) became a correct this.reads = reads rather than a self-assignment.

Test plan

  • spotless / checkstyle / forbiddenapis / javadoc + clean full-reactor build (incl. test compile, which caught a test-double using a removed setter)
  • NativeComparisonTest (JNA==FFM) on macOS: 39/39 (diskStores, networkInterfaces, + updateAttributes variants)
  • Linux/Windows/macOS via PR CI; BSD + OpenIndiana via dispatched unix.yml; AIX via cfarm

Summary by CodeRabbit

Refactor

  • Internal code reorganization across multiple platform implementations (Linux, BSD, macOS, Windows, Solaris, AIX) to standardize how system data updates are handled and processed more consistently. This structural improvement enhances code maintainability and consistency by refining internal data access patterns for hardware statistics, network interface metrics, and file system information management throughout the codebase.

dbwiddis added 3 commits June 13, 2026 09:58
Convert AbstractNetworkIF to the AbstractOSProcess model: the 10 mutable
stat fields (bytesRecv/bytesSent/packetsRecv/packetsSent/inErrors/outErrors/
inDrops/collisions/speed/timeStamp) become protected and are assigned directly
by each platform's updateNetworkStats(); the 10 protected setters are removed.
Adds a VisibilityModifier checkstyle suppression for the file. Mechanical, no
behavior change.
Convert the mutable disk-stat fields (reads/readBytes/writes/writeBytes/
currentQueueLength/transferTime/timeStamp, volatile retained) and the
partitionList AtomicReference to protected, assigned directly by each platform's
updateAttributes(); remove the 7 per-field setters. The immutable identity
fields (name/model/serial/size/diskType) stay final, and the bulk setDiskStats()/
setPartitionList() helpers are kept (used by the Windows DiskStats mapping and
multi-line/cross-instance factory call sites). Adds a VisibilityModifier
suppression. Mechanical, no behavior change; validated on macOS via
NativeComparisonTest.
The mutable, volatile state refreshed by updateFrom()/updateSpaceAndInodes()/
updateSpace() (logicalVolume, description, fsType, freeSpace, usableSpace,
totalSpace, freeInodes, totalInodes) becomes protected, matching the
AbstractOSProcess model and the sibling AbstractHWDiskStore. The immutable
identity fields (name/volume/label/mount/options/uuid/local) stay private, and
the bulk update helpers are retained (no per-field setters existed), so no
subclass call sites change. Adds a VisibilityModifier suppression.
@coderabbitai

coderabbitai Bot commented Jun 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

Run ID: 7f34c2a7-9985-4cb6-9236-3fcbf4ace57b

📥 Commits

Reviewing files that changed from the base of the PR and between fdaad80 and 04ea3de.

📒 Files selected for processing (21)
  • config/checkstyle-suppressions.xml
  • 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/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixNetworkIF.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/netbsd/NetBsdNetworkIF.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/unix/solaris/SolarisNetworkIF.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
  • oshi-common/src/test/java/oshi/hardware/common/AbstractHWDiskStoreTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.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). (13)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 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/aix/AixNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/openbsd/OpenBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/freebsd/FreeBsdHWDiskStore.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.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/mac/MacNetworkIfJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java
🔇 Additional comments (21)
config/checkstyle-suppressions.xml (1)

76-81: LGTM!

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

28-38: LGTM!

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

44-44: LGTM!

Also applies to: 50-50, 53-53, 56-60

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

47-53: LGTM!

Also applies to: 87-93, 97-97

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

114-120: LGTM!

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

109-114: LGTM!

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

55-55: LGTM!

Also applies to: 60-67

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

54-65: LGTM!

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

95-105: LGTM!

Also applies to: 108-108

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

54-54: LGTM!

Also applies to: 60-67

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

57-57: LGTM!

Also applies to: 62-63, 70-74

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

94-103: LGTM!

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

100-108: LGTM!

Also applies to: 118-118

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

93-102: LGTM!

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

106-114: LGTM!

Also applies to: 130-138, 143-143

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

24-35: LGTM!

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

42-51: LGTM!

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

54-54: LGTM!

Also applies to: 59-69

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

116-116: LGTM!

Also applies to: 120-120, 124-124, 128-128, 132-132, 143-143

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

109-109: LGTM!

Also applies to: 114-114, 117-117, 121-121, 124-124, 136-136

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

41-41: LGTM!


📝 Walkthrough

Walkthrough

This PR refactors field visibility across OSHI's hardware and software abstraction layer. Abstract base classes (AbstractNetworkIF, AbstractHWDiskStore, AbstractOSFileStore) expose mutable state fields as protected instead of private and remove protected setter methods. All platform-specific implementations are updated to assign statistics directly to fields instead of using the removed setters.

Changes

Field Visibility and Setter Removal Refactoring

Layer / File(s) Summary
Abstract base class field visibility and setter removal
config/checkstyle-suppressions.xml, oshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.java, oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java, oshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.java
AbstractNetworkIF and AbstractHWDiskStore expose network/disk statistics fields as protected and remove per-metric setXXX() methods. AbstractOSFileStore exposes space/inode counters and identity fields as protected volatile. Checkstyle configuration adds visibility suppressions for these classes.
Network interface platform implementations
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdNetworkIF.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixNetworkIF.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdNetworkIF.java, oshi-common/src/main/java/oshi/hardware/common/platform/unix/solaris/SolarisNetworkIF.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.java, oshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.java, oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.java
All network interface implementations across Linux, BSD, AIX, NetBSD, OpenBSD, Solaris, macOS (JNA and FFM), and Windows (JNA and FFM) replace setter method calls with direct field assignments when populating network statistics (bytes/packets sent/received, errors, collisions, drops, speed, timestamp).
Disk store platform implementations
oshi-common/src/main/java/oshi/hardware/common/platform/unix/aix/AixHWDiskStore.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-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java, oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
All disk store implementations across AIX, FreeBSD, NetBSD, OpenBSD, Solaris, and macOS (JNA and FFM) replace setter method calls with direct field assignments when populating disk I/O statistics (reads/writes, read/write bytes, queue length, transfer time, timestamp).
Test support update
oshi-common/src/test/java/oshi/hardware/common/AbstractHWDiskStoreTest.java
Test helper applyCurrentQueueLength() updates to assign directly to the currentQueueLength field instead of calling the removed setter.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • oshi/oshi#3275: Introduced the abstract AbstractHWDiskStore and AbstractNetworkIF bases that are directly refactored by this PR for visibility and setter removal.
  • oshi/oshi#3350: Implements new AixHWDiskStore and AixNetworkIF classes that extend the abstract bases being refactored, using direct field access patterns matching this PR's changes.
  • oshi/oshi#3368: Introduces Solaris abstract bases (SolarisHWDiskStore, SolarisNetworkIF) and their DiskStats/IfStats-driven update paths that align with this PR's direct field assignment refactor.

Poem

🐰 Fields now dance free, no setters to call,
Protected and ready, for subclasses all,
Straight to the heart, no middleman's way,
Faster, cleaner code—hooray, hooray!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.09% 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 directly and clearly describes the main change: converting mutable stat fields in three common base classes from private with setters to protected fields.
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.

@codecov

codecov Bot commented Jun 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.50000% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.02%. Comparing base (fdaad80) to head (04ea3de).

Files with missing lines Patch % Lines
...hardware/platform/windows/WindowsNetworkIfJNA.java 52.63% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3391      +/-   ##
============================================
- Coverage     75.10%   75.02%   -0.08%     
  Complexity       76       76              
============================================
  Files           579      579              
  Lines         21397    21363      -34     
  Branches       3560     3560              
============================================
- Hits          16070    16028      -42     
- Misses         3305     3308       +3     
- Partials       2022     2027       +5     
Flag Coverage Δ
freebsd 26.30% <20.00%> (-0.12%) ⬇️
linux 30.91% <9.16%> (-0.06%) ⬇️
macos 31.22% <27.50%> (-0.11%) ⬇️
openbsd 25.80% <6.66%> (-0.03%) ⬇️
solaris 27.86% <16.66%> (-0.12%) ⬇️
windows 39.52% <17.50%> (-0.08%) ⬇️

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 62beb0d into oshi:master Jun 13, 2026
23 checks passed
@dbwiddis
dbwiddis deleted the abstract-superclass-protected-fields branch June 13, 2026 17:53
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