Skip to content

Move macOS OperatingSystem tree to oshi-common - #3145

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:mac-migrate
Apr 12, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:mac-migrate

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 12, 2026 •

Copy link
Copy Markdown
Member

Continues the macOS oshi-common migration from #3144 by moving the entire MacOperatingSystem class tree and adding JNA suffixes to all remaining JNA-only classes for naming consistency.

Moved to oshi-common (oshi.software.common.os.mac)

Class Notes
MacInstalledApps Clean move
MacOperatingSystem Fixed LOG bug: was MacOperatingSystemJNA.class, now MacOperatingSystem.class
MacFileSystem New abstract base with shared constants, config fields, mount flags, and OPTIONS_MAP
MacOSFileStore New abstract base with shared fields, constructor, getters, and updateFrom() helper

Split into JNA/FFM pairs

Common base (oshi-common) JNA (oshi-core) FFM (oshi-core-java25)
MacFileSystem MacFileSystemJNA (new name) MacFileSystemFFM (now extends common base)
MacOSFileStore MacOSFileStoreJNA (new name) MacOSFileStoreFFM (now extends common base, deduplicated)

JNA suffix renames (oshi-core)

Old name New name
MacOSProcess MacOSProcessJNA
MacInternetProtocolStats MacInternetProtocolStatsJNA
MacNetworkParams MacNetworkParamsJNA

Other changes

  • Updated checkstyle suppression line range for MacOperatingSystem.java
  • Updated all references in MacOperatingSystemJNA

Summary by CodeRabbit

  • Refactor

    • Reorganized macOS components into clearer abstraction layers and shared base types for filesystem handling.
    • Renamed and separated JNA-specific implementations for improved clarity.
    • Moved several macOS classes to the common macOS package and adjusted visibility and update patterns.
  • Chores

    • Updated copyright years and cleaned up imports.
    • Adjusted code style/configuration suppressions.

@coderabbitai

coderabbitai Bot commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The PR extracts macOS filesystem/file-store behavior into new common base classes under oshi.software.common.os.mac, moves several mac-specific classes into that package, and renames/refactors JNA and FFM implementations to extend those common bases and adopt "JNA" suffixed concrete classes.

Changes

Cohort / File(s) Summary
Common Base Classes
oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java, oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
Added abstract MacFileSystem and MacOSFileStore common bases: shared config keys, path matchers, mount flag constants/option map, and MacOSFileStore.updateFrom(...) helper; constructor visibility for file store made protected.
Common Package Migrations
oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java, oshi-common/src/main/java/oshi/software/common/os/mac/MacInstalledApps.java
Moved classes into oshi.software.common.os.mac; updated logger target and package/imports.
Checkstyle Configuration
config/checkstyle-suppressions.xml
Adjusted VisibilityModifier suppression line range from 53-57 to 52-56.
JNA Implementations – Hierarchy & Renames
oshi-core/src/main/java/oshi/software/os/mac/MacFileSystemJNA.java, oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
MacFileSystemJNA now extends new common MacFileSystem; removed duplicate constants from JNA class. Added concrete MacOSFileStoreJNA implementing updateAttributes() and delegating attribute copy to updateFrom(...).
JNA Implementations – Class Renames
oshi-core/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsJNA.java, oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java, oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
Renamed classes to include "JNA" suffix and updated loggers/method references accordingly.
JNA Coordinator Updates
oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
Factory methods now return JNA-suffixed concrete implementations (MacFileSystemJNA, MacInternetProtocolStatsJNA, MacNetworkParamsJNA, MacOSProcessJNA); imports tidied.
FFM Implementations
oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java, oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java, oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
MacOSFileStoreFFM now extends MacOSFileStore, delegating attribute storage to superclass and using updateFrom(...) in updateAttributes(); added imports for common base.
Minor Imports/Formatting
oshi-core-java25/.../MacFileSystemFFM.java, oshi-core-java25/.../MacOperatingSystemFFM.java
Added explicit imports for new common base classes; minor import reordering.

Sequence Diagram(s)

