Repository navigation
Refactor USB device classes to reduce duplication - #3122
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRefactors USB enumeration: moves per-OS enumeration into new JNA-specific helpers (LinuxUsbDeviceJNA, MacUsbDeviceJNA), centralizes device-flattening in AbstractUsbDevice, removes public enumerators from platform base classes, updates HAL delegation to JNA helpers, and normalizes Linux arch detection using Locale.ROOT. Changes
Sequence Diagram(s)sequenceDiagram
participant HAL as Hardware Abstraction Layer
participant JNA as JNA Helper (Linux / Mac)
participant ENUM as System Enumerator (udev / IORegistry)
participant BASE as Platform Base Class (Linux / Mac)
participant ABSTRACT as AbstractUsbDevice
HAL->>+JNA: getUsbDevices(tree)
JNA->>+ENUM: enumerate devices
ENUM-->>-JNA: attribute maps & parent links
JNA->>+BASE: getDeviceAndChildren(...) per controller/root
BASE-->>-JNA: UsbDevice tree(s)
alt tree == false
JNA->>+ABSTRACT: addDevicesToList(flatList, roots)
ABSTRACT->>ABSTRACT: depth-first traverse connected devices
ABSTRACT-->>-JNA: flattened device list
JNA-->>HAL: flattened devices
else tree == true
JNA-->>HAL: controller-rooted device tree
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 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 #3122 +/- ##
==========================================
+ Coverage 66.46% 67.75% +1.28%
==========================================
Files 37 37
Lines 2025 2025
Branches 336 336
==========================================
+ Hits 1346 1372 +26
+ Misses 563 535 -28
- Partials 116 118 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java (1)
39-49:⚠️ Potential issue | 🟡 MinorFix the stale
@param treedescription.The summary paragraph and the implementation on Lines 51-58 both include controllers when
tree == false, but Line 48 still says the flat list excludes them.Also applies to: 51-58
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java` around lines 39 - 49, The Javadoc `@param` description for the method in class WindowsUsbDevice is stale: it states that a flat list (tree == false) excludes controllers, but the method implementation (getUsbDevices(boolean tree) / the USB device-instantiation logic) actually includes controllers in the flat list. Update the `@param` tree description to say: when true returns a hierarchical list of controllers (top-level) with their connected hubs/devices; when false returns a flat list of all devices including controllers. Ensure the wording matches the summary and implementation.oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (1)
45-46:⚠️ Potential issue | 🟡 MinorFix the flat-list Javadoc.
The code below only flattens each controller's
connectedDevices, sotree == falsenow excludes controllers. This text still says the opposite.🤖 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/hardware/platform/linux/LinuxUsbDeviceFFM.java` around lines 45 - 46, The Javadoc for the 'tree' parameter is incorrect: currently it says tree==false returns a flat list including controllers, but the implementation in LinuxUsbDeviceFFM only flattens each controller's connectedDevices and therefore excludes controllers when tree==false. Update the Javadoc on the relevant method in class LinuxUsbDeviceFFM to state that when tree==true it returns controllers with their device tree, and when tree==false it returns a flat list of connected devices (children) excluding controller entries, making explicit that only controllers' connectedDevices are flattened.
🤖 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-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java`:
- Around line 53-54: queryUsbDevices() returns controller root entries, so
calling addDevicesToList(deviceList, devices) for tree == false re-adds
controllers into the flat list; filter out controller-root devices before
adding. Modify the call site where devices is passed to addDevicesToList (the
local variable devices obtained from queryUsbDevices()) so that when the tree
flag is false you pass a filtered collection excluding devices whose parent is
null (i.e., controller roots), e.g., create filteredDevices =
devices.stream().filter(d -> d.getParentUsbDevice() != null).collect(...) and
call addDevicesToList(deviceList, filteredDevices) instead; keep the original
behavior when tree == true. Ensure you reference queryUsbDevices(),
addDevicesToList(), the devices variable, and the tree parameter when making the
change.
In `@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java`:
- Around line 47-53: The Javadoc for the USB listing behavior is inaccurate:
when tree == false the implementation excludes controllers and only adds each
controller's connectedDevices to the flat list. Update the class/method Javadoc
in LinuxUsbDeviceJNA (the method that returns List<oshi.hardware.UsbDevice>,
e.g., the getUsbDevices/getUsbDeviceList method) to state that tree == true
returns controllers with recursive connectedDevices, whereas tree == false
returns a flat list of only non-controller devices (connectedDevices of
controllers) and does not include the controller devices themselves; change both
the descriptive paragraph and the `@param` text to reflect this exact behavior.
In `@oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`:
- Around line 37-47: Update the stale Javadoc in MacUsbDeviceJNA for the method
that instantiates UsbDevice objects so the `@param` tree description matches the
implementation and summary: change the text to state that when tree is true the
method returns top-level controllers with their device trees, and when tree is
false it returns a single flat list of devices including controllers; ensure the
same corrected wording is applied consistently to the summary and the `@param`
tree tag (and any duplicate paragraph blocks in the same Javadoc) so the
documentation matches the behavior.
- Around line 81-105: The code currently uses a default id=0L when
device.getParentEntry(IOSERVICE) is null, then adds that sentinel into
usbControllers and calls addDeviceAndChildrenToMaps, producing bogus root
entries; change the logic so you only add the controller ID to usbControllers
and call addDeviceAndChildrenToMaps when controller != null (i.e., move
usbControllers.add(id) and the addDeviceAndChildrenToMaps(...) call inside the
controller != null branch), ensuring you still release any CFTypeRef and
controller objects as currently done.
---
Outside diff comments:
In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java`:
- Around line 45-46: The Javadoc for the 'tree' parameter is incorrect:
currently it says tree==false returns a flat list including controllers, but the
implementation in LinuxUsbDeviceFFM only flattens each controller's
connectedDevices and therefore excludes controllers when tree==false. Update the
Javadoc on the relevant method in class LinuxUsbDeviceFFM to state that when
tree==true it returns controllers with their device tree, and when tree==false
it returns a flat list of connected devices (children) excluding controller
entries, making explicit that only controllers' connectedDevices are flattened.
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java`:
- Around line 39-49: The Javadoc `@param` description for the method in class
WindowsUsbDevice is stale: it states that a flat list (tree == false) excludes
controllers, but the method implementation (getUsbDevices(boolean tree) / the
USB device-instantiation logic) actually includes controllers in the flat list.
Update the `@param` tree description to say: when true returns a hierarchical list
of controllers (top-level) with their connected hubs/devices; when false returns
a flat list of all devices including controllers. Ensure the wording matches the
summary and implementation.
🪄 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: 6ec8a181-7863-4025-bf1c-18f308fcc47a
📒 Files selected for processing (14)
oshi-core-java25/src/main/java/oshi/ffm/linux/LinuxLibcFunctions.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core/src/main/java/oshi/hardware/common/AbstractUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.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). (7)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, macos-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 25, windows-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (13)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
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:43.357Z
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.
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:18.791Z
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.
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/common/AbstractUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDevice.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
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/linux/LinuxHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDevice.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
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/linux/LinuxHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.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/linux/LinuxHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/common/AbstractUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.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, 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/ffm/linux/LinuxLibcFunctions.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 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/ffm/linux/LinuxLibcFunctions.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/common/AbstractUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-03T18:44:46.910Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:46.910Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.java
📚 Learning: 2026-04-03T18:43:50.370Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:99-100
Timestamp: 2026-04-03T18:43:50.370Z
Learning: In oshi/oshi PlatformEnum.java, the DragonFly BSD detection uses `osName.equalsIgnoreCase("dragonflybsd")` intentionally, mirroring the exact same check in JNA's `Platform.java` source. Java's `os.name` property on DragonFly BSD is "dragonflybsd" (no space), so `startsWith("DragonFly")` is NOT the correct pattern here. Do not suggest changing it to `startsWith`.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.java
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: For OSHI Linux USB device implementations, the behavior of `getUsbDevices(boolean tree)` with `tree=false` is intentional: the returned flat list includes controller nodes (it is not meant to exclude them). In code review, do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded (e.g., Javadoc text like "returns a flat list excluding controllers" should be corrected).
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.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/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
🔇 Additional comments (6)
oshi-core-java25/src/main/java/oshi/ffm/linux/LinuxLibcFunctions.java (2)
22-22: LGTM: Import correctly added.The
Localeimport is necessary for the locale-aware string normalization below.
47-47: Excellent: Locale-independent normalization prevents architecture detection bugs.Replacing
toLowerCase()withtoLowerCase(Locale.ROOT)ensures consistent behavior across all system locales. The platform-defaulttoLowerCase()can produce incorrect results in certain locales (e.g., Turkish locale where uppercase "I" lowercases to dotless "ı" instead of "i"), which could break architecture detection.oshi-core/src/main/java/oshi/hardware/common/AbstractUsbDevice.java (1)
80-91: Nice helper extraction.Centralizing the depth-first flattening here removes the duplicated per-platform copies without changing the traversal shape.
oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDevice.java (1)
51-65: Nice extraction of the shared tree builder.This gives the macOS implementations one place to keep recursion, VID/PID fallback, and child sorting aligned.
oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java (1)
67-70: LGTM.The HAL now points at the extracted JNA USB enumerator, so the wiring stays aligned with the refactor.
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.java (1)
23-35: Nice extraction of the shared Linux USB base.Making the constructors
protectedand moving the recursive builder here keeps the JNA/FFM helpers thin while preserving a single tree-construction path.Also applies to: 51-63
There was a problem hiding this comment.
Actionable comments posted: 3
♻️ Duplicate comments (1)
oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java (1)
53-54:⚠️ Potential issue | 🟠 MajorFlat mode still returns controller roots.
queryUsbDevices()builds controller-level entries, so flatteningdevicesdirectly here re-adds those roots and breaks thetree == falsecontract. Flatten each controller's children instead.🔧 Proposed fix
List<UsbDevice> deviceList = new ArrayList<>(); - addDevicesToList(deviceList, devices); + for (UsbDevice device : devices) { + addDevicesToList(deviceList, device.getConnectedDevices()); + } return deviceList;🤖 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/hardware/platform/mac/MacUsbDeviceFFM.java` around lines 53 - 54, The code currently flattens the entire devices list (which contains controller roots from queryUsbDevices()) by calling addDevicesToList(deviceList, devices), causing controller entries to be re-added when tree == false; instead iterate the top-level controllers in devices and call addDevicesToList(deviceList, controller.getChildren()) (or equivalent) so only each controller's children are flattened into deviceList, preserving the tree==false contract in queryUsbDevices()/addDevicesToList handling.
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java (1)
68-68: Use aSetto deduplicate controller IDs in the collection loop.The current code adds a controller ID to the list once for each device under that controller (line 102 within the device loop). If multiple devices share the same controller parent, duplicate controller IDs accumulate in the list, causing the loop at lines 120-123 to create multiple
UsbDeviceentries for the same controller.Use
LinkedHashSet<Long>to deduplicate:♻️ Proposed fix
- List<Long> usbControllers = new ArrayList<>(); + Set<Long> usbControllers = new LinkedHashSet<>();Windows implementation already uses a
Setto avoid this issue; Linux avoids it by design (only collecting root-level controllers).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` at line 68, The usbControllers collection in MacUsbDeviceJNA is using List<Long> usbControllers = new ArrayList<>() and accumulates duplicate controller IDs when multiple devices share the same parent; replace it with a LinkedHashSet<Long> (or Set<Long>) to deduplicate controller IDs during the device loop so subsequent iteration over usbControllers only processes each controller once, preserving insertion order and preventing creation of duplicate UsbDevice entries.
🤖 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-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java`:
- Around line 92-95: The code currently pushes the fallback anonymous controller
id (0L) into usbControllers for every device whose parent is unknown, causing
repeated synthetic controllers; update the logic around usbControllers.add(id)
(near addDeviceAndChildrenToMaps calls and hubMap usage) to only add id when id
!= 0L or, if id == 0L, add it only once by checking usbControllers.contains(0L)
before adding so the synthetic controller is recorded a single time.
In `@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java`:
- Around line 84-87: Guard the result of Udev.INSTANCE.udev_new() before using
it: check if the returned Udev.UdevContext udev is null and, if so, skip
creating the enumerator and return early (or handle error) to avoid NPEs; only
call udev.enumerateNew() and later udev.unref() when udev != null. Update the
code paths in the method that use udev (references: Udev.INSTANCE.udev_new(),
Udev.UdevContext udev, enumerateNew(), unref()) to follow the same null-guard
pattern used in the other Linux*JNA implementations.
In `@oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`:
- Around line 171-172: The code calls device.getChildIterator(IOUSB) and
immediately uses childIter.next() (in MacUsbDeviceJNA) without checking for a
null iterator; update the logic around IOIterator childIter =
device.getChildIterator(IOUSB) to check whether childIter is null before calling
childIter.next() and handle the null case (e.g., skip processing this device or
return early) to avoid a NullPointerException when getChildIterator returns
null; ensure any downstream use of IORegistryEntry childDevice is guarded
accordingly.
---
Duplicate comments:
In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java`:
- Around line 53-54: The code currently flattens the entire devices list (which
contains controller roots from queryUsbDevices()) by calling
addDevicesToList(deviceList, devices), causing controller entries to be re-added
when tree == false; instead iterate the top-level controllers in devices and
call addDevicesToList(deviceList, controller.getChildren()) (or equivalent) so
only each controller's children are flattened into deviceList, preserving the
tree==false contract in queryUsbDevices()/addDevicesToList handling.
---
Nitpick comments:
In `@oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`:
- Line 68: The usbControllers collection in MacUsbDeviceJNA is using List<Long>
usbControllers = new ArrayList<>() and accumulates duplicate controller IDs when
multiple devices share the same parent; replace it with a LinkedHashSet<Long>
(or Set<Long>) to deduplicate controller IDs during the device loop so
subsequent iteration over usbControllers only processes each controller once,
preserving insertion order and preventing creation of duplicate UsbDevice
entries.
🪄 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: 6874c763-6586-45f7-9eea-596d36b7d984
📒 Files selected for processing (6)
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core/src/main/java/oshi/hardware/HardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java
✅ Files skipped from review due to trivial changes (1)
- oshi-core/src/main/java/oshi/hardware/HardwareAbstractionLayer.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, windows-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (11)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
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:43.357Z
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.
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:18.791Z
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.
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 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/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.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/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
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/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
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/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: For OSHI Linux USB device implementations, the behavior of `getUsbDevices(boolean tree)` with `tree=false` is intentional: the returned flat list includes controller nodes (it is not meant to exclude them). In code review, do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded (e.g., Javadoc text like "returns a flat list excluding controllers" should be corrected).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.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/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.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, 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/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
🔇 Additional comments (13)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java (3)
1-8: LGTM on copyright and import changes.Copyright year update and static import for
Collections.sortare appropriate housekeeping changes.
51-61: Flat-list controller exclusion logic is correct.The implementation properly excludes controllers when
tree=falseby iterating over each controller and callingaddDevicesToListonly ondevice.getConnectedDevices()rather than on the controller itself. This aligns with the Javadoc contract on lines 47-48 and the PR objective to consistently exclude controllers from flat lists across all platforms.
113-113: LGTM on static import usage.Using the statically imported
sortmethod is a clean simplification.oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (4)
26-29: LGTM - Utility class inheriting shared helper methods.The design where
LinuxUsbDeviceFFMextendsLinuxUsbDevicebut is never instantiated is intentional—it allows inheriting the protected staticgetDeviceAndChildren()method while preventing direct instantiation. The private no-arg constructor correctly delegates to the parent's protected constructor.
41-59: LGTM - Controller exclusion correctly implemented.The flat-list behavior now properly excludes controllers by iterating through controller devices and only adding their
getConnectedDevices()to the result list. The Javadoc accurately describes this behavior, aligning with the HardwareAbstractionLayer API contract as stated in the PR objectives.
61-77: LGTM - Clean early-exit pattern with proper error handling.The
queryUsbDevices()method correctly handles error conditions withemptyList()returns. The absence of a null check onudev_enumerate_new()at line 80 is intentional and consistent with OSHI's established pattern—per libudev semantics,udev_enumerate_new()only returns NULL when udev itself is broken, and a successfuludev_new()(which is guarded) implies enumeration will succeed.
149-155: LGTM - Tree building delegated to parent class.The controller device tree construction correctly uses the inherited
getDeviceAndChildren()method fromLinuxUsbDevice. This eliminates code duplication as the same tree-building logic is now shared between the JNA and FFM implementations.oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java (1)
47-53: Tree vs flat USB listing behavior is consistent and clear.
tree=truereturns controller roots;tree=falseflattens only connected devices, excluding controllers. The Javadoc and implementation are aligned.Also applies to: 55-65
oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java (5)
45-46: Javadoc inconsistency with implementation (previously flagged).The
@param treedescription at Line 46 states the flat list "exclud[es] controllers," but the implementation in Lines 49-56 (usingaddDevicesToList) includes controllers in the flattened output. The summary paragraph at Line 43 is also inconsistent.
1-36: LGTM!The class structure follows the utility class pattern correctly with a private constructor and static methods. The inheritance from
MacUsbDeviceprovides access to the sharedgetDeviceAndChildren()method, and the constants are appropriately scoped.
49-57: LGTM!The method correctly delegates to
queryUsbDevices()for tree building and uses the inheritedaddDevicesToList()for flattening, aligning with the refactor's goal of centralizing the flattening logic.
183-239: LGTM!The controller ID lookup correctly cross-references by
locationID, properly manages IOKit resources (releasingpropertyDict,parent,matchingService,serviceIterator), and usesLocale.ROOTfor consistent hex formatting.
139-168: LGTM!The recursive map population correctly handles nullable properties, uses
computeIfAbsentfor clean hub mapping, and applies proper 16-bit masking withLocale.ROOTformatting for vendor/product IDs.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java (1)
85-111:⚠️ Potential issue | 🟠 MajorAvoid collapsing unknown parents into a synthetic
0Lcontroller.When
getParentEntry(IOSERVICE)isnull, this still registers0Las a controller and later materializes it as a fallbackMacUsbDevice(0000:0000,0x0). That makestree=trueexpose a fake top-level controller and merges every orphan subtree under the same root. If those devices need to stay visible, keep them in a separate orphan list instead of keying them under0L.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` around lines 85 - 111, The code currently collapses devices with null controller into a synthetic controller id 0L and adds it to usbControllers; instead, when controller == null do not set id to 0L or add it to usbControllers or nameMap—treat the device as an orphan: create a separate orphan list (e.g., orphanUsbDevices/orphanControllerIds) and pass a sentinel (e.g., null/Optional/absent parent id) into addDeviceAndChildrenToMaps so children are recorded without being grouped under 0L; keep existing behavior for real controllers (use getParentEntry, getRegistryEntryID, getControllerIdByLocation, nameMap, vendorIdMap/productIdMap) but ensure no MacUsbDevice is synthesized for id 0L and adjust downstream consumers that iterate usbControllers to include the orphan list when appropriate.
🧹 Nitpick comments (1)
oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java (1)
70-70: Conditional 0L check is now redundant withLinkedHashSet.The switch to
LinkedHashSet<Long>at line 70 already prevents duplicate entries. The explicit conditional at lines 98-100 is harmless and documents intent, but could be simplified.♻️ Optional simplification
- // If controller is null, id remains 0L, acting as an anonymous catch-all - // controller so that devices whose parent cannot be identified are not lost. - if (id != 0L || !usbControllers.contains(0L)) { - usbControllers.add(id); - } + // If controller is null, id remains 0L, acting as an anonymous catch-all + // controller so that devices whose parent cannot be identified are not lost. + // LinkedHashSet prevents duplicates, so 0L is only added once. + usbControllers.add(id);Also applies to: 96-100
🤖 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/hardware/platform/mac/MacUsbDeviceFFM.java` at line 70, The explicit contains check around adding 0L to usbControllers is redundant because usbControllers is a LinkedHashSet<Long>; replace the conditional block that checks usbControllers.contains(0L) and then adds 0L with a direct usbControllers.add(0L) call in MacUsbDeviceFFM to simplify the code while preserving behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`:
- Around line 85-111: The code currently collapses devices with null controller
into a synthetic controller id 0L and adds it to usbControllers; instead, when
controller == null do not set id to 0L or add it to usbControllers or
nameMap—treat the device as an orphan: create a separate orphan list (e.g.,
orphanUsbDevices/orphanControllerIds) and pass a sentinel (e.g.,
null/Optional/absent parent id) into addDeviceAndChildrenToMaps so children are
recorded without being grouped under 0L; keep existing behavior for real
controllers (use getParentEntry, getRegistryEntryID, getControllerIdByLocation,
nameMap, vendorIdMap/productIdMap) but ensure no MacUsbDevice is synthesized for
id 0L and adjust downstream consumers that iterate usbControllers to include the
orphan list when appropriate.
---
Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java`:
- Line 70: The explicit contains check around adding 0L to usbControllers is
redundant because usbControllers is a LinkedHashSet<Long>; replace the
conditional block that checks usbControllers.contains(0L) and then adds 0L with
a direct usbControllers.add(0L) call in MacUsbDeviceFFM to simplify the code
while preserving behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 03ba235d-dfd7-48ca-affe-2f9248f8f909
📒 Files selected for processing (7)
CHANGELOG.mdoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core/src/main/java/oshi/hardware/HardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java
✅ Files skipped from review due to trivial changes (2)
- CHANGELOG.md
- oshi-core/src/main/java/oshi/hardware/HardwareAbstractionLayer.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). (7)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
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:43.357Z
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.
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:18.791Z
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.
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 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/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.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/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
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/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
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/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-05T16:15:03.230Z
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:03.230Z
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/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: For OSHI Linux USB device implementations, the behavior of `getUsbDevices(boolean tree)` with `tree=false` is intentional: the returned flat list includes controller nodes (it is not meant to exclude them). In code review, do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded (e.g., Javadoc text like "returns a flat list excluding controllers" should be corrected).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.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, 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/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.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/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
🔇 Additional comments (11)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java (2)
43-53: Javadoc now matches the implemented flat/tree behavior.Nice update: the description and
@param treetext are aligned with the actual return behavior and this refactor’s controller-handling intent.
84-145: Udev lifecycle handling is solid here.The
udev_new()guard plus nestedtry/finallyunref()cleanup for context/enumerator/device objects is clean and resilient.oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (3)
24-29: LGTM - Clean refactor to use base class.The class now correctly extends
LinuxUsbDeviceto inherit the sharedgetDeviceAndChildren()tree-builder. Thepublic finalmodifier with private constructor is appropriate for a static utility helper that instantiatesLinuxUsbDeviceobjects rather than itself.
45-58: LGTM - Correct flat-list implementation excluding controllers.The Javadoc accurately describes the new behavior and the implementation correctly excludes controllers from the flat list by iterating over
device.getConnectedDevices()rather than including the controller device itself. This aligns with the PR objective to consistently exclude controllers from flat device lists across all platforms.
149-154: LGTM - Correct delegation to inherited tree-builder.The call to
getDeviceAndChildren()correctly passes the controller path (String) and all required maps to the inherited method fromLinuxUsbDevice, which handles the recursive tree construction.oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java (3)
33-36: LGTM - Clean refactor to use base class.The class now correctly extends
MacUsbDeviceto inherit the sharedgetDeviceAndChildren()tree-builder. Thepublic finalmodifier with private constructor is appropriate for a static utility helper.
50-59: LGTM - Correctly excludes controllers from flat list.The implementation now iterates over
device.getConnectedDevices()to build the flat list, which correctly excludes controller nodes. This addresses the previous review feedback and aligns with the PR objective for consistent controller exclusion across platforms.
114-118: LGTM - Correct delegation to inherited tree-builder.The call to
getDeviceAndChildren()correctly passes the controller registry entry ID (Long) and all required maps to the inherited method fromMacUsbDevice.oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java (1)
56-59: Please confirm the flat-list semantics here.
AbstractUsbDevice.addDevicesToList()(oshi-core/src/main/java/oshi/hardware/common/AbstractUsbDevice.java:86-91) appends the existing tree nodes, sotree=falsenow returns hubs/devices whosegetConnectedDevices()can still be non-empty. That keeps controllers out of the top-level list, but it also means recursive consumers can double-count descendants after asking for a “flat” result. If that behavior is intentional, the Javadoc on Lines 45-48 should probably clarify that only the top-level list is flat.oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java (2)
39-60: Flat-mode filtering matches the docs now.Tree mode returns controller roots, and flat mode only flattens each controller’s connected devices, so controllers stay out of the flat list.
174-185: Good null-guard before recursing into child devices.The
childIter != nullcheck avoids dereferencing a missing iterator before callingnext().
…c, catch-all controller comments, null guards, deduplication, and changelog
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java`:
- Around line 215-234: The loop prematurely sets found=true when either
vendor-id or device-id is found, causing the other ID to remain "0000"; update
the logic in the matchingService loop (which uses variables matchingService,
parent, vendorIdMap, productIdMap, found, and serviceIterator) so that you only
set found=true (and break) after both IDs have been located for the given id.
Concretely, read vendor-id and device-id from parent via getByteArrayProperty as
you already do, store each into vendorIdMap and productIdMap when present, and
only mark found=true (or exit the loop) when both maps contain an entry for id;
otherwise continue iterating serviceIterator.next() to check subsequent
matchingService entries.
🪄 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: 0786fcdc-ca54-4ce7-aebe-cd322aecd81e
📒 Files selected for processing (7)
CHANGELOG.mdoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core/src/main/java/oshi/hardware/HardwareAbstractionLayer.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java
✅ Files skipped from review due to trivial changes (2)
- CHANGELOG.md
- oshi-core/src/main/java/oshi/hardware/HardwareAbstractionLayer.java
🚧 Files skipped from review as they are similar to previous changes (2)
- oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
- oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.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). (1)
- GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (15)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
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:43.357Z
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.
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:09.616Z
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.
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:18.791Z
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.
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java
📚 Learning: 2026-04-06T21:48:09.616Z
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:09.616Z
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/windows/WindowsUsbDevice.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 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/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.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/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: For OSHI Linux USB device implementations, the behavior of `getUsbDevices(boolean tree)` with `tree=false` is intentional: the returned flat list includes controller nodes (it is not meant to exclude them). In code review, do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded (e.g., Javadoc text like "returns a flat list excluding controllers" should be corrected).
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.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, 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/hardware/platform/linux/LinuxUsbDeviceFFM.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/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-06T21:48:09.616Z
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:09.616Z
Learning: In `oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java` and `MacUsbDeviceFFM.java`, treat `id = 0L` as an intentional sentinel when `device.getParentEntry(IOSERVICE)` returns null. This catch-all value groups devices whose controller cannot be identified (even though that edge case is expected not to occur). Do not review it as a bug, do not suggest skipping those devices, and do not propose moving them to the top level without controller context—this design explicitly avoids silently dropping orphaned devices and preserves controller-grouping behavior.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
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/MacUsbDeviceJNA.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
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/MacUsbDeviceJNA.java
📚 Learning: 2026-04-05T16:15:03.230Z
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:03.230Z
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/MacUsbDeviceJNA.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-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/MacUsbDeviceJNA.java
🔇 Additional comments (8)
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (3)
24-29: Good refactoring to utility class pattern.The class is now
public finalwith a private no-arg constructor, correctly implementing the utility class pattern since all methods are static. ExtendingLinuxUsbDeviceallows inheriting the sharedgetDeviceAndChildrenmethod, reducing duplication.
45-46: Controller exclusion in flat mode is now correct per API contract.The implementation now correctly excludes controllers from the flat list by iterating over
device.getConnectedDevices()rather than including the controller device itself:for (UsbDevice device : devices) { addDevicesToList(deviceList, device.getConnectedDevices()); // controllers excluded }This aligns with the PR objective to consistently exclude controllers from the flat device list across all platforms. The Javadoc at lines 45-46 correctly reflects this behavior. Based on learnings, the previous behavior that included controllers was documented as intentional, but this PR explicitly changes that to align with the HardwareAbstractionLayer API contract.
Also applies to: 49-58
61-155: LGTM - queryUsbDevices implementation.The method has been appropriately renamed from the internal
getUsbDevices()toqueryUsbDevices()to avoid confusion with the public API method. The udev enumeration logic is unchanged and correctly:
- Guards
udev_new()for null (line 76)- Does not redundantly guard
udev_enumerate_new()(consistent with established pattern per learnings)- Delegates tree-building to inherited
getDeviceAndChildren(line 151)- Uses statically imported
emptyList()for cleaner codeoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java (4)
2-2: Copyright year update looks good.Standard maintenance update to reflect the current year.
8-8: Static import refactor is acceptable.The static import of
Collections.sortand its use at line 113 is a minor style change that works correctly.Also applies to: 113-113
51-61: Flat list logic correctly excludes controllers and uses shared helper.The refactored code properly excludes USB controllers from the flat list by iterating over controllers but only adding their
getConnectedDevices()to the list via the inheritedaddDevicesToList(). This aligns with the Javadoc contract and the PR objective of consistent controller exclusion across platforms.
83-125: Device tree building logic is sound.The
queryDeviceAndChildrenmethod correctly builds the hierarchical USB device tree by recursively parsing parent-child relationships and constructingWindowsUsbDeviceinstances. The change to use the statically importedsort()is purely stylistic.oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceJNA.java (1)
51-60: Flat-mode filtering looks correct.Flattening from each controller’s
getConnectedDevices()drops the controller roots while preserving every descendant, so this now matches the updated Javadoc and expected HAL behavior.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.java`:
- Line 134: Update the Javadoc return description in the OpenBsdUsbDevice class
by changing the article from "A" to "An" so the line reads "An OpenBsdUsbDevice
corresponding to this device" to fix the grammar in the method/class Javadoc.
🪄 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: 74611f25-4d84-4c96-ba78-6f1add778208
📒 Files selected for processing (13)
oshi-core-java25/src/main/java/oshi/ffm/linux/LinuxLibcFunctions.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core/src/main/java/oshi/SystemInfo.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.javaoshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javapom.xml
✅ Files skipped from review due to trivial changes (3)
- pom.xml
- oshi-core/src/main/java/oshi/SystemInfo.java
- oshi-core-java25/src/main/java/oshi/ffm/linux/LinuxLibcFunctions.java
🚧 Files skipped from review as they are similar to previous changes (4)
- oshi-core/src/main/java/oshi/hardware/platform/mac/MacHardwareAbstractionLayerJNA.java
- oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.java
- oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceJNA.java
- oshi-core/src/main/java/oshi/hardware/platform/mac/MacUsbDevice.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). (11)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Test JDK 11, ubuntu-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 25, ubuntu-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, macos-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (14)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
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:43.357Z
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.
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:09.616Z
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.
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:18.791Z
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.
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: In OSHI's Linux USB device implementations (LinuxUsbDeviceFFM, and the JNA equivalent), when `getUsbDevices(boolean tree)` is called with `tree=false`, the returned flat list intentionally **includes** controller nodes — it does not exclude them. The existing Javadoc that says "returns a flat list excluding controllers" is incorrect. Do not flag the implementation for including controllers in flat mode; instead, flag only the Javadoc if it claims controllers are excluded.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-06T21:48:09.616Z
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:09.616Z
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/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 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/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.javaoshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.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/unix/solaris/SolarisUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.java
📚 Learning: 2026-04-03T18:44:46.910Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:63-66
Timestamp: 2026-04-03T18:44:46.910Z
Learning: In oshi/oshi PlatformEnum.java, the DRAGONFLYBSD enum constant is intentionally added for platform detection only (no implementation classes exist yet). It allows UnsupportedOperationException messages to say "DragonFly BSD" rather than "Unknown". Full DragonFly BSD support is tracked in issue `#2583`. Do not flag the missing switch-case implementations as a bug.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.javaoshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.java
📚 Learning: 2026-04-03T18:43:50.370Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3112
File: oshi-core/src/main/java/oshi/PlatformEnum.java:99-100
Timestamp: 2026-04-03T18:43:50.370Z
Learning: In oshi/oshi PlatformEnum.java, the DragonFly BSD detection uses `osName.equalsIgnoreCase("dragonflybsd")` intentionally, mirroring the exact same check in JNA's `Platform.java` source. Java's `os.name` property on DragonFly BSD is "dragonflybsd" (no space), so `startsWith("DragonFly")` is NOT the correct pattern here. Do not suggest changing it to `startsWith`.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.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/hardware/platform/mac/MacUsbDeviceFFM.javaoshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
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-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
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-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
📚 Learning: 2026-04-05T15:37:16.042Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3117
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java:59-65
Timestamp: 2026-04-05T15:37:16.042Z
Learning: For OSHI Linux USB device implementations, the behavior of `getUsbDevices(boolean tree)` with `tree=false` is intentional: the returned flat list includes controller nodes (it is not meant to exclude them). In code review, do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded (e.g., Javadoc text like "returns a flat list excluding controllers" should be corrected).
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:40:43.357Z
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:43.357Z
Learning: In OSHI’s Linux FFM implementations (e.g., LinuxPowerSourceFFM, LinuxHWDiskStoreFFM, LinuxLogicalVolumeGroupFFM, LinuxUsbDeviceFFM) and the corresponding JNA udev code, do not require/flag a missing null check around `udev_enumerate_new()`/`enumerateNew()`. Per libudev semantics, `udev_enumerate_new()` returns NULL only if udev itself is broken (e.g., OOM). Since `udev_new()` is already guarded and is the successful prerequisite for enumeration, treating `udev_enumerate_new()` as non-null is consistent with the established pattern; adding a redundant null guard would be inconsistent.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.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, 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/hardware/platform/linux/LinuxUsbDeviceFFM.java
📚 Learning: 2026-04-05T05:39:18.791Z
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:18.791Z
Learning: When reviewing OSHI Linux FFM/JNA code that uses libudev, do not flag a missing null check on `udev_enumerate_new()` if `udev_new()` has already been guarded. Per libudev semantics, `udev_enumerate_new()` returns NULL only when the udev context itself is broken (e.g., OOM), so a successful `udev_new()` implies `udev_enumerate_new()` should succeed as well. Therefore, lack of a redundant null guard on `udev_enumerate_new()` is acceptable in this pattern.
Applied to files:
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
🔇 Additional comments (9)
oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisUsbDevice.java (1)
7-8: LGTM! Flattening logic correctly excludes controllers.The refactored
getUsbDevices(tree=false)path now iterates over controller devices and only adds theirgetConnectedDevices()to the flat list via the inheritedaddDevicesToList()helper. This correctly excludes controller nodes from the flat list, aligning with the HardwareAbstractionLayer API contract.Also applies to: 46-56
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsUsbDevice.java (1)
52-62: LGTM! Consistent refactoring pattern applied.The
tree=falsepath correctly excludes controller devices by iterating over them and only adding theirgetConnectedDevices()via the inheritedaddDevicesToList()method.oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdUsbDevice.java (1)
42-52: LGTM! Flattening logic correctly excludes controllers.The implementation follows the consistent refactoring pattern across platforms.
oshi-core/src/main/java/oshi/hardware/platform/unix/freebsd/FreeBsdUsbDevice.java (1)
45-55: LGTM! Consistent implementation with inherited helper.The
tree=falsepath correctly leverages the inheritedaddDevicesToList()fromAbstractUsbDeviceto recursively flatten the device tree while excluding controller nodes.oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (2)
26-29: LGTM! Clean utility class pattern.The class is now
finalwith a private no-arg constructor, extendingLinuxUsbDeviceto inherit the sharedgetDeviceAndChildren()andaddDevicesToList()helpers. This correctly follows the refactoring pattern.
49-59: LGTM! Flattening logic correctly excludes controllers.The
tree=falsepath iterates controller devices and adds only theirgetConnectedDevices(), correctly excluding controller nodes from the flat list.oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java (3)
34-37: LGTM! Clean utility class pattern.The class is now
finalwith a private no-arg constructor, extendingMacUsbDeviceto inherit shared helpers.
51-61: LGTM! Controller exclusion issue addressed.The
tree=falsepath now correctly excludes controller roots by iterating over them and adding only theirgetConnectedDevices()via the inheritedaddDevicesToList()method.
71-71: LGTM! Duplicate controller ID issue addressed.Using
LinkedHashSet<Long>instead of aListensures the anonymous0Lcatch-all controller (and all controller IDs) are added only once while preserving insertion order. The comment at lines 97-98 clearly documents the intentional catch-all behavior.Also applies to: 97-99
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Refactors all USB device classes to eliminate repeated code across platforms.
Changes
AbstractUsbDeviceaddDevicesToList()here asprotected static, removing the identical private copy that existed in FreeBSD, OpenBSD, Solaris, and Windows.Linux
LinuxUsbDeviceas a concrete base class holding the sharedgetDeviceAndChildren()tree-builder.LinuxUsbDeviceJNA.LinuxUsbDeviceFFMnow extendsLinuxUsbDeviceand inheritsgetDeviceAndChildren()instead of duplicating it.Mac
MacUsbDevicebase class with sharedgetDeviceAndChildren(); original implementation renamed toMacUsbDeviceJNA;MacUsbDeviceFFMextendsMacUsbDevice.All platforms
tree=false), matching the API contract documented inHardwareAbstractionLayer.Pre-existing fix
toLowerCase()→toLowerCase(Locale.ROOT)inLinuxLibcFunctions(forbiddenapis violation).Summary by CodeRabbit
New Features
Bug Fixes
Refactor
Documentation
Chores