Skip to content

Move remaining macOS hardware classes to oshi-common - #3149

Merged
dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:mac-hw-finish
Apr 12, 2026
Merged

dbwiddis merged 2 commits into
oshi:masterfrom
dbwiddis:mac-hw-finish

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 12, 2026 •

Copy link
Copy Markdown
Member

Final macOS hardware migration. This PR completes the move of all macOS superclasses to oshi-common, meaning every macOS FFM class now depends solely on oshi-common with zero dependencies on oshi-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 — memoized Supplier with 5 getters; subclasses implement abstract queryEfi() returning a Quintet.
  • MacHWDiskStore — 8 fields with getters/protected setters and shared CFKey enum. Subclasses keep updateDiskStats and getDisks with native CoreFoundation/DiskArbitration/IOKit calls.

Renamed in oshi-core:

  • MacCentralProcessor → MacCentralProcessorJNA
  • MacFirmware → MacFirmwareJNA
  • MacHWDiskStore → MacHWDiskStoreJNA
  • MacNetworkIFJNA → 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

    • Better Apple Silicon support: more accurate distinction and reporting of performance vs efficiency cores and per-core frequencies on macOS.
  • Bug Fixes

    • Improved CPU identification and feature reporting on macOS.
    • More reliable firmware metadata extraction.
    • More consistent disk I/O statistics collection.
  • Performance

    • Reduced repeated firmware/registry queries via memoization for faster macOS hardware initialization.