sequenceDiagram
    participant OS as MacOperatingSystemJNA
    participant FS as MacFileSystemJNA
    participant Store as MacOSFileStoreJNA
    participant Repo as OSFileStore (system query)

    OS->>FS: getFileSystem()
    FS->>Repo: enumerate system file stores
    Repo-->>FS: list of OSFileStore
    FS->>Store: instantiate MacOSFileStoreJNA(...) for each entry
    Store->>FS: updateAttributes() (calls FS.getFileStoreMatching)
    FS->>Repo: getFileStoreMatching(name, local)
    Repo-->>FS: matching OSFileStore
    FS-->>Store: matched OSFileStore
    Store->>Store: updateFrom(matched OSFileStore)
    Store-->>OS: updated file-store instances returned to OS
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related PRs

Poem

🐰 Hopped through macOS files with care,

Common roots now standing there,
JNA joins FFM in line,
Stores update from one design,
A little rabbit cheers: "Refactor fine!" 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.11% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main objective of the PR, which is moving the macOS OperatingSystem classes to oshi-common.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

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 Apr 12, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.21%. Comparing base (d6a8095) to head (d3dddf3).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3145      +/-   ##
============================================
+ Coverage     61.91%   62.21%   +0.30%     
  Complexity       12       12              
============================================
  Files            39       39              
  Lines          2329     2329              
  Branches        407      407              
============================================
+ Hits           1442     1449       +7     
+ Misses          777      770       -7     
  Partials        110      110              

☔ 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

24-32: ⚠️ Potential issue | 🟠 Major

Preserve the updateAttributes() fail-closed contract here.

This override now lets FFM/native failures escape instead of returning false, which changes the behavior callers expect from updateAttributes(). Wrap the body in catch (Throwable) and return false without logging.

