Repository navigation
Add native-free Linux SystemInfoProvider in oshi-common - #3238
Conversation
📝 WalkthroughWalkthroughAdds 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. ChangesNative-free Linux Provider Implementation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.java (1)
32-35: 💤 Low value
getconf CLK_TCKsubprocess runs during class initialization.
queryUserHz()is invoked in the static initializer (<clinit>), so thegetconfprocess is forked the first time this class is loaded. Ifgetconfis 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_HZvia a holder pattern, or alternatively, readingCONFIG_HZfrom/boot/config-$(uname -r)or thekernel.pid_maxsysctl 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 valueConsider defining named constants for soft and hard limit indices in
getProcessOpenFileLimitcalls.The literal
1and2arguments represent array indices for soft and hard limits respectively (from the split of/proc/{pid}/limits). Defining constants likeRLIMIT_SOFT_INDEX = 1andRLIMIT_HARD_INDEX = 2would 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
📒 Files selected for processing (13)
oshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.javaoshi-common/src/main/java/oshi/nativefree/SystemInfo.javaoshi-common/src/main/java/oshi/nativefree/package-info.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.javaoshi-common/src/test/java/module-info.testoshi-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.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.javaoshi-common/src/main/java/oshi/nativefree/SystemInfo.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.javaoshi-common/src/main/java/oshi/nativefree/package-info.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.javaoshi-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-opensdirectives 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 — intentionalnullreturn correctly triggers thejava.io.Filefallback path.oshi-common/src/main/java/module-info.java (1)
50-50: No action required—oshi.nativefree.SystemInfoalready guards against non-Linux platforms.The
providesdeclaration unconditionally registers the provider viaServiceLoader, but the implementation'sisAvailable()method returnsfalseon non-Linux platforms.SystemInfoFactoryfilters providers based onisAvailable()before instantiation, sogetOperatingSystem()andgetHardware()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[]), andqueryMaxFreqFromSysfs()) are declared withprotectedvisibility inLinuxCentralProcessorand are correctly accessible to the subclass overrides.oshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.java (2)
65-73: ⚡ Quick winThis design pattern is intentional and matches the interface contract.
The
OperatingSysteminterface explicitly documentsgetFileSystem()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
OperatingSysteminstance itself is memoized bySystemInfo, 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/loadavgtotal counts all kernel scheduling entities (processes and kernel threads), whilesysinfo().procs(used in JNA and FFM implementations) counts only processes.The field
running/totalin/proc/loadavgrepresents all kernel scheduling entities (both user processes and kernel threads), whereas thesysinfo().procsfield 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]>
3dcd789 to
ad1e202
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.java (1)
41-43: ⚡ Quick winPreserve 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
📒 Files selected for processing (18)
oshi-benchmark/src/test/java/oshi/comparison/NativeFreeComparisonTest.javaoshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxCentralProcessorNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHWDiskStoreNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIFNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/package-info.javaoshi-common/src/main/java/oshi/nativefree/SystemInfo.javaoshi-common/src/main/java/oshi/nativefree/package-info.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxFileSystemNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxNetworkParamsNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOSProcessNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/LinuxOperatingSystemNF.javaoshi-common/src/main/java/oshi/software/common/os/linux/nativefree/package-info.javaoshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/nativefree/SystemInfoTest.javaoshi-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.javaoshi-common/src/main/java/oshi/hardware/common/AbstractCentralProcessor.javaoshi-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 fallbackNice 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 inupdateAttributes().Returning
falsewhenstatis 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]>
ad1e202 to
5487d50
Compare
53c937a to
95cebfa
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (2)
oshi-common/src/main/java/oshi/spi/SystemInfoFactory.java (1)
49-50: ⚡ Quick winAlign
@throwsJavadoc with the new runtime guidance.Line 49-50 still mentions only
oshi-core/oshi-core-ffm, but the exception message now also documentsoshi-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 winPass the
Throwabledirectly to SLF4J instead ofe.toString().
e.toString()only captures the exception type and message; the stack trace is silently discarded. SLF4J'sThrowable-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
📒 Files selected for processing (5)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxGraphicsCardNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.javaoshi-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.javaoshi-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.
95cebfa to
4f1f3cc
Compare
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]>
4f1f3cc to
6de788c
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (7)
oshi-benchmark/src/test/java/oshi/comparison/NativeFreeComparisonTest.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxGraphicsCardNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxHardwareAbstractionLayerNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxNetworkIfNF.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/nativefree/LinuxUsbDeviceNF.javaoshi-common/src/main/java/oshi/spi/SystemInfoFactory.javaoshi-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.
| @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(); |
There was a problem hiding this comment.
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.
| @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.
Summary
Implements a priority-0
SystemInfoProvider(oshi.nativefree.SystemInfo) inoshi-commonthat works on Linux using only procfs, sysfs,getconf, command-line tools, and standard Java APIs. No JNA, no FFM, no--enable-native-accessrequired.This is the lowest-priority provider — it is only selected by
SystemInfoFactorywhen neitheroshi-core(JNA, priority 10) noroshi-core-ffm(FFM, priority 20) is on the classpath.Feature-complete — all HAL and OS methods implemented
LinuxCentralProcessorNF/proc/statticks/proc/meminfo,/proc/vmstatLinuxOperatingSystemNFgetconf,/proc/self/stat,/proc/loadavgLinuxOSProcessNF/proc/[pid]/*,/proc/[pid]/limits,/proc/[pid]/task/LinuxFileSystemNF/proc/mounts, JavaFileAPI fallbackLinuxNetworkParamsNFInetAddress,routecommandLinuxHWDiskStoreNF/sys/block/, sysfs statLinuxNetworkIFNFNetworkInterface,/sys/class/net//sys/class/power_supply/LinuxUsbDeviceNF/sys/bus/usb/devices/LinuxGraphicsCardNFlspci/lshw, sysfs GPU stats (AMD/Intel)/sys/class/hwmon/,/sys/class/thermal//sys/class/dmi/id//proc/asound/cards/sys/class/drm/Bug fix included
Fixes a long-standing bug in
AbstractCentralProcessor.createProcessorID()where three/proc/cpuinfoflag names did not match the CPUID mnemonics used in the switch statement:/proc/cpuinfoactualpse-36pse36clfshclflushhtthtThis caused 3 feature bits to be missing from the processor ID when constructed from flags (the fallback path used in unprivileged containers where
dmidecodeandcpuidare unavailable).Testing
LinuxNativeFreeProviderTest— integration test verifying provider basicsSystemInfoTest— human-readable output exercising CPU, memory, OS, disk, network, filesystem, processNativeFreeComparisonTest(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
*NFclass extends the existing abstract Linux class inoshi-commonand overrides only the methods that require native access (udev, ioctl, sysconf, getrlimit) with procfs/sysfs/command-line alternatives. Thenativefreepackage name explains theNFsuffix.Package structure:
oshi.nativefree— public entry point (SystemInfo)oshi.hardware.common.platform.linux.nativefree— hardware implementationsoshi.software.common.os.linux.nativefree— OS/process implementationsKnown differences vs JNA/FFM
device/serial.InetAddressreturns short hostname; nativegethostnamemay return FQDN.Related
Closes #3237
Summary by CodeRabbit
New Features
Bug Fixes
Tests