Repository navigation
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (2)
📜 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)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
🔇 Additional comments (4)
📝 WalkthroughWalkthroughThis 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. ChangesDisk I/O Statistics
Network Interface Statistics
File Store Metadata
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.java (1)
15-23: ⚡ Quick winAdd direct coverage for the new shared update helpers.
This test only validates constructor-backed getters. The new cross-platform behavior is in
updateFrom(...),updateSpaceAndInodes(...), andupdateSpace(...), 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
📒 Files selected for processing (25)
oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacNetworkIF.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.javaoshi-common/src/main/java/oshi/software/common/AbstractOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-common/src/test/java/oshi/software/common/AbstractOSFileStoreTest.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfFFM.javaoshi-core/src/main/java/oshi/hardware/platform/unix/BsdNetworkIF.javaoshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixNetworkIF.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.javaoshi-core/src/main/java/oshi/software/os/unix/aix/AixOSFileStore.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSFileStore.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSFileStore.javaoshi-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.javaoshi-core/src/main/java/oshi/hardware/platform/unix/aix/AixNetworkIF.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSFileStore.javaoshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSFileStore.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsNetworkIfJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSFileStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHWDiskStore.javaoshi-core/src/main/java/oshi/software/os/unix/aix/AixOSFileStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.javaoshi-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.javaoshi-common/src/main/java/oshi/hardware/common/AbstractNetworkIF.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.javaoshi-common/src/main/java/oshi/software/common/os/windows/WindowsOSFileStore.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSFileStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.javaoshi-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
| private String logicalVolume; | ||
| private String description; | ||
| private String fsType; | ||
|
|
||
| private long freeSpace; | ||
| private long usableSpace; | ||
| private long totalSpace; | ||
| private long freeInodes; | ||
| private long totalInodes; |
There was a problem hiding this comment.
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 Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- 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
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)
logicalVolume,description,fsType,freeSpace,usableSpace,totalSpace,freeInodes,totalInodesfields + getters +updateFrom/updateSpaceAndInodes/updateSpacehelpers intoAbstractOSFileStoreNetworkIF (commit 2)
bytesRecv,bytesSent,packetsRecv,packetsSent,inErrors,outErrors,inDrops,collisions,speed,timeStampfields + getters + protected setters intoAbstractNetworkIFifType,ndisPhysicalMediumType,connectorPresent,ifAlias,ifOperStatus) remain in subclassesHWDiskStore (commit 3)
reads,readBytes,writes,writeBytes,currentQueueLength,transferTime,timeStamp,partitionListfields + getters + protected setters +setDiskStatsbulk setter intoAbstractHWDiskStoreTesting
spotless:apply,checkstyle:check,install,forbiddenapis:check,javadoc:javadocall greenNet impact
Summary by CodeRabbit