Repository navigation
Move remaining macOS hardware classes to oshi-common - #3149
Conversation
…classes to oshi-common; add JNA suffix to remaining mac hardware classes (#3148)
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📜 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 (12)📓 Common learnings📚 Learning: 2026-04-06T22:30:07.083ZApplied to files:
📚 Learning: 2026-04-03T02:07:49.467ZApplied to files:
📚 Learning: 2026-04-06T21:48:11.921ZApplied to files:
📚 Learning: 2026-04-05T05:40:45.797ZApplied to files:
📚 Learning: 2026-04-10T22:44:32.055ZApplied to files:
📚 Learning: 2026-04-05T05:39:21.126ZApplied to files:
📚 Learning: 2026-03-29T20:03:00.830ZApplied to files:
📚 Learning: 2026-04-05T16:15:06.124ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-12T19:34:56.879ZApplied to files:
🔇 Additional comments (2)
📝 WalkthroughWalkthroughExtracted macOS-specific CPU, firmware, and disk-store logic into new thread-safe abstract bases in oshi-common, and adapted JNA/FFM platform implementations to extend these bases while renaming/redirecting several macOS JNA classes and factory usages. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify 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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3149 +/- ##
============================================
+ Coverage 62.00% 62.38% +0.38%
Complexity 12 12
============================================
Files 39 39
Lines 2329 2329
Branches 407 407
============================================
+ Hits 1444 1453 +9
+ Misses 776 768 -8
+ Partials 109 108 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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/hardware/common/platform/mac/MacCentralProcessor.java`:
- Around line 105-114: The switch in MacCentralProcessor that sets family based
on mSeries currently maps all unknown series to M1_CPUFAMILY (using constants
M2_CPUFAMILY, M3_CPUFAMILY, M1_CPUFAMILY), which will misreport newer SoCs;
change the default branch so it does NOT assign M1_CPUFAMILY but instead falls
back to the runtime hw.cpufamily value (the system cpufamily/sysctl value
previously obtained) or leaves family unset/unknown so cpuFamily and processorID
are not misreported; update the default case in the mSeries switch in
MacCentralProcessor to use that hw.cpufamily fallback instead of M1_CPUFAMILY
and ensure any downstream logic handles the fallback correctly.
- Around line 159-163: The core-efficiency flag is inverted: in
MacCentralProcessor where physProcs is created you set efficiency = 1 for cores
in ARM_P_CORES; change that to efficiency = 0 for ARM_P_CORES and 1 otherwise
(so P-cores are non-efficient, E-cores efficient) and then update the downstream
frequency selection that checks PhysicalProcessor.getEfficiency() (the branch
that currently treats efficiency==1 as performance/core) to use the reversed
test (i.e., treat efficiency==0 as performance/P-core and select the performance
frequency accordingly) so classification and frequency mapping remain
consistent.
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java`:
- Line 27: partitionList can be null when updateDiskStats(...) fails during
construction, causing getPartitions() to return null and trigger NPEs; make
getPartitions() null-safe by returning Collections.emptyList() (or initializing
partitionList to an empty list) when partitionList == null, and ensure
constructors or updateDiskStats callers (including the JNA/FFM disk-store
constructors) either initialize partitionList to Collections.emptyList() or rely
on the null-safe getPartitions(); update references to partitionList,
getPartitions(), and updateDiskStats(...) accordingly so callers always see an
empty list rather than null.
In `@oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java`:
- Around line 36-98: The code in MacFirmwareJNA that iterates IORegistry
(variables platformExpert, iter, entry) must be made exception-safe: wrap use of
iter and entry in nested try/finally blocks so entry.release() and
iter.release() always run (and platformExpert.release() in an outer finally),
and avoid NPE by null-checking entry.getName() (or storing it to a local String
and checking for null) before calling switch; update the loop in the method
where platformExpert is obtained to release entry in a finally inside the loop,
release iter in a finally after the loop, and release platformExpert in its own
finally to ensure native handles are always freed.
🪄 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: 5bf0e7a2-a952-4b3b-b604-b36be32330ce
📒 Files selected for processing (16)
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacFirmware.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessor.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacComputerSystemJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmware.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.java
💤 Files with no reviewable changes (2)
- oshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessor.java
- oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmware.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 21, windows-latest
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (6)
📓 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.
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.
📚 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/hardware/platform/mac/MacHardwareAbstractionLayerFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.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/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorJNA.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/MacHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacComputerSystemJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
📚 Learning: 2026-04-06T22:30:07.083Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3122
File: oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java:215-234
Timestamp: 2026-04-06T22:30:07.083Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`, the `found` flag in `getControllerIdByLocation` is intentionally set to `true` as soon as either `vendor-id` or `device-id` is found in a matching service's parent. This is a deliberate design choice: a partial match (one of the two IDs) is preferred over continuing to iterate, because iterating further risks pairing IDs from two different and potentially mismatched services. Do not flag this as a bug or suggest splitting into separate `foundVendor`/`foundProduct` flags.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.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-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
🔇 Additional comments (4)
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacFirmware.java (1)
21-49: Clean shared abstraction for firmware lookup and caching.The memoized
Supplierplus abstractqueryEfi()hook is a solid extraction and keeps subclass responsibilities focused on native querying.oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.java (1)
12-25: Inheritance change to commonMacFirmwareis correctly wired.The class extension and
protected queryEfi()override match the new shared contract cleanly.oshi-core/src/main/java/oshi/hardware/platform/mac/MacComputerSystemJNA.java (1)
28-30: Firmware factory update is correct.
createFirmware()now points toMacFirmwareJNA, matching the refactor and new class naming.oshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorJNA.java (1)
128-135: Good native-buffer cleanup path.Freeing the
host_processor_infobuffer in afinallyblock avoids leaking the Mach allocation across repeated CPU-tick queries.
…eption-safe IOKit iteration in MacFirmwareJNA
Final macOS hardware migration. This PR completes the move of all macOS superclasses to
oshi-common, meaning every macOS FFM class now depends solely onoshi-commonwith zero dependencies onoshi-core.Changes
New base classes in
oshi-common:MacCentralProcessor— shared constants (ARM core types, M-series CPU families, default frequency), fields with getters/setters, and ~245 lines of shared logic (queryProcessorId,initProcessorCounts,getCacheValues,queryCurrentFreq,queryMaxFreq,queryContextSwitches,queryInterrupts, etc.). Subclasses implement abstract sysctl delegates and native IOKit/Mach calls.MacFirmware— memoizedSupplierwith 5 getters; subclasses implement abstractqueryEfi()returning aQuintet.MacHWDiskStore— 8 fields with getters/protected setters and sharedCFKeyenum. Subclasses keepupdateDiskStatsandgetDiskswith native CoreFoundation/DiskArbitration/IOKit calls.Renamed in
oshi-core:MacCentralProcessor→MacCentralProcessorJNAMacFirmware→MacFirmwareJNAMacHWDiskStore→MacHWDiskStoreJNAMacNetworkIFJNA→MacNetworkIfJNA(capitalization fix)Renamed in
oshi-core-java25:MacNetworkIFFM→MacNetworkIfFFM(capitalization fix)Updated references in:
MacComputerSystemJNA(→MacFirmwareJNA)MacHardwareAbstractionLayerJNA(→MacCentralProcessorJNA,MacHWDiskStoreJNA)MacHardwareAbstractionLayerFFM(updated ref)Summary by CodeRabbit
New Features
Bug Fixes
Performance