Skip to content

Begin Linux FFM migration: udev-dependent HAL components - #3117

Merged
dbwiddis merged 12 commits into
oshi:masterfrom
dbwiddis:udev-ffm
Apr 5, 2026
Merged

dbwiddis merged 12 commits into
oshi:masterfrom
dbwiddis:udev-ffm

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Apr 5, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR establishes the foundation for migrating Linux hardware detection from JNA-based libudev bindings to the JDK Foreign Function & Memory (FFM) API introduced in Java 22+. It introduces a parallel class hierarchy where abstract base classes hold shared pure-Java logic, JNA subclasses hold the existing native implementations, and new FFM subclasses provide equivalent implementations using the FFM API.

Motivation

The oshi-core-java25 module targets JDK 25+ and aims to eliminate JNA dependencies in favour of the FFM API. Linux hardware enumeration relies heavily on libudev, making it the natural first target for migration. This PR does not change any existing behaviour for oshi-core users — the JNA path is preserved exactly as before.

Approach

A three-level pattern is used consistently across all migrated classes:

  • Abstract base class — (oshi-core, only if there's shared code) holds shared pure-Java/sysfs logic as the fallback, with protected visibility on all members to support future separation into a common module
  • JNA subclass (oshi-core) — holds the existing udev implementation unchanged
  • FFM subclass (oshi-core-java25) — provides an equivalent udev implementation via UdevFunctions, falling back to the base class sysfs path when libudev is unavailable

Changes

Foundation (oshi-core-java25)

  • UdevFunctions — 20 libudev FFM bindings with 6 convenience helpers; respects oshi.os.linux.allowudev config property
  • LinuxOperatingSystemFFM — exposes HAS_UDEV sourced from UdevFunctions.isAvailable()
  • LinuxOperatingSystemJNA — shell subclass of LinuxOperatingSystem for future JNA method migration
  • LinuxHardwareAbstractionLayerFFM / LinuxHardwareAbstractionLayerJNA — concrete HAL implementations wiring FFM/JNA subclasses respectively

Migrated HAL components (one commit each)

  • LinuxPowerSource → LinuxPowerSourceJNA + LinuxPowerSourceFFM
  • LinuxUsbDevice → LinuxUsbDeviceFFM (no shared fallback; FFM class extends AbstractUsbDevice directly)
  • LinuxHWDiskStore → LinuxHWDiskStoreJNA + LinuxHWDiskStoreFFM
  • LinuxNetworkIF → LinuxNetworkIFJNA + LinuxNetworkIFFFM
  • LinuxLogicalVolumeGroup → LinuxLogicalVolumeGroupJNA + LinuxLogicalVolumeGroupFFM

LinuxHardwareAbstractionLayer is now abstract, with getUsbDevices, getPowerSources, getDiskStores, getNetworkIFs, and getLogicalVolumeGroups removed from the base and delegated to the concrete subclasses.

Not in this PR

LinuxCentralProcessor has three separate udev call sites and warrants its own focused PR. All other HAL methods (createComputerSystem, createMemory, createSensors, getDisplays, getSoundCards, getGraphicsCards, getPrinters) are pure Java/sysfs and remain in the base class.

Summary by CodeRabbit

  • New Features

    • Improved Linux device discovery: new native-backed implementations for disks, USB, network interfaces, power supplies, logical volumes, and OS/hardware detection.
    • Optional libudev support enables richer metadata and incremental updates when available, with graceful fallbacks when unavailable.
  • Chores

    • Changelog updated to document the Linux migration work.

dbwiddis added 6 commits April 4, 2026 19:29
…nuxHardwareAbstractionLayerFFM

- Add UdevFunctions with FFM bindings for all 20 libudev symbols,
  GlobalConfig check, INFO/WARN logging, and 6 convenience helpers
- Add LinuxOperatingSystemFFM extending LinuxOperatingSystem with
  HAS_UDEV = UdevFunctions.isAvailable() for FFM consumer classes
- Add LinuxHardwareAbstractionLayerFFM extending LinuxHardwareAbstractionLayer
  as the entry point for future per-class FFM overrides
- Wire both FFM classes into SystemInfo for Linux
- De-finalize LinuxHardwareAbstractionLayer to allow FFM subclassing,
  consistent with the planned oshi-common / oshi-core / oshi-core-java25
  three-way split where the base class holds non-native shared logic
- De-finalize LinuxPowerSource; strip JNA udev branch leaving sysfs-only
  fallback as the base getPowerSources() implementation
- Add LinuxPowerSourceJNA extending LinuxPowerSource with JNA udev path,
  falling back to super (sysfs) when udev is unavailable
- Add LinuxPowerSourceFFM extending LinuxPowerSource with FFM udev path
  via UdevFunctions, falling back to super (sysfs) on failure
- Override getPowerSources in LinuxHardwareAbstractionLayerJNA to call
  LinuxPowerSourceJNA, and in LinuxHardwareAbstractionLayerFFM to call
  LinuxPowerSourceFFM
- Make LinuxHardwareAbstractionLayer abstract; remove getPowerSources and
  getUsbDevices, forcing subclasses to provide native implementations
- LinuxHardwareAbstractionLayerJNA overrides both, calling LinuxUsbDevice
  and LinuxPowerSource (the existing JNA implementations)
- Add LinuxUsbDeviceFFM extending AbstractUsbDevice directly with FFM
  udev implementation via UdevFunctions
- LinuxHardwareAbstractionLayerFFM overrides both, calling LinuxUsbDeviceFFM
  and LinuxPowerSourceFFM
- Refactor LinuxHWDiskStore into abstract base with all shared fields,
  constants, UdevStat enum, and helpers (computeDiskStats, readMountsMap,
  finalizePartitions, etc.) — all protected for future module separation;
  fields private with protected setters/accessors
- Add LinuxHWDiskStoreJNA extending the base with JNA udev implementation
  and updateAttributes()
- Add LinuxHWDiskStoreFFM extending the base with FFM udev implementation
  via UdevFunctions and updateAttributes()
- Remove getDiskStores from LinuxHardwareAbstractionLayer base; override
  in LinuxHardwareAbstractionLayerJNA and LinuxHardwareAbstractionLayerFFM
@coderabbitai

coderabbitai Bot commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • ✅ Review completed - (🔄 Check again to review again)
📝 Walkthrough

Walkthrough

Adds FFM libudev bindings and FFM-backed Linux discovery implementations in the java25 tree; introduces JNA-backed Linux implementations in the core tree; refactors several Linux-specific classes into abstract bases and moves discovery logic into FFM/JNA-specific classes. SystemInfo dispatch updated accordingly.

Changes

Cohort / File(s) Summary
FFM System Initialization
oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
SystemInfo in java25 now instantiates FFM-backed LinuxOperatingSystemFFM and LinuxHardwareAbstractionLayerFFM.
FFM libudev Bindings
oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java, oshi-core-java25/src/main/java/oshi/ffm/linux/package-info.java
New FFM wrapper for libudev: conditional loading, MethodHandle downcalls, many wrapper helpers, UTF‑8/Arena helpers and isAvailable() gate.
FFM Hardware Implementations
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/*FFM.java
(LinuxHWDiskStoreFFM.java, LinuxNetworkIFFFM.java, LinuxUsbDeviceFFM.java, LinuxPowerSourceFFM.java, LinuxLogicalVolumeGroupFFM.java)
New FFM-backed implementations enumerating disks, partitions, LVM, network IFs, USB and power sources via UdevFunctions and Arenas; handle DM/LVM, mounts, and explicit native cleanup.
FFM OS/HAL
oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java, oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
New FFM OS and HAL classes delegating to FFM-specific discovery and exposing HAS_UDEV.
Core System Initialization
oshi-core/src/main/java/oshi/SystemInfo.java
Core SystemInfo now selects JNA-backed LinuxOperatingSystemJNA and LinuxHardwareAbstractionLayerJNA.
Base Class Refactor (core)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStore.java, .../LinuxHardwareAbstractionLayer.java, .../LinuxNetworkIF.java, .../LinuxLogicalVolumeGroup.java, .../LinuxPowerSource.java
Concrete/final Linux classes converted to abstract bases; many helpers/constructors widened to protected; builtin public discovery methods removed to let backend-specific implementations supply discovery. Attention: visibility and API surface changed for subclasses.
JNA Hardware Implementations (core)
oshi-core/src/main/java/oshi/hardware/platform/linux/*JNA.java
(LinuxHWDiskStoreJNA.java, LinuxNetworkIFJNA.java, LinuxLogicalVolumeGroupJNA.java, LinuxPowerSourceJNA.java, LinuxHardwareAbstractionLayerJNA.java, LinuxOperatingSystemJNA.java, LinuxNetworkIFJNA.java, LinuxPowerSourceJNA.java)
Added JNA-backed counterparts that implement discovery via JNA/libudev and delegate from HAL; mirror FFM features on the core tree.
Changelog
CHANGELOG.md
Added entry for PR initiating Linux FFM migration.

Sequence Diagram(s)

sequenceDiagram
    participant App as Application
    participant HAL as LinuxHardwareAbstractionLayer (FFM/JNA)
    participant Impl as Linux*FFM / Linux*JNA implementations
    participant UdevFFM as UdevFunctions (FFM)
    participant LibUdev as libudev (native)
    participant Arena as Memory Arena

    App->>HAL: request hardware info
    HAL->>Impl: delegate to backend implementation
    alt FFM path
        Impl->>Arena: allocate confined Arena
        Impl->>UdevFFM: udev_new / enumerate / device queries
        UdevFFM->>LibUdev: downcall native symbols
        LibUdev-->>UdevFFM: device entries & properties
        UdevFFM-->>Impl: MemorySegment results
        Impl->>UdevFFM: udev_device_unref / enumerate_unref / udev_unref
        Impl-->>HAL: return constructed model objects
    else JNA path
        Impl->>LibUdev: call JNA udev APIs (create/enumerate/device)
        LibUdev-->>Impl: device objects & properties
        Impl->>LibUdev: unref JNA resources
        Impl-->>HAL: return constructed model objects
    end
    HAL-->>App: return hardware list
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

"🐇 I nibble at bindings in an Arena snug and neat,
I hop through udev trees where sysfs and devices meet,
Disks, nets, USB — I trace each tiny trail,
JNA or FFM, either path will tell the tale,
Hooray — hardware found, with whiskers quick and fleet!"

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.43% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: beginning a migration of Linux FFM (Foreign Function & Memory) implementation for udev-dependent hardware abstraction layer components.

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

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

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Apr 5, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3117      +/-   ##
==========================================
+ Coverage   66.73%   68.51%   +1.77%     
==========================================
  Files          37       37              
  Lines        2023     2023              
  Branches      336      336              
==========================================
+ Hits         1350     1386      +36     
+ Misses        554      527      -27     
+ Partials      119      110       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (2)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java (1)

53-55: Add @Override annotation to getSoundCards() for consistency.

The method getSoundCards() overrides the interface method declared in HardwareAbstractionLayer (line 121), but is missing the @Override annotation that other similar methods in this class (getDisplays, getGraphicsCards, getPrinters) have.

Suggested change
+    `@Override`
     public List<SoundCard> getSoundCards() {
         return LinuxSoundCard.getSoundCards();
     }
🤖 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/linux/LinuxHardwareAbstractionLayer.java`
around lines 53 - 55, The getSoundCards() method in
LinuxHardwareAbstractionLayer is an implementation of the
HardwareAbstractionLayer interface but lacks the `@Override` annotation; add the
`@Override` annotation immediately above the getSoundCards() method declaration in
class LinuxHardwareAbstractionLayer to match other methods like getDisplays,
getGraphicsCards, and getPrinters and ensure consistency.
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java (1)

56-57: Partition association depends on udev enumeration order.

The store variable holds the last-created disk, and partitions are associated with it by checking store.getName().equals(parent.getDevnode()). This works because udev typically enumerates disks before their partitions, but if enumeration order ever changes (e.g., due to udev version differences or async discovery), partitions could be missed or misassociated.

Consider using a Map<String, LinuxHWDiskStoreJNA> keyed by devnode to decouple partition association from enumeration order. This would also eliminate the need for the store variable to carry state across loop iterations.

Also applies to: 116-135

🤖 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/linux/LinuxHWDiskStoreJNA.java`
around lines 56 - 57, The current loop relies on a mutable local `store`
(LinuxHWDiskStoreJNA) to associate partitions by comparing
`store.getName().equals(parent.getDevnode())`, which breaks if udev enumeration
order changes; replace this with a Map<String, LinuxHWDiskStoreJNA> keyed by
each disk's devnode (use disk.getName() or disk.getDevnode() as the key when
creating a LinuxHWDiskStoreJNA and populating `result`), then when you encounter
a partition use parent.getDevnode() to lookup the correct LinuxHWDiskStoreJNA
from the map and add the partition to it; remove the cross-iteration `store`
state and update the logic in the disk/partition processing sections (including
the analogous block around the 116-135 region) to always use
map.get(parent.getDevnode()) for association.
🤖 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/linux/LinuxHWDiskStoreFFM.java`:
- Around line 49-51: The current implementation logs warnings inside getDisks
(e.g., the HAS_UDEV branch) which makes updateAttributes() noisy when it's
called to refresh an existing store; remove or silence LOG.warn calls inside
getDisks (and the related catch block) so it simply returns an empty list on
failure, and move any warning messages into the discovery path where
storeToUpdate == null inside updateAttributes() (or the caller that handles
initial discovery) so only discovery logs warnings; update
LinuxHWDiskStoreFFM.getDisks and ensure
LinuxHWDiskStoreFFM.updateAttributes/getDisks interplay follows this
silent-failure-for-updates behavior.
- Around line 87-110: The DM device branch in LinuxHWDiskStoreFFM treats every
/dev/dm-* as LVM; fetch DM_UUID via UdevFunctions.getPropertyValue(device,
DM_UUID, arena) into devSerial and only run the LVM-specific logic (calling
getPartitionNameForDmDevice, getMountPointOfDmDevice and using
DM_VG_NAME/DM_LV_NAME) when devSerial != null && devSerial.startsWith("LVM-");
otherwise skip building the LVM partition (or handle as a generic DM device) so
dm-crypt/multipath devices aren't misreported as a Logical Volume Group. Ensure
you still set devModel/devSerial appropriately and avoid calling
getPartitionNameForDmDevice/getMountPointOfDmDevice when DM_UUID is not an LVM
identifier.
- Around line 135-152: The code uses the leaf sysname when calling
getDependentNamesFromHoldersDirectory(sysname), which creates a relative
/holders path and misses dependent devices; retrieve the device syspath (e.g.,
call UdevFunctions.getString(UdevFunctions.udev_device_get_syspath(device),
arena) into a variable like sysPath) and pass that syspath to
getDependentNamesFromHoldersDirectory(sysPath) instead of sysname in the
HWPartition fallback.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java`:
- Around line 105-107: The mapping may pass a null pv set into the
LinuxLogicalVolumeGroupFFM constructor; change the stream mapping to supply an
empty set when physicalVolumesMap lacks the key (use
physicalVolumesMap.getOrDefault(e.getKey(), Collections.emptySet()) or
equivalent) so LinuxLogicalVolumeGroupFFM never receives null for the PV set;
reference logicalVolumesMap, physicalVolumesMap and LinuxLogicalVolumeGroupFFM
in the change.

In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java`:
- Around line 44-46: Update LinuxHardwareAbstractionLayerJNA.getPowerSources()
to delegate to LinuxPowerSourceJNA.getPowerSources() instead of
LinuxPowerSource.getPowerSources() so the method uses the JNA/udev-based
discovery with sysfs fallback; locate the getPowerSources() implementation in
class LinuxHardwareAbstractionLayerJNA and replace the call target, and update
any imports/usages to reference LinuxPowerSourceJNA if needed.

---

Nitpick comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java`:
- Around line 53-55: The getSoundCards() method in LinuxHardwareAbstractionLayer
is an implementation of the HardwareAbstractionLayer interface but lacks the
`@Override` annotation; add the `@Override` annotation immediately above the
getSoundCards() method declaration in class LinuxHardwareAbstractionLayer to
match other methods like getDisplays, getGraphicsCards, and getPrinters and
ensure consistency.

In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java`:
- Around line 56-57: The current loop relies on a mutable local `store`
(LinuxHWDiskStoreJNA) to associate partitions by comparing
`store.getName().equals(parent.getDevnode())`, which breaks if udev enumeration
order changes; replace this with a Map<String, LinuxHWDiskStoreJNA> keyed by
each disk's devnode (use disk.getName() or disk.getDevnode() as the key when
creating a LinuxHWDiskStoreJNA and populating `result`), then when you encounter
a partition use parent.getDevnode() to lookup the correct LinuxHWDiskStoreJNA
from the map and add the partition to it; remove the cross-iteration `store`
state and update the logic in the disk/partition processing sections (including
the analogous block around the 116-135 region) to always use
map.get(parent.getDevnode()) for association.
🪄 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: 7da7af40-19d2-4196-9d02-141b148a51a3

📥 Commits

Reviewing files that changed from the base of the PR and between d6d7614 and 37b529f.

📒 Files selected for processing (22)
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/package-info.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroup.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.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 25, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (4)
📚 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/package-info.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.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-java25/src/main/java/oshi/ffm/SystemInfo.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • 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-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/linux/LinuxHWDiskStore.java
🔇 Additional comments (16)
oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java (1)

46-47: LGTM! Correct wiring of FFM implementations for Linux.

The Linux platform case now correctly instantiates LinuxOperatingSystemFFM and LinuxHardwareAbstractionLayerFFM, consistent with the FFM approach already used for macOS.

Also applies to: 59-60

oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java (1)

19-28: LGTM! Clean FFM operating system wrapper.

The class correctly exposes HAS_UDEV computed from UdevFunctions.isAvailable(), providing a single point for FFM consumers to check udev availability. The Javadoc clearly documents the intended usage pattern.

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java (2)

29-29: LGTM! Appropriate visibility changes for subclassing.

The class is correctly de-finalized, and Prop enum and buildPowerSource() are made protected to support the JNA/FFM subclass hierarchy while keeping the implementation details encapsulated.

Also applies to: 31-31, 100-100


71-98: LGTM! Clean sysfs-based power source discovery.

The implementation correctly:

  • Lists /sys/class/power_supply entries
  • Filters out adapters (ADP*, AC*, USBC)
  • Parses uevent files using the PropByName lazy-init pattern
  • Only adds sources where POWER_SUPPLY_PRESENT > 0

This provides a reliable sysfs fallback when udev is unavailable.

oshi-core/src/main/java/oshi/SystemInfo.java (1)

77-79: LGTM! Correct JNA implementation wiring for oshi-core module.

The oshi-core module correctly instantiates LinuxOperatingSystemJNA and LinuxHardwareAbstractionLayerJNA for Linux/Android platforms, maintaining backward compatibility while the FFM variants are available in the oshi-core-java25 module.

Also applies to: 108-110

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java (1)

21-46: LGTM! Clean JNA hardware abstraction layer.

The class correctly overrides the five hardware query methods that were removed from the abstract base class. Each method delegates to the appropriate JNA-backed or sysfs-based implementation.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java (1)

21-46: LGTM! Clean FFM hardware abstraction layer.

The class correctly mirrors the JNA variant's structure, overriding the five hardware query methods and delegating to FFM-backed implementations. The symmetric design with LinuxHardwareAbstractionLayerJNA maintains consistency across the module boundary.

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java (1)

26-26: LGTM! Correct abstract base class design.

Making the class abstract properly enforces that concrete implementations (LinuxHardwareAbstractionLayerJNA, LinuxHardwareAbstractionLayerFFM) must provide the five platform-specific hardware query methods while inheriting the shared pure-Java implementations.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java (2)

36-69: LGTM! Robust udev query implementation with proper fallbacks.

The queryIfModel method correctly implements the three-tier fallback pattern:

  1. Early return to sysfs if HAS_UDEV is false (line 38-40)
  2. Sysfs fallback if udev_new() returns NULL (line 43-45)
  3. Returns interface name on any exception (line 65-68)

Resource cleanup is properly handled with nested try-finally blocks ensuring udev_device_unref and udev_unref are always called. The Arena.ofConfined() with try-with-resources ensures memory segments are deallocated.


77-87: LGTM! Clean factory method with proper error handling.

The getNetworks method correctly iterates over network interfaces, instantiates LinuxNetworkIFFFM for each, and gracefully handles InstantiationException by logging at debug level and continuing. This ensures one failing interface doesn't prevent others from being enumerated.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java (1)

1-107: LGTM!

The FFM-based power source implementation correctly:

  • Falls back to sysfs when udev is unavailable
  • Properly manages FFM resources with Arena and try-finally blocks
  • Handles the EnumMap population safely (missing keys are handled by buildPowerSource's use of getOrDefault and null-safe parsing)
  • Falls back gracefully on any Throwable during enumeration
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java (1)

1-93: LGTM!

The JNA-based power source implementation mirrors the FFM version appropriately with proper resource cleanup via try-finally blocks and consistent filtering/property collection logic.

oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java (3)

60-152: Solid FFM binding implementation with proper all-or-nothing initialization.

The static initializer correctly:

  • Respects the oshi.os.linux.allowudev configuration option
  • Uses findOrThrow for all symbols, ensuring consistent availability state
  • Catches Throwable to handle any FFM initialization failures gracefully
  • Assigns all handles atomically at the end, preventing partial initialization

86-86: Both libraryLookup and LINKER are properly defined in the ForeignFunctions parent class.

libraryLookup(String libraryName) is a public static method that maps the platform-independent library name to the platform-specific filename, and LINKER is a protected static field initialized with Linker.nativeLinker(). Both are correctly inherited and accessible from UdevFunctions.


409-411: Delegation to parent class method is correct.

getString properly delegates to getStringFromNativePointer, which is inherited from ForeignFunctions.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (1)

180-180: No action needed. UsbDevice extends Comparable<UsbDevice>, so Collections.sort(usbDevices) at line 180 is safe and will not throw a ClassCastException.

			> Likely an incorrect or invalid review comment.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java (1)

128-130: Consider logging exception details for debugging.

When symbol binding fails, the current warning message doesn't include which symbol failed or the exception type. This could make troubleshooting harder.

🔧 Optional: Include exception details
         } catch (Throwable e) {
-            LOG.warn("Did not find udev library in operating system. Some features may not work.");
+            LOG.warn("Did not find udev library in operating system. Some features may not work: {}", e.getMessage());
         }
🤖 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/ffm/linux/UdevFunctions.java` around
lines 128 - 130, The catch block in UdevFunctions currently swallows the
Throwable and logs a generic warning via LOG.warn; update the catch for
Throwable e to include exception details and the failing symbol information in
the log call (e.g., LOG.warn("Did not find udev library... failed symbol: {} -
{}", symbolName, e.toString()) or similar), ensuring you reference the LOG.warn
call in class UdevFunctions and surface e (and any symbolName or binding
identifier available where symbol binding occurs) so the logged message contains
both the symbol that failed and the exception details for easier debugging.
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (1)

138-166: Partition enumeration relies on device order assumption.

The logic at line 138 (store != null) and line 144 (store.getName().equals(parentDevnode)) assumes that udev enumerates disk devices before their partitions. While this is typically true for Linux sysfs traversal, it's not strictly guaranteed by the udev API.

This matches the existing JNA implementation pattern, so it's acceptable, but worth noting that reordering in future udev versions could cause partitions to be missed.

If robustness is desired, consider a two-pass approach: first collect all disks into a map, then iterate partitions and look up their parent disks by devnode. However, this would be a larger refactor and the current approach works in practice.

🤖 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/LinuxHWDiskStoreFFM.java`
around lines 138 - 166, The current partition-add logic in the block checking
storeToUpdate == null && store != null && PARTITION assumes parent disks are
processed before partitions, which can miss partitions if udev order differs;
replace with a two-pass approach: in the first pass collect all disk stores into
a Map keyed by devnode (use store.getName() as key when creating HWDeviceStore
entries), then in a second pass iterate devices where devtype == PARTITION and
look up the parent device devnode (via
UdevFunctions.getParentWithSubsystemDevtype and
getString(udev_device_get_devnode, arena)) in that map to find the parent store
and call store.getMutablePartitionList().add(new HWPartition(...)); update or
remove the old conditional that relied on store != null and
store.getName().equals(parentDevnode) and ensure
mountsMap/getDependentNamesFromHoldersDirectory, ParseUtil calls, and properties
(ID_FS_TYPE, ID_FS_UUID, ID_FS_LABEL, SIZE, MAJOR, MINOR) are used unchanged
when creating HWPartition.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java`:
- Around line 128-130: The catch block in UdevFunctions currently swallows the
Throwable and logs a generic warning via LOG.warn; update the catch for
Throwable e to include exception details and the failing symbol information in
the log call (e.g., LOG.warn("Did not find udev library... failed symbol: {} -
{}", symbolName, e.toString()) or similar), ensuring you reference the LOG.warn
call in class UdevFunctions and surface e (and any symbolName or binding
identifier available where symbol binding occurs) so the logged message contains
both the symbol that failed and the exception details for easier debugging.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java`:
- Around line 138-166: The current partition-add logic in the block checking
storeToUpdate == null && store != null && PARTITION assumes parent disks are
processed before partitions, which can miss partitions if udev order differs;
replace with a two-pass approach: in the first pass collect all disk stores into
a Map keyed by devnode (use store.getName() as key when creating HWDeviceStore
entries), then in a second pass iterate devices where devtype == PARTITION and
look up the parent device devnode (via
UdevFunctions.getParentWithSubsystemDevtype and
getString(udev_device_get_devnode, arena)) in that map to find the parent store
and call store.getMutablePartitionList().add(new HWPartition(...)); update or
remove the old conditional that relied on store != null and
store.getName().equals(parentDevnode) and ensure
mountsMap/getDependentNamesFromHoldersDirectory, ParseUtil calls, and properties
(ID_FS_TYPE, ID_FS_UUID, ID_FS_LABEL, SIZE, MAJOR, MINOR) are used unchanged
when creating HWPartition.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eeec8a7c-a933-4f16-81dc-1f0a1b2898a1

📥 Commits

Reviewing files that changed from the base of the PR and between 37b529f and 420e4c0.

📒 Files selected for processing (6)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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 25, windows-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 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/LinuxHWDiskStoreFFM.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/UdevFunctions.java
🪛 markdownlint-cli2 (0.22.0)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (8)
oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java (3)

1-34: Well-structured FFM binding class.

The class correctly implements the FFM binding pattern with:

  • Private constructor preventing instantiation
  • Static final fields for all native function handles
  • Availability check via isAvailable() method

The Javadoc clearly documents the contract that callers must check availability and unref resources when done.


292-301: Important ownership documentation.

The Javadoc correctly documents that the returned parent device handle is owned by the child and should not be unref'd separately. This is a critical detail that prevents double-free bugs.


399-484: Well-designed convenience helpers.

The helper methods follow a consistent pattern:

  • Allocate native UTF-8 strings in the provided Arena
  • Call the underlying native function
  • Convert results back to Java types

This reduces boilerplate for callers and ensures proper string encoding.

CHANGELOG.md (1)

3-4: Changelog entry follows project conventions.

The heading level (#####) matches the established pattern used throughout the changelog file (see line 17 "##### Bug fixes / Improvements" under version 6.11.0). The static analysis warning about heading increment is a false positive in this context.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (4)

31-46: Clean public API design.

The class follows the established pattern:

  • Package-private constructor (called only from getDisks)
  • Single public static factory method getDisks()
  • @ThreadSafe annotation correctly applied to a final class with immutable fields after construction

59-178: Excellent resource management.

The nested try-finally blocks ensure proper cleanup of all native resources:

  • Arena.ofConfined() - auto-closed by try-with-resources
  • udev context - unref'd in outermost finally (line 177)
  • enumerate handle - unref'd in middle finally (line 174)
  • device handles - unref'd in innermost finally (line 170)
  • Parent device from getParentWithSubsystemDevtype - correctly NOT unref'd (owned by child per libudev API)

95-120: LVM-specific handling correctly gated.

The code properly distinguishes LVM logical volumes from other device-mapper types:

  • All DM devices are identified with model "Logical Volume Group" and DM_UUID as serial
  • LVM-specific partition metadata (VG name, LV name, mount point) is only extracted when devSerial.startsWith("LVM-") (line 100)
  • This prevents dm-crypt/multipath devices from being misreported with bogus LVM partition names

179-192: Error handling follows OSHI FFM conventions.

The implementation correctly follows the learned pattern:

  • Catches Throwable and returns empty list (line 183)
  • Only logs warnings during discovery (storeToUpdate == null), not during attribute updates
  • updateAttributes() returns false (via empty list) silently on failure

This ensures updateAttributes() has the expected boolean failure API without noisy logs. Based on learnings, OSHI FFM updateAttributes() implementations are expected to return false on failure without logging.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java (1)

56-60: Add NULL check after udev_new() for consistency.

udev_new() can return NULL on failure (e.g., memory allocation error). While the outer catch (Throwable) would handle any resulting NPE, an explicit check would be cleaner and consistent with LinuxHWDiskStoreFFM.java (lines 61-66) which checks if (MemorySegment.NULL.equals(udev)).

♻️ Suggested improvement
         try (Arena arena = Arena.ofConfined()) {
             MemorySegment udev = UdevFunctions.udev_new();
+            if (MemorySegment.NULL.equals(udev)) {
+                LOG.warn("Failed to create udev context for power source enumeration.");
+                return LinuxPowerSource.getPowerSources();
+            }
             try {
                 MemorySegment enumerate = UdevFunctions.udev_enumerate_new(udev);
🤖 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/LinuxPowerSourceFFM.java`
around lines 56 - 60, Add an explicit NULL check immediately after calling
UdevFunctions.udev_new() in the try-with-resources block: detect
MemorySegment.NULL.equals(udev) and handle it the same way as
LinuxHWDiskStoreFFM (log or throw an appropriate exception / return early)
before proceeding to call udev_enumerate_new and other UDEV functions; ensure
any created Arena is closed by the existing try-with-resources and do not call
further UDEV functions if udev is NULL.
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (1)

138-167: Partition association relies on enumeration order.

The code adds partitions only to the most recently created disk (store) if its name matches the parent devnode. Partitions whose parent disk was enumerated earlier (not the most recent) would be silently skipped.

This matches the existing JNA implementation pattern, so behavioral parity is maintained. However, a more robust approach would search the result list for the matching parent disk.

♻️ Optional improvement for robustness
                             } else if (storeToUpdate == null && store != null && PARTITION.equals(devtype)) {
                                 MemorySegment parent = UdevFunctions.getParentWithSubsystemDevtype(device, BLOCK,
                                         DISK, arena);
                                 if (!MemorySegment.NULL.equals(parent)) {
                                     String parentDevnode = UdevFunctions
                                             .getString(UdevFunctions.udev_device_get_devnode(parent), arena);
-                                    if (store.getName().equals(parentDevnode)) {
+                                    // Find matching disk in result list (supports out-of-order enumeration)
+                                    LinuxHWDiskStoreFFM parentStore = null;
+                                    for (HWDiskStore ds : result) {
+                                        if (ds.getName().equals(parentDevnode)) {
+                                            parentStore = (LinuxHWDiskStoreFFM) ds;
+                                            break;
+                                        }
+                                    }
+                                    if (parentStore != null) {
                                         String name = devnode;
                                         // ... rest of partition handling uses parentStore instead of store
🤖 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/LinuxHWDiskStoreFFM.java`
around lines 138 - 167, The partition association currently only adds a
partition to the most-recently-created local variable store when its name equals
parentDevnode, which skips disks enumerated earlier; change the logic in the
block handling PARTITION (where getParentWithSubsystemDevtype(...) is called and
parentDevnode is retrieved) to search the existing result list for a disk whose
getName().equals(parentDevnode) (or fall back to store if desired), assign that
disk to a targetStore variable (instead of assuming store), and then call
targetStore.getMutablePartitionList().add(new HWPartition(...)) so partitions
are added to the correct parent disk (ensure you reference result, store,
storeToUpdate, HWPartition, getParentWithSubsystemDevtype, and
getMutablePartitionList in the change).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java`:
- Around line 138-167: The partition association currently only adds a partition
to the most-recently-created local variable store when its name equals
parentDevnode, which skips disks enumerated earlier; change the logic in the
block handling PARTITION (where getParentWithSubsystemDevtype(...) is called and
parentDevnode is retrieved) to search the existing result list for a disk whose
getName().equals(parentDevnode) (or fall back to store if desired), assign that
disk to a targetStore variable (instead of assuming store), and then call
targetStore.getMutablePartitionList().add(new HWPartition(...)) so partitions
are added to the correct parent disk (ensure you reference result, store,
storeToUpdate, HWPartition, getParentWithSubsystemDevtype, and
getMutablePartitionList in the change).

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java`:
- Around line 56-60: Add an explicit NULL check immediately after calling
UdevFunctions.udev_new() in the try-with-resources block: detect
MemorySegment.NULL.equals(udev) and handle it the same way as
LinuxHWDiskStoreFFM (log or throw an appropriate exception / return early)
before proceeding to call udev_enumerate_new and other UDEV functions; ensure
any created Arena is closed by the existing try-with-resources and do not call
further UDEV functions if udev is NULL.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f0b471a-a713-4e6c-9503-b79e3f4862db

📥 Commits

Reviewing files that changed from the base of the PR and between 420e4c0 and f538df2.

📒 Files selected for processing (5)
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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). (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (3)
📚 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/LinuxPowerSourceFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.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/UdevFunctions.java
📚 Learning: 2026-03-29T20:03:00.830Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java25/src/main/java/oshi/util/platform/windows/PdhUtilFFM.java:87-89
Timestamp: 2026-03-29T20:03:00.830Z
Learning: In the OSHI FFM codebase (oshi-core-java25), all PDH/Kernel32/COM wrapper methods in classes like PdhFFM, Kernel32FFM, etc. declare `throws Throwable` solely as a compiler artifact of `MethodHandle.invokeExact`. They are native calls and do not throw Java checked exceptions in practice. The enclosing `getOpenFileDescriptors()` method in PdhUtilFFM already has an outer `catch (Throwable t)` that covers the entire method body including any `finally` blocks, so no exception-masking concern exists for cleanup calls like `PdhCloseQuery` in `finally`.

Applied to files:

  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java
🔇 Additional comments (9)
oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java (4)

60-152: LGTM! Static initialization handles binding failures gracefully.

The static initializer correctly:

  • Respects the oshi.os.linux.allowudev config with proper default
  • Uses local variables before assigning to final fields to ensure consistency
  • Sets AVAILABLE=false if any binding fails, preventing partial initialization
  • Logs informative messages on configuration skip or binding failure

162-171: Good fallback strategy for library loading.

The approach of trying the unversioned name first, then falling back to known versioned sonames (libudev.so.1, libudev.so.0), correctly handles both development and runtime-only Linux environments.


178-416: LGTM! Clean wrapper methods with proper Javadoc.

The wrapper methods correctly:

  • Use invokeExact() with proper casts for the FFM API
  • Declare throws Throwable as required by MethodHandle.invokeExact (compiler artifact)
  • Document ownership semantics for parent device handles (important for avoiding double-unref)

Based on learnings, the throws Throwable pattern is expected for OSHI FFM wrapper methods.


428-503: LGTM! Well-designed convenience helpers.

The helper methods:

  • Reduce boilerplate for common udev operations
  • Properly allocate native strings in the caller-provided arena
  • Handle null results gracefully via getStringFromNativePointer
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java (2)

29-44: LGTM! Clean class structure.

The FFM variant correctly extends LinuxPowerSource and delegates constructor parameters to the parent, maintaining the established pattern.


78-94: LGTM! Correct property enumeration pattern.

The code correctly:

  • Filters to devices where POWER_SUPPLY_PRESENT > 0
  • Iterates all Prop enum values using p.name() as the udev property key
  • Properly unrefs the device handle in the finally block
  • Delegates to buildPowerSource() from the parent class
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (3)

30-37: LGTM! Appropriate class design.

Package-private constructor correctly enforces use of the getDisks() factory method.


48-66: LGTM! Proper conditional logging for the updateAttributes() path.

Warnings are correctly gated on storeToUpdate == null, ensuring that updateAttributes() failures remain silent per the established OSHI pattern.


189-192: LGTM! updateAttributes() follows the established pattern.

The implementation correctly:

  • Delegates to getDisks(this) which updates stats via computeDiskStats()
  • Returns false (empty list) on failure without logging (per the retrieved learning)
  • Returns true when the disk is found and updated

Based on learnings, this matches the expected OSHI FFM updateAttributes() contract.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/linux/LinuxPowerSourceFFM.java`:
- Around line 62-65: Guard the MemorySegment returned by
UdevFunctions.udev_enumerate_new(udev) (variable enumerate) for
MemorySegment.NULL before calling UdevFunctions.addMatchSubsystem(enumerate,
...), UdevFunctions.udev_enumerate_scan_devices(enumerate) and any subsequent
uses; if enumerate is NULL, skip the enumeration logic and return the existing
fallback path. Also only call UdevFunctions.udev_enumerate_unref(enumerate)
during cleanup when enumerate is not MemorySegment.NULL to avoid unref on a null
segment. Ensure checks reference the enumerate variable and use
MemorySegment.NULL as the sentinel.
🪄 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: 2c0b20e6-cdd0-4cff-ac82-f486c421f952

📥 Commits

Reviewing files that changed from the base of the PR and between f538df2 and 9129f5f.

📒 Files selected for processing (1)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.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). (6)
  • GitHub Check: Codacy Static Code Analysis
  • 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 21, macos-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (1)
📚 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/LinuxPowerSourceFFM.java
🔇 Additional comments (1)
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java (1)

57-60: Good defensive fallback on failed udev_new().

The null-pointer guard on Line 58 with immediate sysfs fallback keeps this path robust under partial libudev failures.

@dbwiddis

dbwiddis commented Apr 5, 2026

Copy link
Copy Markdown
Member Author

@CodeRabbit full review

@coderabbitai

coderabbitai Bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Full review triggered.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

♻️ Duplicate comments (3)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java (2)

79-99: ⚠️ Potential issue | 🟠 Major

Don't treat every /dev/dm-* disk as LVM.

On dm-crypt or multipath devices, DM_VG_NAME and DM_LV_NAME can be absent. This branch still rewrites the disk as Logical Volume Group and builds LVM-specific names from null components, so non-LVM mapper devices are misreported.

Minimal fix
                                     if (devnode.startsWith(DevPath.DM)) {
-                                        devModel = LOGICAL_VOLUME_GROUP;
                                         devSerial = device.getPropertyValue(DM_UUID);
-                                        store = new LinuxHWDiskStoreJNA(devnode, devModel,
-                                                devSerial == null ? Constants.UNKNOWN : devSerial, devSize);
-                                        String vgName = device.getPropertyValue(DM_VG_NAME);
-                                        String lvName = device.getPropertyValue(DM_LV_NAME);
-                                        store.getMutablePartitionList()
-                                                .add(new HWPartition(getPartitionNameForDmDevice(vgName, lvName),
-                                                        device.getSysname(),
-                                                        device.getPropertyValue(ID_FS_TYPE) == null ? PARTITION
-                                                                : device.getPropertyValue(ID_FS_TYPE),
-                                                        device.getPropertyValue(ID_FS_UUID) == null ? ""
-                                                                : device.getPropertyValue(ID_FS_UUID),
-                                                        device.getPropertyValue(ID_FS_LABEL) == null ? ""
-                                                                : device.getPropertyValue(ID_FS_LABEL),
-                                                        ParseUtil.parseLongOrDefault(device.getSysattrValue(SIZE), 0L)
-                                                                * SECTORSIZE,
-                                                        ParseUtil.parseIntOrDefault(device.getPropertyValue(MAJOR), 0),
-                                                        ParseUtil.parseIntOrDefault(device.getPropertyValue(MINOR), 0),
-                                                        getMountPointOfDmDevice(vgName, lvName)));
+                                        boolean isLvm = devSerial != null && devSerial.startsWith("LVM-");
+                                        store = new LinuxHWDiskStoreJNA(devnode,
+                                                isLvm ? LOGICAL_VOLUME_GROUP
+                                                        : devModel == null ? Constants.UNKNOWN : devModel,
+                                                devSerial == null ? Constants.UNKNOWN : devSerial, devSize);
+                                        if (isLvm) {
+                                            String vgName = device.getPropertyValue(DM_VG_NAME);
+                                            String lvName = device.getPropertyValue(DM_LV_NAME);
+                                            store.getMutablePartitionList()
+                                                    .add(new HWPartition(getPartitionNameForDmDevice(vgName, lvName),
+                                                            device.getSysname(),
+                                                            device.getPropertyValue(ID_FS_TYPE) == null ? PARTITION
+                                                                    : device.getPropertyValue(ID_FS_TYPE),
+                                                            device.getPropertyValue(ID_FS_UUID) == null ? ""
+                                                                    : device.getPropertyValue(ID_FS_UUID),
+                                                            device.getPropertyValue(ID_FS_LABEL) == null ? ""
+                                                                    : device.getPropertyValue(ID_FS_LABEL),
+                                                            ParseUtil.parseLongOrDefault(
+                                                                    device.getSysattrValue(SIZE), 0L) * SECTORSIZE,
+                                                            ParseUtil.parseIntOrDefault(
+                                                                    device.getPropertyValue(MAJOR), 0),
+                                                            ParseUtil.parseIntOrDefault(
+                                                                    device.getPropertyValue(MINOR), 0),
+                                                            getMountPointOfDmDevice(vgName, lvName)));
+                                        }
                                     } else {
🤖 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/linux/LinuxHWDiskStoreJNA.java`
around lines 79 - 99, The code treats every DevPath.DM device as LVM
unconditionally; update the branch in LinuxHWDiskStoreJNA so it first reads
device.getPropertyValue(DM_VG_NAME) and device.getPropertyValue(DM_LV_NAME) and
only set devModel = LOGICAL_VOLUME_GROUP and call
getPartitionNameForDmDevice/getMountPointOfDmDevice when both vgName and lvName
are non-null/non-empty; otherwise preserve the original devModel/devSerial and
create a generic partition entry (or skip LVM-specific name resolution) using
available properties (e.g., DM_UUID and device.getSysname()) so non-LVM mapper
devices (dm-crypt/multipath) are not misidentified.

132-133: ⚠️ Potential issue | 🟡 Minor

Use the sysfs path for the holders fallback.

getDependentNamesFromHoldersDirectory() appends /holders; passing device.getSysname() on Line 133 makes it probe a relative path like sda1/holders, so the fallback never resolves dependent names when /proc/mounts has no entry.

Minimal fix
                                                 mountsMap.getOrDefault(name,
-                                                        getDependentNamesFromHoldersDirectory(device.getSysname()))));
+                                                        getDependentNamesFromHoldersDirectory(syspath))));
🤖 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/linux/LinuxHWDiskStoreJNA.java`
around lines 132 - 133, The fallback to getDependentNamesFromHoldersDirectory is
using device.getSysname(), which builds a relative path (e.g., "sda1/holders")
and fails to find entries; change the argument to the device's sysfs absolute
path by passing device.getSysfsPath() to getDependentNamesFromHoldersDirectory
inside the mountsMap.getOrDefault(...) call (keep the rest of the expression
identical so dependent name probing uses the correct sysfs/holders path).
oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (1)

95-100: ⚠️ Potential issue | 🟠 Major

Only relabel /dev/dm-* disks when DM_UUID is actually LVM.

Line 96 rewrites every mapper disk to Logical Volume Group before the LVM- check on Line 100. dm-crypt and multipath devices will still be reported as LVM even though the LVM-only partition block is skipped.

Minimal fix
                                     if (devnode.startsWith(DevPath.DM)) {
-                                        devModel = LOGICAL_VOLUME_GROUP;
                                         devSerial = UdevFunctions.getPropertyValue(device, DM_UUID, arena);
-                                        store = new LinuxHWDiskStoreFFM(devnode, devModel,
+                                        boolean isLvm = devSerial != null && devSerial.startsWith("LVM-");
+                                        store = new LinuxHWDiskStoreFFM(devnode,
+                                                isLvm ? LOGICAL_VOLUME_GROUP
+                                                        : devModel == null ? Constants.UNKNOWN : devModel,
                                                 devSerial == null ? Constants.UNKNOWN : devSerial, devSize);
-                                        if (devSerial != null && devSerial.startsWith("LVM-")) {
+                                        if (isLvm) {
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIF.java (1)

38-40: Avoid calling updateAttributes() from an abstract base constructor.

Now that LinuxNetworkIF is abstract, Line 40 can dispatch to a subclass override before the subclass constructor has run. Moving the refresh into the concrete constructors, or making updateAttributes() final here, removes that initialization hazard.

🤖 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/linux/LinuxNetworkIF.java`
around lines 38 - 40, The abstract class LinuxNetworkIF currently calls
updateAttributes() from its constructor (protected LinuxNetworkIF(...)), which
can dispatch to subclass overrides before subclass construction completes; to
fix, remove the updateAttributes() call from the LinuxNetworkIF constructor and
instead call updateAttributes() from each concrete subclass constructor after
their own initialization, or alternatively declare updateAttributes() as final
in LinuxNetworkIF so it cannot be overridden; update the implementations
accordingly (referencing the LinuxNetworkIF constructor and the
updateAttributes() method) to ensure initialization occurs only after subclass
construction is complete.
🤖 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/linux/LinuxLogicalVolumeGroupFFM.java`:
- Around line 47-50: The call to UdevFunctions.udev_enumerate_new(udev) must be
guarded because UdevFunctions.udev_new() can return MemorySegment.NULL; update
the logic in LinuxLogicalVolumeGroupFFM (around the try-with-resources using
Arena and the variable MemorySegment udev) to check if udev ==
MemorySegment.NULL before calling UdevFunctions.udev_enumerate_new(udev) and, if
NULL, skip enumeration and return or fall back to Collections.emptyList() (or
otherwise close the arena and continue the best-effort path); ensure any
subsequent uses of the enumerate MemorySegment only happen after verifying it's
non-NULL and free resources appropriately.

In
`@oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java`:
- Around line 82-85: The Udev context returned by UdevFunctions.udev_new() can
be MemorySegment.NULL and must be checked before calling
UdevFunctions.udev_enumerate_new() and before unref; in the LinuxUsbDeviceFFM
method where you call UdevFunctions.udev_new(), add a null-check (if udev ==
MemorySegment.NULL) to skip enumeration and any enumerate-related logic and
avoid calling UdevFunctions.udev_unref(udev) on a NULL segment; mirror the guard
used in LinuxPowerSourceFFM/LinuxHWDiskStoreFFM so enumeration only runs when
udev is non-NULL and unref is only invoked for a valid context.

In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java`:
- Around line 60-62: The call to Udev.INSTANCE.udev_new() may return null but is
dereferenced immediately (variable udev used for udev.enumerateNew() and later
cleanup), so add a null guard after calling Udev.INSTANCE.udev_new(): if udev is
null log or return early (or skip enumeration/cleanup) to avoid
NullPointerException. Update the code paths around the Udev variable in
LinuxHWDiskStoreJNA where enumerateNew() and the later cleanup use udev so they
only run when udev != null, mirroring the null-check pattern used in
LinuxNetworkIFJNA and LinuxPowerSourceFFM.

In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java`:
- Around line 46-48: The code calls Udev.INSTANCE.udev_new() and immediately
invokes methods on the result (udev.enumerateNew() and later udev.unref()),
which will NPE if udev_new() returns null; update the method to guard the
Udev.UdevContext udev result (the variable named udev) with a null check similar
to LinuxNetworkIFJNA: if udev is null, skip the enumerateNew()/scan/unref logic
and handle/return appropriately; ensure you only call udev.enumerateNew() and
udev.unref() when udev != null to avoid NullPointerException.

In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java`:
- Around line 54-56: Guard the call to Udev.INSTANCE.udev_new() in
LinuxPowerSourceJNA by checking if the returned udev is null before using it; if
null, skip the JNA enumerate/cleanup path and fall back to calling
LinuxPowerSource.getPowerSources(). Specifically, after Udev.INSTANCE.udev_new()
assign to the local variable udev and if udev == null return or delegate to
LinuxPowerSource.getPowerSources(); likewise, only call udev.enumerateNew() and
any cleanup/unref methods (e.g., udev_unref or udev.free) when udev is non-null
to avoid NPEs, matching the null-check pattern used in LinuxPowerSourceFFM.

---

Duplicate comments:
In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java`:
- Around line 79-99: The code treats every DevPath.DM device as LVM
unconditionally; update the branch in LinuxHWDiskStoreJNA so it first reads
device.getPropertyValue(DM_VG_NAME) and device.getPropertyValue(DM_LV_NAME) and
only set devModel = LOGICAL_VOLUME_GROUP and call
getPartitionNameForDmDevice/getMountPointOfDmDevice when both vgName and lvName
are non-null/non-empty; otherwise preserve the original devModel/devSerial and
create a generic partition entry (or skip LVM-specific name resolution) using
available properties (e.g., DM_UUID and device.getSysname()) so non-LVM mapper
devices (dm-crypt/multipath) are not misidentified.
- Around line 132-133: The fallback to getDependentNamesFromHoldersDirectory is
using device.getSysname(), which builds a relative path (e.g., "sda1/holders")
and fails to find entries; change the argument to the device's sysfs absolute
path by passing device.getSysfsPath() to getDependentNamesFromHoldersDirectory
inside the mountsMap.getOrDefault(...) call (keep the rest of the expression
identical so dependent name probing uses the correct sysfs/holders path).

---

Nitpick comments:
In `@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIF.java`:
- Around line 38-40: The abstract class LinuxNetworkIF currently calls
updateAttributes() from its constructor (protected LinuxNetworkIF(...)), which
can dispatch to subclass overrides before subclass construction completes; to
fix, remove the updateAttributes() call from the LinuxNetworkIF constructor and
instead call updateAttributes() from each concrete subclass constructor after
their own initialization, or alternatively declare updateAttributes() as final
in LinuxNetworkIF so it cannot be overridden; update the implementations
accordingly (referencing the LinuxNetworkIF constructor and the
updateAttributes() method) to ensure initialization occurs only after subclass
construction is complete.
🪄 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: 282b99ec-7a16-4a55-a1c0-40e51d0efa3e

📥 Commits

Reviewing files that changed from the base of the PR and between d6d7614 and 9129f5f.

📒 Files selected for processing (23)
  • CHANGELOG.md
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/package-info.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroup.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.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 (9)
📓 Common learnings
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-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/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/package-info.java
  • oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java
  • oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.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/software/os/linux/LinuxOperatingSystemJNA.java
  • oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroup.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayer.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.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-java25/src/main/java/oshi/ffm/SystemInfo.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/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroup.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxNetworkIFJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStore.java
  • oshi-core-java25/src/main/java/oshi/ffm/linux/UdevFunctions.java
📚 Learning: 2026-04-03T02:07:47.621Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3110
File: oshi-core-java25/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java:119-121
Timestamp: 2026-04-03T02:07:47.621Z
Learning: In OSHI’s Java FFM/API implementation classes (e.g., *FFM.java) that implement/override `updateAttributes()`, preserve the intentional failure-handling pattern: catch `Throwable` and return `false` without logging. `updateAttributes()` is a public API whose contract is to signal failure via the boolean return value, and callers rely on that return value (so emitting logs from this path is not desired and should not be introduced during review unless the method contract changes).

Applied to files:

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

Applied to files:

  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
🪛 markdownlint-cli2 (0.22.0)
CHANGELOG.md

[warning] 3-3: Heading levels should only increment by one level at a time
Expected: h2; Actual: h5

(MD001, heading-increment)

🔇 Additional comments (11)
CHANGELOG.md (1)

3-4: LGTM!

The changelog entry follows the existing project format. The ##### heading level is consistent with other release sections (e.g., line 17).

oshi-core-java25/src/main/java/oshi/ffm/linux/package-info.java (1)

1-4: LGTM!

Clear and concise package-level documentation for the new FFM Linux bindings package.

oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystemJNA.java (1)

9-15: LGTM!

The empty JNA-backed class correctly extends LinuxOperatingSystem and serves as the concrete dispatch target for the oshi-core module. The final modifier is appropriate for a leaf implementation.

oshi-core/src/main/java/oshi/SystemInfo.java (1)

12-12: LGTM!

The Linux platform dispatch is correctly updated to use JNA-backed implementations (LinuxOperatingSystemJNA and LinuxHardwareAbstractionLayerJNA), maintaining consistency with the migration pattern where oshi-core uses JNA and oshi-core-java25 uses FFM.

Also applies to: 20-20, 77-79, 108-110

oshi-core-java25/src/main/java/oshi/ffm/SystemInfo.java (1)

13-13: LGTM!

The FFM SystemInfo correctly wires Linux to FFM-backed implementations. The absence of Android support in the FFM module is intentional—FFM only targets Windows, macOS, and Linux.

Also applies to: 17-17, 46-47, 59-60

oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java (1)

19-28: LGTM!

The FFM-based Linux OS implementation correctly exposes HAS_UDEV based on UdevFunctions.isAvailable(). The clear Javadoc guidance for FFM consumers to import HAS_UDEV from this class rather than the base LinuxOperatingSystem is helpful.

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSource.java (2)

29-29: LGTM!

The accessibility changes (public class instead of final, protected enum Prop, protected static buildPowerSource()) correctly enable the JNA/FFM subclass pattern while keeping the sysfs-based implementation in the base class.

Also applies to: 31-39, 100-100


71-98: Clean sysfs-based power source discovery.

The simplified getPowerSources() implementation:

  • Correctly filters out AC adapters and USB-C power supplies (line 80)
  • Uses the lazy PropByName holder for efficient property lookup
  • Applies a sensible default (1) for POWER_SUPPLY_PRESENT when the property is absent

This now serves as the pure-Java/sysfs fallback for both JNA and FFM subclasses.

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerJNA.java (1)

16-47: LGTM!

The JNA hardware abstraction layer correctly delegates all hardware queries to their respective JNA implementations. The delegation to LinuxUsbDevice.getUsbDevices() (rather than a JNA-specific variant) is appropriate since USB device enumeration uses a unified implementation.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxHardwareAbstractionLayerFFM.java (1)

23-45: Clean HAL dispatch split.

The overrides stay narrowly focused on the five udev-dependent methods that moved out of the shared base, which keeps the FFM path easy to reason about.

oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStore.java (1)

126-190: Nice reuse boundary for disk population.

These protected setters/helpers give the JNA and FFM enumerators the state they need while keeping shared stat parsing and partition finalization centralized here.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/linux/LinuxUsbDeviceFFM.java`:
- Around line 59-65: The current construction of deviceList and addDevicesToList
violates the tree=false contract by including controller nodes and preserving
nested connectedDevices; update the code that builds the list (the loop that
calls new LinuxUsbDeviceFFM(...) and addDevicesToList) and the addDevicesToList
implementation so that when the boolean tree flag is false you (1) skip/omit
controller devices (use the UsbDevice property that identifies controllers,
e.g., device.isController() or device.getType()), (2) always add flattened
entries with connectedDevices set to Collections.emptyList(), and (3) do not
append existing hierarchical nodes directly (instead recurse/flatten children
into the same top-level deviceList). Ensure these checks reference deviceList,
addDevicesToList, and the LinuxUsbDeviceFFM constructor so the flat mode returns
a single-level list without controllers or nested connectedDevices.
🪄 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: fe9ba948-8f9a-4934-9eb4-616c47b44f6e

📥 Commits

Reviewing files that changed from the base of the PR and between 9129f5f and 5bdcf22.

📒 Files selected for processing (5)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java
🚧 Files skipped from review as they are similar to previous changes (2)
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.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 25, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
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-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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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/LinuxPowerSourceJNA.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/LinuxPowerSourceJNA.java
🔇 Additional comments (6)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java (4)

49-57: Fallback gating and null-context handling look correct.

HAS_UDEV gating plus the udev_new() null fallback avoids NPEs and preserves sysfs discovery behavior.


59-93: Resource cleanup is robust across all paths.

The nested try/finally structure correctly releases UdevDevice, UdevEnumerate, and UdevContext.


61-83: Filtering and presence checks are consistent with the non-udev path.

The ADP/AC/USBC exclusion and POWER_SUPPLY_PRESENT gating align behavior between JNA and sysfs implementations.


59-60: Keeping enumerateNew() unguarded here is consistent with project intent.

Given the existing udev_new() guard, this matches the agreed libudev handling pattern for this migration.

Based on learnings: In OSHI Linux FFM/JNA udev code, a null guard on udev_enumerate_new() is intentionally unnecessary once udev_new() is guarded.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java (2)

47-103: Robust udev lifecycle and filtering logic here.

The guard on udev_new(), nested unref cleanup, and defensive device/property checks make this path resilient while preserving best-effort behavior.

Based on learnings: in this codebase, not adding a null guard around udev_enumerate_new() after a successful udev_new() is intentional and should not be flagged.


108-111: Null-safe VG→PV constructor mapping is correctly handled.

Using getOrDefault(..., Collections.emptySet()) avoids passing null PV sets into LinuxLogicalVolumeGroupFFM.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/linux/LinuxLogicalVolumeGroupJNA.java`:
- Around line 95-97: The mapping uses physicalVolumesMap.get(e.getKey()) which
can return null; change the construction in LinuxLogicalVolumeGroupJNA mapping
to use physicalVolumesMap.getOrDefault(e.getKey(), Collections.emptySet()) (or
equivalent non-null empty collection) so the LinuxLogicalVolumeGroupJNA
constructor always receives a non-null pvSet; update the stream map call where
logicalVolumesMap is converted to List to replace .get(...) with
.getOrDefault(...).
🪄 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: 2422ddfa-c3e4-4651-80e9-028d85d7554f

📥 Commits

Reviewing files that changed from the base of the PR and between 9129f5f and 9ad9a31.

📒 Files selected for processing (6)
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.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 (9)
📓 Common learnings
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: 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/LinuxUsbDevice.java
  • 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 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/LinuxUsbDevice.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.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/linux/LinuxUsbDevice.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/LinuxLogicalVolumeGroupJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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
  • oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.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: 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/LinuxPowerSourceJNA.java
🔇 Additional comments (10)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxUsbDevice.java (2)

48-58: Documentation correction aligns with actual behavior.

The Javadoc now correctly documents that tree=false returns a flat list including controllers. This matches the implementation at lines 67-71 where controllers (top-level devices) are explicitly added to deviceList before recursively adding their connected devices.

Based on learnings: "For OSHI Linux USB device implementations... do not flag the implementation for including controllers in flat mode; instead, only flag/update documentation/JavaDoc that incorrectly claims controllers are excluded."


65-73: Implementation comment accurately reflects the flattening logic.

The updated comment correctly describes the behavior: controllers (top-level devices) are added to the flat list with empty connectedDevices, followed by their descendants via addDevicesToList. This maintains consistency with the updated Javadoc.

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupFFM.java (1)

39-112: Well-structured FFM implementation with proper resource management.

The implementation correctly:

  • Guards udev_new() before enumeration (line 49-51)
  • Uses nested try-finally for proper FFM resource cleanup
  • Adds defensive DM_UUID "LVM-" check to filter only LVM devices (line 73)
  • Handles potential null pvSet with getOrDefault (line 110)
  • Catches Throwable with graceful fallback to empty list
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxLogicalVolumeGroupJNA.java (1)

38-94: JNA implementation correctly mirrors FFM structure.

Resource management with nested try-finally is proper, udev_new() null guard is in place (lines 47-49), and the DM_UUID "LVM-" filter is correctly applied (line 63).

oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxUsbDeviceFFM.java (3)

46-67: LGTM!

The getUsbDevices(boolean tree) method correctly implements the contract:

  • Tree mode returns hierarchical device structure
  • Flat mode returns all devices (including controllers) with controller nodes flattened to have empty connectedDevices

The Javadoc accurately describes the behavior.


82-155: Well-structured resource management.

The udev enumeration correctly implements the defensive pattern:

  • Null guard on udev_new() (addressed per prior feedback)
  • Properly nested try-finally blocks ensuring udev_device_unref, udev_enumerate_unref, and udev_unref are always called
  • Appropriate catch-all for FFM/native errors with warning log

172-187: LGTM!

The recursive tree-building logic correctly:

  • Inherits vendor/product IDs from parent when not explicitly set
  • Provides sensible fallbacks for missing device attributes
  • Sorts children for consistent ordering
  • Creates immutable device instances with their child hierarchy
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceJNA.java (3)

1-24: LGTM!

License header is correct, and all imports are used appropriately.


26-42: LGTM!

The class structure is appropriate: @ThreadSafe annotation is accurate for the immutable PowerSource type, and the constructor correctly delegates all parameters to the parent class.


49-95: Well-structured udev enumeration with proper resource cleanup.

The implementation correctly:

  • Guards udev_new() with null check and falls back to sysfs (lines 55-57)
  • Uses nested try-finally blocks to ensure all native handles (device, enumerate, udev) are properly unreferenced
  • Applies consistent filtering logic (ADP/AC/USBC exclusion) matching the sysfs fallback in LinuxPowerSource.getPowerSources()
  • Safely handles null device handles (line 70) and null property values (line 77)

Based on learnings, the absence of a null guard on enumerateNew() (line 59) is intentional and consistent with the project's established pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant