Skip to content

Add native-free Linux SystemInfoProvider in oshi-common - #3238

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:feature/linux-native-free-provider
May 8, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:feature/linux-native-free-provider

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Implements a priority-0 SystemInfoProvider (oshi.nativefree.SystemInfo) in oshi-common that works on Linux using only procfs, sysfs, getconf, command-line tools, and standard Java APIs. No JNA, no FFM, no --enable-native-access required.

This is the lowest-priority provider — it is only selected by SystemInfoFactory when neither oshi-core (JNA, priority 10) nor oshi-core-ffm (FFM, priority 20) is on the classpath.

Feature-complete — all HAL and OS methods implemented

Category Implementation Source
CentralProcessor LinuxCentralProcessorNF sysfs topology/freq, /proc/stat ticks
GlobalMemory / VirtualMemory Concrete superclass /proc/meminfo, /proc/vmstat
OperatingSystem LinuxOperatingSystemNF getconf, /proc/self/stat, /proc/loadavg
OSProcess / OSThread LinuxOSProcessNF /proc/[pid]/*, /proc/[pid]/limits, /proc/[pid]/task/
FileSystem LinuxFileSystemNF /proc/mounts, Java File API fallback
NetworkParams LinuxNetworkParamsNF Java InetAddress, route command
HWDiskStore LinuxHWDiskStoreNF /sys/block/, sysfs stat
NetworkIF LinuxNetworkIFNF Java NetworkInterface, /sys/class/net/
PowerSource Concrete superclass /sys/class/power_supply/
UsbDevice LinuxUsbDeviceNF /sys/bus/usb/devices/
GraphicsCard LinuxGraphicsCardNF lspci/lshw, sysfs GPU stats (AMD/Intel)
Sensors Concrete superclass /sys/class/hwmon/, /sys/class/thermal/
ComputerSystem / Baseboard / Firmware Concrete superclass /sys/class/dmi/id/
SoundCard Concrete superclass /proc/asound/cards
Display Concrete superclass /sys/class/drm/

Bug fix included

Fixes a long-standing bug in AbstractCentralProcessor.createProcessorID() where three /proc/cpuinfo flag names did not match the CPUID mnemonics used in the switch statement:

EDX Bit Was /proc/cpuinfo actual Fixed
17 pse-36 pse36 ✓
19 clfsh clflush ✓
28 htt ht ✓

This caused 3 feature bits to be missing from the processor ID when constructed from flags (the fallback path used in unprivileged containers where dmidecode and cpuid are unavailable).

Testing

  • LinuxNativeFreeProviderTest — integration test verifying provider basics
  • SystemInfoTest — human-readable output exercising CPU, memory, OS, disk, network, filesystem, process
  • NativeFreeComparisonTest (oshi-benchmark) — conformance test comparing NF vs JNA field-by-field, confirming identical results for deterministic values (hz, pageSize, processorID, topology, memory total, disk sizes, network MACs/IPs)

Design

Each *NF class extends the existing abstract Linux class in oshi-common and overrides only the methods that require native access (udev, ioctl, sysconf, getrlimit) with procfs/sysfs/command-line alternatives. The nativefree package name explains the NF suffix.

Package structure:

  • oshi.nativefree — public entry point (SystemInfo)
  • oshi.hardware.common.platform.linux.nativefree — hardware implementations
  • oshi.software.common.os.linux.nativefree — OS/process implementations

Known differences vs JNA/FFM

  • Disk model: sysfs returns raw kernel string (spaces); udev may normalize to underscores. Both are correct.
  • Disk serial: some virtual disks expose serial only via udev properties, not sysfs device/serial.
  • Hostname: Java InetAddress returns short hostname; native gethostname may return FQDN.
  • GPU stats: NVML metrics unavailable (returns -1); sysfs-based metrics work for AMD/Intel.

Related

Closes #3237

Summary by CodeRabbit

  • New Features

    • Native-free Linux provider added for hardware/OS info (CPU, memory, disks, network, USB, graphics, filesystem) that works without native libraries and uses sysfs/procfs/CLI fallbacks.
    • Filesystem and GPU stats gracefully fall back when native data isn’t available.
  • Bug Fixes

    • Improved CPU feature flag recognition.
    • Clearer error when no provider is available.
  • Tests

    • Added Linux-only and parity tests validating native-free behavior.

@coderabbitai

coderabbitai Bot commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a Linux-only, pure-Java SystemInfoProvider and native-free OS/HAL implementations that use procfs/sysfs/command-line utilities; registers the provider in the module descriptor and adds provider, comparison, and integration tests.

Changes

Native-free Linux Provider Implementation

Layer / File(s) Summary
Service Registration & Module Exports
oshi-common/src/main/java/module-info.java, oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
Module-level exports oshi.nativefree and provides oshi.spi.SystemInfoProvider with oshi.nativefree.SystemInfo enable automatic provider discovery. Factory error message expands to mention native-free option on Linux.
Service Provider Entry Point
oshi-common/src/main/java/oshi/nativefree/SystemInfo.java, oshi-common/src/main/java/oshi/nativefree/package-info.java
SystemInfo memoizes native-free LinuxOperatingSystemNF and LinuxHardwareAbstractionLayerNF instances, returns priority 0, and limits availability to Linux platform via PlatformEnum.
Operating System Core
oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java, .../package-info.java
Initializes static USER_HZ and PAGE_SIZE from getconf with fallback defaults; implements process/thread identifiers via /proc/self/stat, /proc/thread-self, and /proc/loadavg; wires native-free filesystem and network parameter factories.
CPU Implementation
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java
Derives USER_HZ from getconf CLK_TCK and overrides udev-based topology/frequency methods to delegate to sysfs helpers (readTopologyFromSysfs, queryCurrentFreqFromSysfs, queryMaxFreqFromSysfs).
Supporting OS Components
oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.java, LinuxNetworkParamsNF.java, LinuxOSProcessNF.java
LinuxFileSystemNF returns null from queryStatvfs() to trigger Java File fallback; LinuxNetworkParamsNF uses inherited behavior; LinuxOSProcessNF overrides queryRlimitSoft/Hard to fetch process open-file limits.
Hardware Abstraction Layer
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
Wires LinuxCentralProcessorNF and LinuxGlobalMemory (with native-free page size); delegates disk/network/power/USB/graphics queries to sysfs-based implementations (LinuxHWDiskStoreNF, LinuxNetworkIfNF, LinuxPowerSource, LinuxUsbDeviceNF, LinuxGraphicsCardNF).
Disk Store Hardware
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
Enumerates block devices from /sys/block/, reads model/serial/size and HDD/SSD classification, constructs partitions with major/minor numbers and mount points, implements updateAttributes() for stat refresh.
Network Interface Hardware
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java
Wraps Java NetworkInterface instances and queries sysfs for per-interface model identifiers via static getNetworks() factory.
USB & Graphics Hardware
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java, oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxGraphicsCardNF.java
LinuxUsbDeviceNF walks /sys/bus/usb/devices/ to build USB device tree with attributes; LinuxGraphicsCardNF wraps DRM cards and disables NVML metrics (returns sentinel -1 values).
Processor Identifier Flag Normalization
oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
Feature-flag-to-bit mapping now recognizes pse36 (was pse-36), ht (was htt), and clflush (alongside clfsh) for improved CPU flag coverage.
Test Configuration
oshi-common/src/test/java/module-info.test
Added --add-opens directives to grant JUnit reflective access to oshi.spi, oshi.nativefree, and native-free package hierarchies.
Provider & Functional Tests
oshi-common/src/test/java/oshi/spi/LinuxNativeFreeProviderTest.java, oshi-common/src/test/java/oshi/nativefree/SystemInfoTest.java
LinuxNativeFreeProviderTest validates provider availability, priority, and key hardware/OS fields on Linux; SystemInfoTest exercises provider across OS metadata, CPU, memory, filesystem, network, disk, and process attributes with invariant checks.
Comparison Testing
oshi-benchmark/src/test/java/oshi/comparison/NativeFreeComparisonTest.java
Initializes both native-free and JNA-based providers, validates parity with exact equality for stable fields (hz, page size, family) and tolerance-based checks for dynamic values (thread counts, CPU frequencies, memory availability, disk space).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • oshi/oshi#3121: The native-free implementations reuse procfs/sysfs refactors moved into oshi-common.
  • oshi/oshi#3120: Extracted udev/sysfs hooks from LinuxCentralProcessor; native-free subclass overrides those hooks.
  • oshi/oshi#3234: Introduced the SystemInfoProvider SPI/SystemInfoFactory that this PR implements a concrete provider for.

Poem

🐰 Through /proc and /sys I nimbly creep,
Reading clocks and mounts while others sleep,
No JNA, no native fuss, just Java lore,
A tiny rabbit brings Linux info to your door,
Hop — pure-Java OSHI, lightweight and sure.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.93% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add native-free Linux SystemInfoProvider in oshi-common' accurately and specifically describes the main objective of the changeset: implementing a native-free (JNA/FFM-free) Linux SystemInfoProvider within oshi-common.
Linked Issues check ✅ Passed The PR successfully implements all coding requirements from issue #3237: a priority-0 Linux-only SystemInfoProvider in oshi-common using procfs/sysfs/CLI utilities without JNA/FFM, with feature-complete implementations of CPU, memory, disk, filesystem, network, and process components, plus test coverage.
Out of Scope Changes check ✅ Passed All changes are in scope: native-free provider implementation, component classes, package info files, test infrastructure, and a minimal bug fix to CPU flag mappings in AbstractCentralProcessor.

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

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

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 May 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 55.89744% with 86 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.79%. Comparing base (43ff204) to head (6de788c).

Files with missing lines Patch % Lines
...on/platform/linux/nativefree/LinuxUsbDeviceNF.java 25.45% 37 Missing and 4 partials ⚠️
...platform/linux/nativefree/LinuxGraphicsCardNF.java 11.76% 15 Missing ⚠️
.../platform/linux/nativefree/LinuxHWDiskStoreNF.java 73.46% 7 Missing and 6 partials ⚠️
...on/os/linux/nativefree/LinuxOperatingSystemNF.java 65.62% 6 Missing and 5 partials ⚠️
...on/platform/linux/nativefree/LinuxNetworkIfNF.java 81.81% 2 Missing ⚠️
...e/common/os/linux/nativefree/LinuxOSProcessNF.java 50.00% 2 Missing ⚠️
...form/linux/nativefree/LinuxCentralProcessorNF.java 87.50% 0 Missing and 1 partial ⚠️
...mmon/src/main/java/oshi/nativefree/SystemInfo.java 87.50% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3238      +/-   ##
============================================
- Coverage     63.82%   63.79%   -0.03%     
  Complexity       73       73              
============================================
  Files           422      433      +11     
  Lines         19741    19936     +195     
  Branches       3411     3442      +31     
============================================
+ Hits          12599    12719     +120     
- Misses         5388     5449      +61     
- Partials       1754     1768      +14     
Flag Coverage Δ
linux 30.31% <55.89%> (+0.28%) ⬆️
macos 32.80% <2.05%> (-0.31%) ⬇️
windows 40.47% <2.05%> (-0.36%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java (1)

32-35: 💤 Low value

getconf CLK_TCK subprocess runs during class initialization.

queryUserHz() is invoked in the static initializer (<clinit>), so the getconf process is forked the first time this class is loaded. If getconf is absent the parse yields 0 and the 100 Hz fallback kicks in correctly, but a slow or blocked process spawn during class loading could delay initialization unexpectedly in restricted container environments.

Consider lazily resolving USER_HZ via a holder pattern, or alternatively, reading CONFIG_HZ from /boot/config-$(uname -r) or the kernel.pid_max sysctl approach to stay purely within procfs/sysfs without forking a subprocess — consistent with the rest of the native-free design philosophy.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java`
around lines 32 - 35, The static getconf call should not run during class init;
make USER_HZ lazy by replacing the eager static initializer with a holder
pattern (e.g., an inner static class or a getUserHz() accessor that defers
initialization) and change queryUserHz() to prefer non-subprocess methods first
(try reading CONFIG_HZ from /boot/config-$(uname -r) or related proc/sys values)
and only fall back to executing "getconf CLK_TCK" if those reads fail, returning
100 on parse failure; update all usages to call the new lazy accessor
(referencing queryUserHz and the new USER_HZ holder/getUserHz) so class loading
no longer forks a process.
oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.java (1)

29-36: 💤 Low value

Consider defining named constants for soft and hard limit indices in getProcessOpenFileLimit calls.

The literal 1 and 2 arguments represent array indices for soft and hard limits respectively (from the split of /proc/{pid}/limits). Defining constants like RLIMIT_SOFT_INDEX = 1 and RLIMIT_HARD_INDEX = 2 would clarify intent across the multiple files that use this pattern (LinuxOSProcessNF, LinuxOSProcessFFM, LinuxOSProcessJNA, FreeBsdOSProcess, SolarisOSProcess).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.java`
around lines 29 - 36, The code uses magic indices (1 and 2) when calling
getProcessOpenFileLimit from queryRlimitSoft/queryRlimitHard; define descriptive
constants (e.g., RLIMIT_SOFT_INDEX = 1 and RLIMIT_HARD_INDEX = 2) in the class
or a common utility and replace the literal arguments in
LinuxOSProcessNF.queryRlimitSoft, LinuxOSProcessNF.queryRlimitHard and the
analogous calls in LinuxOSProcessFFM, LinuxOSProcessJNA, FreeBsdOSProcess, and
SolarisOSProcess with these constants so the intent is clear and maintainable
(ensure any references to getProcessOpenFileLimit continue to compile after
renaming the arguments).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java`:
- Around line 32-35: The static getconf call should not run during class init;
make USER_HZ lazy by replacing the eager static initializer with a holder
pattern (e.g., an inner static class or a getUserHz() accessor that defers
initialization) and change queryUserHz() to prefer non-subprocess methods first
(try reading CONFIG_HZ from /boot/config-$(uname -r) or related proc/sys values)
and only fall back to executing "getconf CLK_TCK" if those reads fail, returning
100 on parse failure; update all usages to call the new lazy accessor
(referencing queryUserHz and the new USER_HZ holder/getUserHz) so class loading
no longer forks a process.

In
`@oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.java`:
- Around line 29-36: The code uses magic indices (1 and 2) when calling
getProcessOpenFileLimit from queryRlimitSoft/queryRlimitHard; define descriptive
constants (e.g., RLIMIT_SOFT_INDEX = 1 and RLIMIT_HARD_INDEX = 2) in the class
or a common utility and replace the literal arguments in
LinuxOSProcessNF.queryRlimitSoft, LinuxOSProcessNF.queryRlimitHard and the
analogous calls in LinuxOSProcessFFM, LinuxOSProcessJNA, FreeBsdOSProcess, and
SolarisOSProcess with these constants so the intent is clear and maintainable
(ensure any references to getProcessOpenFileLimit continue to compile after
renaming the arguments).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 77121499-5ba7-4a39-8618-8ecf2366edee

📥 Commits

Reviewing files that changed from the base of the PR and between 43ff204 and d8a6a0b.

📒 Files selected for processing (13)
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/nativefree/SystemInfo.java
  • oshi-common/src/main/java/oshi/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/spi/LinuxNativeFreeProviderTest.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 (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.java
  • oshi-common/src/main/java/oshi/nativefree/SystemInfo.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java
🔇 Additional comments (10)
oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.java (1)

1-16: LGTM — clean delegation subtype.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.java (1)

1-8: LGTM.

oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.java (1)

1-8: LGTM.

oshi-common/src/main/java/oshi/nativefree/package-info.java (1)

1-8: LGTM.

oshi-common/src/test/java/module-info.test (1)

3-6: LGTM — new --add-opens directives align with the new packages.

Also applies to: 17-18, 31-32

oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.java (1)

14-21: LGTM — intentional null return correctly triggers the java.io.File fallback path.

oshi-common/src/main/java/module-info.java (1)

50-50: No action required—oshi.nativefree.SystemInfo already guards against non-Linux platforms.

The provides declaration unconditionally registers the provider via ServiceLoader, but the implementation's isAvailable() method returns false on non-Linux platforms. SystemInfoFactory filters providers based on isAvailable() before instantiation, so getOperatingSystem() and getHardware() are never called on non-Linux systems.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java (1)

37-50: No issues found. All three sysfs-based methods (readTopologyFromSysfs(), queryCurrentFreqFromSysfs(long[]), and queryMaxFreqFromSysfs()) are declared with protected visibility in LinuxCentralProcessor and are correctly accessible to the subclass overrides.

oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java (2)

65-73: ⚡ Quick win

This design pattern is intentional and matches the interface contract.

The OperatingSystem interface explicitly documents getFileSystem() as "Instantiates a [FileSystem] object" — the contract requires creating new instances on each call, not caching. All implementations across the codebase (LinuxOperatingSystemNF, LinuxOperatingSystemFFM, LinuxOperatingSystemJNA, WindowsOperatingSystemFFM, etc.) consistently follow this pattern.

While the OperatingSystem instance itself is memoized by SystemInfo, the methods within it intentionally return fresh instances to allow callers to always access current state (e.g., updated file stores, changed network configuration). This is not a defect; it is the designed contract.

			> Likely an incorrect or invalid review comment.

111-124: ⚡ Quick win

getThreadCount() measures different entities than other Linux implementations: /proc/loadavg total counts all kernel scheduling entities (processes and kernel threads), while sysinfo().procs (used in JNA and FFM implementations) counts only processes.

The field running/total in /proc/loadavg represents all kernel scheduling entities (both user processes and kernel threads), whereas the sysinfo().procs field returned by the JNA and FFM implementations counts only processes. In high-I/O workloads with many kernel threads, these measurements could diverge meaningfully. Consider whether this alternative implementation is intentional or if consistency with the other Linux implementations is preferred.

…rocesses)

Implements a priority-0 SystemInfoProvider in oshi-common that works on Linux
using only procfs, sysfs, getconf, and standard Java APIs. No JNA, no FFM,
no --enable-native-access required.

Phase 1 provides full support for:
- CentralProcessor (topology, frequencies, ticks via sysfs)
- GlobalMemory / VirtualMemory (already concrete in superclass)
- OperatingSystem (family, version, boot time, uptime, process listing)
- OSProcess (stat, status, cmdline, open file limits via /proc)
- FileSystem (mounts, file stores via Java File API fallback)
- NetworkParams (hostname, DNS, gateways via Java + route command)

Stubbed for future phases (return empty lists):
- HWDiskStore, NetworkIF, PowerSource, UsbDevice, GraphicsCard

Also fixes a 10-year-old bug in AbstractCentralProcessor.createProcessorID()
where /proc/cpuinfo flag names (pse36, clflush, ht) did not match the CPUID
mnemonics (pse-36, clfsh, htt), causing 3 EDX feature bits to be missing from
the processor ID when constructed from flags.

Closes #3237 (partially)

Signed-off-by: Dan Widdis <[email protected]>
@dbwiddis
dbwiddis force-pushed the feature/linux-native-free-provider branch 3 times, most recently from 3dcd789 to ad1e202 Compare May 8, 2026 06:06

@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

🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.java (1)

41-43: ⚡ Quick win

Preserve failure context in debug logging

Line 42 currently logs e.toString(), which drops stack trace and interface identity. Include the interface name and pass the throwable directly.

♻️ Proposed logging improvement
-            } catch (InstantiationException e) {
-                LOG.debug("Network Interface Instantiation failed: {}", e.toString());
+            } catch (InstantiationException e) {
+                LOG.debug("Network interface '{}' instantiation failed", ni.getName(), e);
             }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.java`
around lines 41 - 43, The debug log in LinuxNetworkIFNF currently uses
e.toString(), losing stack trace and interface identity; update the LOG.debug
call in the catch block (in class LinuxNetworkIFNF) to include the interface
name and pass the throwable as the last argument so the logger records the
stacktrace — e.g., LOG.debug("Network interface {} instantiation failed",
<interfaceNameOrGetter>, e) where <interfaceNameOrGetter> is the variable/method
that provides the interface identity (for example iface.getName() or name).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java`:
- Around line 64-65: The code in LinuxHWDiskStoreNF.java reads rotational via
FileUtil.getStringFromFile(sysPath + "queue/rotational") and unconditionally
classifies diskType as "SSD" when the read value isn't "1"; instead, detect
missing/unreadable values (null or empty after trim) and set diskType to a
distinct "UNKNOWN" (or similar) rather than defaulting to "SSD"; only map "1" =>
"HDD" and "0" => "SSD", otherwise set diskType = "UNKNOWN" and proceed, ensuring
you call trim() only when the string is non-null.

---

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.java`:
- Around line 41-43: The debug log in LinuxNetworkIFNF currently uses
e.toString(), losing stack trace and interface identity; update the LOG.debug
call in the catch block (in class LinuxNetworkIFNF) to include the interface
name and pass the throwable as the last argument so the logger records the
stacktrace — e.g., LOG.debug("Network interface {} instantiation failed",
<interfaceNameOrGetter>, e) where <interfaceNameOrGetter> is the variable/method
that provides the interface identity (for example iface.getName() or name).
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 080d6c2e-c08e-4974-b909-d55540de5dd6

📥 Commits

Reviewing files that changed from the base of the PR and between d8a6a0b and ad1e202.

📒 Files selected for processing (18)
  • oshi-benchmark/src/test/java/oshi/comparison/NativeFreeComparisonTest.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/nativefree/SystemInfo.java
  • oshi-common/src/main/java/oshi/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/nativefree/SystemInfoTest.java
  • oshi-common/src/test/java/oshi/spi/LinuxNativeFreeProviderTest.java
✅ Files skipped from review due to trivial changes (10)
  • oshi-common/src/main/java/oshi/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.java
  • oshi-common/src/main/java/oshi/nativefree/SystemInfo.java
  • oshi-common/src/test/java/oshi/spi/LinuxNativeFreeProviderTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.java
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/nativefree/SystemInfoTest.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeFreeComparisonTest.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java
  • oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.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 (1)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.java
  • oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java
🔇 Additional comments (3)
oshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.java (1)

368-402: Good compatibility fix for Linux CPU flag aliases.

Keeping both historical and procfs-style spellings mapped to the same CPUID bits is the right approach and avoids regressions while restoring missing feature bits.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.java (1)

26-41: Clean native-free wrapping and graceful fallback

Nice implementation: constructor wiring to sysfs model lookup and per-interface instantiation fallback is clear and robust for partial failures.

oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.java (1)

104-112: Good fail-fast behavior in updateAttributes().

Returning false when stat is unavailable is clean and keeps stale updates from being reported as successful.

Implements disk store enumeration from /sys/block/ with stats from sysfs,
network interface enumeration using Java NetworkInterface + sysfs model,
and power source via the existing sysfs-based LinuxPowerSource.

Only USB and graphics card enumeration remain stubbed.

Comparison tests confirm NF matches JNA for disk names, sizes, serials,
partition counts, and network interface MACs, IPs, MTUs, and speeds.

Signed-off-by: Dan Widdis <[email protected]>
@dbwiddis
dbwiddis force-pushed the feature/linux-native-free-provider branch from ad1e202 to 5487d50 Compare May 8, 2026 06:15
@dbwiddis
dbwiddis marked this pull request as ready for review May 8, 2026 16:14
@dbwiddis
dbwiddis force-pushed the feature/linux-native-free-provider branch from 53c937a to 95cebfa Compare May 8, 2026 16:23

@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-common/src/main/java/oshi/spi/SystemInfoFactory.java (1)

49-50: ⚡ Quick win

Align @throws Javadoc with the new runtime guidance.

Line 49-50 still mentions only oshi-core / oshi-core-ffm, but the exception message now also documents oshi-common-only usage on Linux. Updating the Javadoc avoids contradictory guidance in API docs vs runtime behavior.

Suggested doc update
-     * `@throws` IllegalStateException if no available provider is found. Ensure {`@code` oshi-core} or
-     *                               {`@code` oshi-core-ffm} is declared as a dependency.
+     * `@throws` IllegalStateException if no available provider is found. Ensure {`@code` oshi-core} or
+     *                               {`@code` oshi-core-ffm} is declared as a dependency, or use
+     *                               {`@code` oshi-common} alone on Linux (native-free provider).
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java` around lines 49 -
50, Update the `@throws` Javadoc on SystemInfoFactory (class SystemInfoFactory) to
match the runtime guidance: mention that IllegalStateException can be thrown if
no provider is found and advise that consumers should declare either oshi-core
or oshi-core-ffm as a dependency, or on Linux the oshi-common-only usage is
supported; replace the existing text that only references "oshi-core" /
"oshi-core-ffm" with a single sentence that lists "oshi-core, oshi-core-ffm, or
(on Linux) oshi-common-only" as valid dependency options to avoid conflicting
API docs vs runtime behavior.
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java (1)

41-43: ⚡ Quick win

Pass the Throwable directly to SLF4J instead of e.toString().

e.toString() only captures the exception type and message; the stack trace is silently discarded. SLF4J's Throwable-as-last-arg convention retains the full stack trace when the debug level is active.

♻️ Proposed fix
-                LOG.debug("Network Interface Instantiation failed: {}", e.toString());
+                LOG.debug("Network Interface Instantiation failed: {}", e.getMessage(), e);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java`
around lines 41 - 43, In the catch block in LinuxNetworkIfNF (the
InstantiationException handler), stop passing e.toString() and pass the
Throwable as the last argument to SLF4J so the full stack trace is preserved;
replace the current LOG.debug("Network Interface Instantiation failed: {}",
e.toString()) call with a LOG.debug(...) invocation that supplies a descriptive
message and the exception object (e) as the final parameter.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java`:
- Around line 41-43: In the catch block in LinuxNetworkIfNF (the
InstantiationException handler), stop passing e.toString() and pass the
Throwable as the last argument to SLF4J so the full stack trace is preserved;
replace the current LOG.debug("Network Interface Instantiation failed: {}",
e.toString()) call with a LOG.debug(...) invocation that supplies a descriptive
message and the exception object (e) as the final parameter.

In `@oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java`:
- Around line 49-50: Update the `@throws` Javadoc on SystemInfoFactory (class
SystemInfoFactory) to match the runtime guidance: mention that
IllegalStateException can be thrown if no provider is found and advise that
consumers should declare either oshi-core or oshi-core-ffm as a dependency, or
on Linux the oshi-common-only usage is supported; replace the existing text that
only references "oshi-core" / "oshi-core-ffm" with a single sentence that lists
"oshi-core, oshi-core-ffm, or (on Linux) oshi-common-only" as valid dependency
options to avoid conflicting API docs vs runtime behavior.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dbf8c9d2-68f3-43ed-a975-ac0fc3451608

📥 Commits

Reviewing files that changed from the base of the PR and between 53c937a and 95cebfa.

📒 Files selected for processing (5)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxGraphicsCardNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
🚧 Files skipped from review as they are similar to previous changes (3)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxGraphicsCardNF.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java
🔇 Additional comments (1)
oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java (1)

69-70: Clearer failure guidance is a good improvement.

The new message at Line 69 now points users to the Linux native-free fallback path, which makes provider resolution failures much easier to act on.

@dbwiddis
dbwiddis force-pushed the feature/linux-native-free-provider branch from 95cebfa to 4f1f3cc Compare May 8, 2026 16:27
Implements USB device enumeration from /sys/bus/usb/devices/ with tree
structure derived from device naming conventions (bus-port.port hierarchy).

Implements graphics card enumeration via the existing lspci/lshw command-line
parsing in the superclass, with a GpuStats implementation that provides
sysfs-based metrics for AMD/Intel GPUs and returns -1 for NVML-only metrics.

No more stubs — all HardwareAbstractionLayer methods are now implemented.

Signed-off-by: Dan Widdis <[email protected]>
@dbwiddis
dbwiddis force-pushed the feature/linux-native-free-provider branch from 4f1f3cc to 6de788c Compare May 8, 2026 16:30

@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 current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@oshi-common/src/test/java/oshi/nativefree/SystemInfoTest.java`:
- Around line 55-69: The test testPlatformEnum/main currently verifies the
platform but not that the implementations are the native-free ones; after
obtaining SystemInfo si and the instances via si.getHardware() and
si.getOperatingSystem(), add assertions that these instances are the native-free
providers by checking their runtime types (e.g., assert that
hal.getClass().getName() and os.getClass().getName() contain "nativefree" or
that they are instances of the
NativeFreeHardwareAbstractionLayer/NativeFreeOperatingSystem classes if those
concrete classes exist) so provider-selection regressions fail the test; update
testPlatformEnum/main to perform these checks using the existing
HardwareAbstractionLayer hal and OperatingSystem os variables.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 68bf995c-7862-498e-881e-a4bb1664c2bc

📥 Commits

Reviewing files that changed from the base of the PR and between 95cebfa and 6de788c.

📒 Files selected for processing (7)
  • oshi-benchmark/src/test/java/oshi/comparison/NativeFreeComparisonTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxGraphicsCardNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
  • oshi-common/src/test/java/oshi/nativefree/SystemInfoTest.java
✅ Files skipped from review due to trivial changes (1)
  • oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java
🚧 Files skipped from review as they are similar to previous changes (5)
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxGraphicsCardNF.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.java
  • oshi-benchmark/src/test/java/oshi/comparison/NativeFreeComparisonTest.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.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 comments (1)
oshi-common/src/test/java/oshi/nativefree/SystemInfoTest.java (1)

49-50: Linux-only + same-thread annotations are a solid fit for this smoke test.

Good guardrails for environment-specific behavior and deterministic execution in CI.

Comment on lines +55 to +69
@Test
public void testPlatformEnum() {
assertThat("Unsupported OS", PlatformEnum.getCurrentPlatform(), is(not(PlatformEnum.UNKNOWN)));
main(null);
}

public static void main(String[] args) {
logger.info("------------------------------------------------------------------------");
logger.info("Using Native-Free (NF)");
logger.info("------------------------------------------------------------------------");
logger.info("Initializing System...");
SystemInfo si = new SystemInfo();

HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Assert the provider path is truly native-free, not just runnable.

On Line 57 and Line 58, the test checks platform and runs smoke output, but it never verifies that HAL/OS came from native-free implementations. That can let provider-selection regressions pass silently.

Proposed test hardening
 import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsString;
 import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.not;
@@
     `@Test`
     public void testPlatformEnum() {
         assertThat("Unsupported OS", PlatformEnum.getCurrentPlatform(), is(not(PlatformEnum.UNKNOWN)));
+        SystemInfo si = new SystemInfo();
+        assertThat("HAL should be native-free", si.getHardware().getClass().getName(),
+                containsString(".nativefree."));
+        assertThat("OS should be native-free", si.getOperatingSystem().getClass().getName(),
+                containsString(".nativefree."));
         main(null);
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Test
public void testPlatformEnum() {
assertThat("Unsupported OS", PlatformEnum.getCurrentPlatform(), is(not(PlatformEnum.UNKNOWN)));
main(null);
}
public static void main(String[] args) {
logger.info("------------------------------------------------------------------------");
logger.info("Using Native-Free (NF)");
logger.info("------------------------------------------------------------------------");
logger.info("Initializing System...");
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
`@Test`
public void testPlatformEnum() {
assertThat("Unsupported OS", PlatformEnum.getCurrentPlatform(), is(not(PlatformEnum.UNKNOWN)));
SystemInfo si = new SystemInfo();
assertThat("HAL should be native-free", si.getHardware().getClass().getName(),
containsString(".nativefree."));
assertThat("OS should be native-free", si.getOperatingSystem().getClass().getName(),
containsString(".nativefree."));
main(null);
}
public static void main(String[] args) {
logger.info("------------------------------------------------------------------------");
logger.info("Using Native-Free (NF)");
logger.info("------------------------------------------------------------------------");
logger.info("Initializing System...");
SystemInfo si = new SystemInfo();
HardwareAbstractionLayer hal = si.getHardware();
OperatingSystem os = si.getOperatingSystem();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@oshi-common/src/test/java/oshi/nativefree/SystemInfoTest.java` around lines
55 - 69, The test testPlatformEnum/main currently verifies the platform but not
that the implementations are the native-free ones; after obtaining SystemInfo si
and the instances via si.getHardware() and si.getOperatingSystem(), add
assertions that these instances are the native-free providers by checking their
runtime types (e.g., assert that hal.getClass().getName() and
os.getClass().getName() contain "nativefree" or that they are instances of the
NativeFreeHardwareAbstractionLayer/NativeFreeOperatingSystem classes if those
concrete classes exist) so provider-selection regressions fail the test; update
testPlatformEnum/main to perform these checks using the existing
HardwareAbstractionLayer hal and OperatingSystem os variables.

@dbwiddis
dbwiddis merged commit b488daf into oshi:master May 8, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the feature/linux-native-free-provider branch May 8, 2026 16:49
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.

Provide a native-free Linux fallback provider in oshi-common

1 participant