…classes to oshi-common; add JNA suffix to remaining mac hardware classes (#3148)
@coderabbitai

coderabbitai Bot commented Apr 12, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ffb1ab8c-a57b-4db4-9fd0-b5efdf6f2319

📥 Commits

Reviewing files that changed from the base of the PR and between fdc62d0 and 63d544c.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
✅ Files skipped from review due to trivial changes (1)
  • CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (12)
📓 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-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/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.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/hardware/platform/mac/MacFirmwareJNA.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/MacFirmwareJNA.java
📚 Learning: 2026-04-05T05:40:45.797Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:40:45.797Z
Learning: In OSHI's Linux FFM and JNA udev code, a null guard on `udev_enumerate_new()` is intentionally absent and should not be flagged. This is consistent across all four FFM classes (LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the JNA implementation (which also does not guard `enumerateNew()` for null). Per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` (which is guarded) implies `udev_enumerate_new()` will succeed. Adding a null guard would be both redundant and inconsistent with the established pattern.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
📚 Learning: 2026-04-10T22:44:32.055Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:32.055Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
📚 Learning: 2026-04-05T05:39:21.126Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java:62-65
Timestamp: 2026-04-05T05:39:21.126Z
Learning: In OSHI's Linux FFM/JNA udev code, a null guard on `udev_enumerate_new()` is unnecessary if `udev_new()` has already been guarded: per libudev semantics, `udev_enumerate_new()` only returns NULL when udev itself is broken (e.g. OOM), so a successful `udev_new()` implies `udev_enumerate_new()` will succeed as well. Do not flag missing null checks on `udev_enumerate_new()` as an issue.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
📚 Learning: 2026-04-05T16:15:06.124Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java:95-97
Timestamp: 2026-04-05T16:15:06.124Z
Learning: In `LinuxLogicalVolumeGroupJNA.getLogicalVolumeGroups()` (oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java), `physicalVolumesMap.get(e.getKey())` in the final stream mapping cannot return null: both `logicalVolumesMap` and `physicalVolumesMap` are populated via `computeIfAbsent` inside the same conditional block (`!Util.isBlank(vgName) && !Util.isBlank(lvName)`), so every VG key in `logicalVolumesMap` is guaranteed to have a corresponding entry in `physicalVolumesMap`. Do not flag this `.get()` call as a potential null-return issue. The FFM version uses `getOrDefault` as extra defensiveness, not because null is possible here.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.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/MacFirmwareJNA.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/hardware/common/platform/mac/MacCentralProcessor.java
📚 Learning: 2026-04-12T19:34:56.879Z
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:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
🔇 Additional comments (2)
oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java (2)

36-109: Exception-safe native handle management looks correct.

The nested try/finally structure ensures entry, iter, and platformExpert are released on all paths, including exceptions.


44-79: Null-safe entry-name dispatch is clean and defensive.

Guarding entry.getName() before the switch avoids null-driven failures during IORegistry traversal.


📝 Walkthrough

Walkthrough

Extracted 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

Cohort / File(s) Summary
CPU Processor Base & Implementations
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java, oshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessor.java (deleted), oshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorJNA.java, oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
Added abstract MacCentralProcessor encapsulating macOS CPU identification, topology, caches, feature flags, and frequency logic; removed old concrete impl; added JNA-backed MacCentralProcessorJNA implementing sysctl/IORegistry hooks and tick/load queries; refactored FFM class to extend the new base and supply FFM sysctl hooks.
Firmware Base & Implementations
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacFirmware.java, oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmware.java (deleted), oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java, oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.java
Added abstract MacFirmware with memoized queryEfi() template; removed previous package-private impl; added MacFirmwareJNA to query IORegistry via JNA; updated FFM firmware class to extend new abstract base and expose protected queryEfi().
Disk Store Base & Implementations
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java, oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java, oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
Added abstract MacHWDiskStore holding disk I/O metrics and partition list with protected setters; removed duplicate local state in JNA/FFM classes; updated JNA/FFM implementations to populate stats via superclass setters and renamed JNA class to MacHWDiskStoreJNA.
Network Interface Renames
oshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.java, oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.java
Renamed MacNetworkIFJNA → MacNetworkIfJNA and MacNetworkIFFM → MacNetworkIfFFM; updated constructors, logger references, and call sites.
HAL & Factory Updates
oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java, oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.java, oshi-core/src/main/java/oshi/hardware/platform/mac/MacComputerSystemJNA.java
Updated factory/creation sites to return JNA-specific classes (MacCentralProcessorJNA, MacHWDiskStoreJNA, MacNetworkIfJNA, MacFirmwareJNA) and FFM-specific class names where applicable.
Changelog
CHANGELOG.md
Expanded macOS superclass migration changelog entry to reference multiple PRs and adjusted formatting.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • #3111 — FFM-based macOS HAL migration adding parallel FFM implementations and related platform hooks (overlapping CPU/firmware/disk refactor).
  • #3146 — Core PR performing macOS hardware superclass migration into oshi-common (same migration scope and files).
  • #3109 — Related macOS hardware stack refactor touching processor, firmware, and disk components and native bindings.

Poem

🐰
Hopping through IORegistry light,
I stitched common bases late at night.
JNA and FFM now dance in tune,
Cores, firmware, disks — beneath the moon.
Thump-thump, a shared-path harvest bright.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.21% 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 'Move remaining macOS hardware classes to oshi-common' accurately and concisely describes the main change—completing the migration of macOS hardware superclass implementations to the oshi-common module.

✏️ 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.38%. Comparing base (b0c5e39) to head (63d544c).
⚠️ Report is 1 commits behind head on master.

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.
📢 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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between b0c5e39 and fdc62d0.

📒 Files selected for processing (16)
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacFirmware.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacComputerSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmware.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java
  • oshi-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.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
  • oshi-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.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacFirmwareFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
  • oshi-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.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacNetworkIfJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacComputerSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacFirmwareJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorJNA.java
  • oshi-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.java
  • oshi-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 Supplier plus abstract queryEfi() 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 common MacFirmware is 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 to MacFirmwareJNA, 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_info buffer in a finally block avoids leaking the Mach allocation across repeated CPU-tick queries.

…eption-safe IOKit iteration in MacFirmwareJNA
@dbwiddis
dbwiddis merged commit 6ccc9c4 into oshi:master Apr 12, 2026
15 of 16 checks passed
@dbwiddis
dbwiddis deleted the mac-hw-finish branch April 12, 2026 19:44
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