Suggested fix
     `@Override`
     public boolean updateAttributes() {
-        for (OSFileStore fileStore : MacFileSystemFFM.getFileStoreMatching(getName(), isLocal())) {
-            if (getVolume().equals(fileStore.getVolume()) && getMount().equals(fileStore.getMount())) {
-                updateFrom(fileStore);
-                return true;
+        try {
+            for (OSFileStore fileStore : MacFileSystemFFM.getFileStoreMatching(getName(), isLocal())) {
+                if (getVolume().equals(fileStore.getVolume()) && getMount().equals(fileStore.getMount())) {
+                    updateFrom(fileStore);
+                    return true;
+                }
             }
+            return false;
+        } catch (Throwable e) {
+            return false;
         }
-        return false;
     }

Based on learnings: in OSHI’s Java FFM/API implementation classes, updateAttributes() intentionally catches Throwable and returns false without logging.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java`
around lines 24 - 32, The override in MacOSFileStoreFFM.updateAttributes() must
preserve the fail-closed contract: wrap the existing logic (the for-loop that
iterates over MacFileSystemFFM.getFileStoreMatching(getName(), isLocal()),
compares getVolume()/getMount(), and calls updateFrom(fileStore)) in a try block
and add a catch (Throwable) that simply returns false (no logging or
rethrowing); keep the method returning true on successful update and false
otherwise.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java`:
- Line 38: The LOCAL_DISK pattern in MacFileSystem currently only matches
single-digit device names and misses real macOS names; update the Pattern
referenced by LOCAL_DISK in class MacFileSystem to match one-or-more digits and
optional slice/partition suffix (e.g., allow /dev/disk10 and /dev/disk0s2) so
local volumes are detected correctly; replace the existing
Pattern.compile("/dev/disk\\d") with a regex that uses \\d+ and an optional
(s\\d+)? suffix.

---

Outside diff comments:
In `@oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java`:
- Around line 24-32: The override in MacOSFileStoreFFM.updateAttributes() must
preserve the fail-closed contract: wrap the existing logic (the for-loop that
iterates over MacFileSystemFFM.getFileStoreMatching(getName(), isLocal()),
compares getVolume()/getMount(), and calls updateFrom(fileStore)) in a try block
and add a catch (Throwable) that simply returns false (no logging or
rethrowing); keep the method returning true on successful update and false
otherwise.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 21f4af46-9263-43f6-a5b4-06d2349e80c6

📥 Commits

Reviewing files that changed from the base of the PR and between d6a8095 and 08b60ab.

📒 Files selected for processing (14)
  • config/checkstyle-suppressions.xml
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacInstalledApps.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.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). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacInstalledApps.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacInstalledApps.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
📚 Learning: 2026-04-06T21:48:11.921Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:85-111
Timestamp: 2026-04-06T21:48:11.921Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` (and `MacUsbDeviceFFM.java`), the `id = 0L` sentinel is intentional when `device.getParentEntry(IOSERVICE)` returns null. It acts as a catch-all controller group for devices whose controller cannot be identified (an edge case that "should never happen" given the IORegistry format). Do not flag this as a bug or suggest skipping such devices; the design intentionally avoids both silently dropping orphaned devices and placing them at the top level without a controller context.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.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/software/os/mac/MacNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacFileSystemJNA.java
📚 Learning: 2026-04-03T02:07:49.467Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:49.467Z
Learning: In `oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java` (and similar FFM/API implementations in OSHI), the `updateAttributes()` method intentionally uses `catch (Throwable e) { return false; }` without logging. This is by design: `updateAttributes()` is a public API method whose contract is to return `false` on failure; callers consume the boolean and would never see log output, so adding a log statement is not desired.

Applied to files:

  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
🔇 Additional comments (13)
config/checkstyle-suppressions.xml (1)

41-41: Suppression range update is consistent with the moved field block.
This looks correct and keeps the existing intent intact after line shifts.

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

5-11: Package migration and import adjustments look clean.
No behavioral risk in this segment; the move aligns with the common macOS refactor.

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

45-45: Logger target fix is correct.
Switching to MacOperatingSystem.class resolves the previous class-reference mismatch in logs.

oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java (1)

33-33: Superclass import update is correct for the migration.
MacOperatingSystemFFM now resolves to the shared common base as intended.

oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java (1)

28-33: JNA rename wiring is consistent.
Class name and logger target are aligned, reducing future confusion in logs and type references.

oshi-core/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsJNA.java (1)

57-71: Type rename propagation is complete in this segment.
Constructor and memoized supplier references correctly point to MacInternetProtocolStatsJNA.

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

23-35: Shared constant/config extraction looks solid.
Centralizing FS include/exclude config and mount-option mapping in this base class is a good consolidation step for JNA/FFM parity.

Also applies to: 64-87

oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java (1)

41-41: Import update is correct for shared base adoption.
MacFileSystemFFM now cleanly extends the common macOS filesystem base.

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

15-95: Nice shared-base extraction.

Pulling the common macOS file-store state and the updateFrom(...) helper into one base class keeps the JNA and FFM implementations thinner without changing where the matching logic lives.

oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java (1)

48-61: Rename and constructor wiring look consistent.

The common MacOperatingSystem import, logger target, class rename, and constructor signature all line up with the updated factory path.

Also applies to: 142-148

oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java (1)

69-75: Factory updates are internally consistent.

getFileSystem(), getInternetProtocolStats(), getProcess(), and getNetworkParams() all now resolve to the renamed JNA implementations, and the MacOSProcessJNA constructor call matches the new base-type signature.

Also applies to: 111-149

oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)

15-33: Good split between shared state and JNA-specific lookup.

Keeping the match logic here and centralizing the field-copying in updateFrom(...) makes the move to oshi-common nicely contained.

oshi-core/src/main/java/oshi/software/os/mac/MacFileSystemJNA.java (1)

34-48: The filesystem refactor hangs together cleanly.

Extending the shared MacFileSystem base and emitting MacOSFileStoreJNA instances keeps the JNA-specific enumeration logic intact while deduplicating the shared macOS constants and config.

Also applies to: 162-164

…nd MacOSFileStore; add JNA suffix to remaining classes (#3145)

@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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

24-33: ⚠️ Potential issue | 🟠 Major

Restore Throwable guard in updateAttributes() to keep failure signaling contract.

updateAttributes() currently lets runtime failures propagate. Per the FFM pattern in this codebase, it should return false on any failure and avoid logging from this path.

Proposed patch
     `@Override`
     public boolean updateAttributes() {
-        for (OSFileStore fileStore : MacFileSystemFFM.getFileStoreMatching(getName(), isLocal())) {
-            if (getVolume().equals(fileStore.getVolume()) && getMount().equals(fileStore.getMount())) {
-                updateFrom(fileStore);
-                return true;
+        try {
+            for (OSFileStore fileStore : MacFileSystemFFM.getFileStoreMatching(getName(), isLocal())) {
+                if (getVolume().equals(fileStore.getVolume()) && getMount().equals(fileStore.getMount())) {
+                    updateFrom(fileStore);
+                    return true;
+                }
             }
+        } catch (Throwable t) { // intentional: API contract is boolean failure signaling
+            return false;
         }
         return false;
     }

Based on learnings: in OSHI Java FFM updateAttributes() implementations, preserve catch Throwable and return false without logging.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java`
around lines 24 - 33, The updateAttributes() method should preserve the FFM
failure-contract by wrapping the existing logic in a try/catch Throwable that
returns false on any error and does not log; specifically, in
MacOSFileStoreFFM.updateAttributes() wrap the loop that iterates over
MacFileSystemFFM.getFileStoreMatching(getName(), isLocal()) and compares
getVolume() and getMount(), calling updateFrom(fileStore) and returning true on
match, with a try block and add a catch(Throwable t) { return false; } so any
runtime/checked errors simply cause updateAttributes() to return false without
emitting logs.
🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java (1)

64-87: Consider making OPTIONS_MAP unmodifiable for thread-safety.

While the map is only populated in the static initializer and never modified afterward, wrapping it in Collections.unmodifiableMap() would make the immutability explicit and prevent accidental modification by subclasses, which better aligns with the @ThreadSafe annotation.

♻️ Proposed fix
-    protected static final Map<Integer, String> OPTIONS_MAP = new HashMap<>();
-    static {
-        OPTIONS_MAP.put(MNT_SYNCHRONOUS, "synchronous");
-        OPTIONS_MAP.put(MNT_NOEXEC, "noexec");
-        OPTIONS_MAP.put(MNT_NOSUID, "nosuid");
-        OPTIONS_MAP.put(MNT_NODEV, "nodev");
-        OPTIONS_MAP.put(MNT_UNION, "union");
-        OPTIONS_MAP.put(MNT_ASYNC, "asynchronous");
-        OPTIONS_MAP.put(MNT_CPROTECT, "content-protection");
-        OPTIONS_MAP.put(MNT_EXPORTED, "exported");
-        OPTIONS_MAP.put(MNT_QUARANTINE, "quarantined");
-        OPTIONS_MAP.put(MNT_LOCAL, "local");
-        OPTIONS_MAP.put(MNT_QUOTA, "quotas");
-        OPTIONS_MAP.put(MNT_ROOTFS, "rootfs");
-        OPTIONS_MAP.put(MNT_DOVOLFS, "volfs");
-        OPTIONS_MAP.put(MNT_DONTBROWSE, "nobrowse");
-        OPTIONS_MAP.put(MNT_IGNORE_OWNERSHIP, "noowners");
-        OPTIONS_MAP.put(MNT_AUTOMOUNTED, "automounted");
-        OPTIONS_MAP.put(MNT_JOURNALED, "journaled");
-        OPTIONS_MAP.put(MNT_NOUSERXATTR, "nouserxattr");
-        OPTIONS_MAP.put(MNT_DEFWRITE, "defwrite");
-        OPTIONS_MAP.put(MNT_MULTILABEL, "multilabel");
-        OPTIONS_MAP.put(MNT_NOATIME, "noatime");
-    }
+    protected static final Map<Integer, String> OPTIONS_MAP;
+    static {
+        Map<Integer, String> map = new HashMap<>();
+        map.put(MNT_SYNCHRONOUS, "synchronous");
+        map.put(MNT_NOEXEC, "noexec");
+        map.put(MNT_NOSUID, "nosuid");
+        map.put(MNT_NODEV, "nodev");
+        map.put(MNT_UNION, "union");
+        map.put(MNT_ASYNC, "asynchronous");
+        map.put(MNT_CPROTECT, "content-protection");
+        map.put(MNT_EXPORTED, "exported");
+        map.put(MNT_QUARANTINE, "quarantined");
+        map.put(MNT_LOCAL, "local");
+        map.put(MNT_QUOTA, "quotas");
+        map.put(MNT_ROOTFS, "rootfs");
+        map.put(MNT_DOVOLFS, "volfs");
+        map.put(MNT_DONTBROWSE, "nobrowse");
+        map.put(MNT_IGNORE_OWNERSHIP, "noowners");
+        map.put(MNT_AUTOMOUNTED, "automounted");
+        map.put(MNT_JOURNALED, "journaled");
+        map.put(MNT_NOUSERXATTR, "nouserxattr");
+        map.put(MNT_DEFWRITE, "defwrite");
+        map.put(MNT_MULTILABEL, "multilabel");
+        map.put(MNT_NOATIME, "noatime");
+        OPTIONS_MAP = Collections.unmodifiableMap(map);
+    }

Add the import:

import java.util.Collections;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java`
around lines 64 - 87, Make OPTIONS_MAP truly immutable by replacing the mutable
HashMap with an unmodifiable map: after populating the current static HashMap in
the static initializer for class MacFileSystem, wrap it with
Collections.unmodifiableMap(...) and assign that back to OPTIONS_MAP (and add
the import for java.util.Collections); this makes the static OPTIONS_MAP
constant read-only and protects against accidental modification by subclasses or
other code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java`:
- Around line 24-33: The updateAttributes() method should preserve the FFM
failure-contract by wrapping the existing logic in a try/catch Throwable that
returns false on any error and does not log; specifically, in
MacOSFileStoreFFM.updateAttributes() wrap the loop that iterates over
MacFileSystemFFM.getFileStoreMatching(getName(), isLocal()) and compares
getVolume() and getMount(), calling updateFrom(fileStore) and returning true on
match, with a try block and add a catch(Throwable t) { return false; } so any
runtime/checked errors simply cause updateAttributes() to return false without
emitting logs.

---

Nitpick comments:
In `@oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java`:
- Around line 64-87: Make OPTIONS_MAP truly immutable by replacing the mutable
HashMap with an unmodifiable map: after populating the current static HashMap in
the static initializer for class MacFileSystem, wrap it with
Collections.unmodifiableMap(...) and assign that back to OPTIONS_MAP (and add
the import for java.util.Collections); this makes the static OPTIONS_MAP
constant read-only and protects against accidental modification by subclasses or
other code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4485170d-5eb9-45c3-ab01-1ef985da51b8

📥 Commits

Reviewing files that changed from the base of the PR and between 08b60ab and d3dddf3.

📒 Files selected for processing (14)
  • config/checkstyle-suppressions.xml
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacInstalledApps.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
✅ Files skipped from review due to trivial changes (5)
  • config/checkstyle-suppressions.xml
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacInstalledApps.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOperatingSystemJNA.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacInternetProtocolStatsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/mac/MacOSFileStore.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). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.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/software/os/mac/MacFileSystemJNA.java
📚 Learning: 2026-04-06T04:45:51.516Z
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:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.

Applied to files:

  • oshi-common/src/main/java/oshi/software/common/os/mac/MacFileSystem.java
🔇 Additional comments (4)
oshi-core-java25/src/main/java/oshi/software/os/mac/MacOSFileStoreFFM.java (1)

8-21: Nice consolidation onto the common macOS file-store base.

This inheritance + constructor delegation cleanup is consistent with the JNA/FFM split and removes duplicated state/getter logic cleanly.

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

1-38: Clean extraction of common macOS filesystem constants and configuration.

The structure is well-organized with config keys, PathMatcher filters, and the LOCAL_DISK pattern properly extracted to the common base class. The eagerly-loaded PathMatcher fields align with how FileSystemUtil is designed to be used.

oshi-core/src/main/java/oshi/software/os/mac/MacFileSystemJNA.java (2)

34-48: Refactoring looks correct.

The class now properly extends the common MacFileSystem base and the logger correctly references MacFileSystemJNA.class, fixing the bug mentioned in the PR objectives where it previously referenced the wrong class.


55-56: Consistent naming with the JNA suffix convention.

The comment update and MacOSFileStoreJNA instantiation correctly reflect the renamed classes in this PR.

Also applies to: 162-164

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