Skip to content

Extract Solaris common abstract bases for JNA/FFM parity - #3367

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:solaris-common-base
Jun 11, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:solaris-common-base

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 11, 2026 •

Copy link
Copy Markdown
Member

Part 1 of 2 of the Solaris JNA/FFM parity cleanup. This PR covers the software.os classes; a follow-up will give the Solaris hardware classes (CentralProcessor, GlobalMemory, HWDiskStore, NetworkIF, PowerSource, HAL) the same treatment.

Brings Solaris in line with the AIX/FreeBSD JNA/FFM structure. Solaris was the last platform whose JNA and FFM implementations both extended the generic Abstract* bases directly, duplicating Solaris-specific logic across oshi-core and oshi-core-ffm.

What changed

  • Shared /proc carriers in oshi-common — pure-Java mirrors of psinfo_t / lwpsinfo_t / prusage_t / timestruc_t plus a common PsInfo driver that parses /proc/<pid>/{psinfo,usage} and /proc/<pid>/lwp/<tid>/{lwpsinfo,usage} from a ByteBuffer. No native code, so both implementations share them, mirroring oshi.driver.common.unix.aix.
  • Abstract bases for OSProcess, OSThread, FileSystem, NetworkParams, and OperatingSystem in oshi-common, with concrete <Os>FooJNA (oshi-core) and <Os>FooFFM (oshi-core-ffm) subclasses. This removes the duplicated updateAttributes logic and drops the FQN-extends awkwardness.
  • OSFileStore becomes a single concrete common class (no native code), like AixOSFileStore.
  • Driver split mirrors AIX: buffer parsing lives in the common PsInfo; the JNA PsInfo is renamed PsInfoJNA (keeps only the pread-based arg/env read) and PsInfoFFM keeps only the pargs-based read. The now-unused psinfo/lwpsinfo/prusage JNA structs are removed from SolarisLibc.

Kstat2 stays JNA-only (intentional)

HAS_KSTAT2, the dual-path file-descriptor counts, system uptime/boot time, and the getSessions() override remain in SolarisOperatingSystemJNA / SolarisFileSystemJNA. FFM uses the legacy kstat chain only — kstat2 exists only on the JDK 17-capped latest Solaris, and illumos forked before it, so FFM (JDK 25) never needs it.

Incidental FFM fix

The FFM prusage POJO had dropped pr_ioch, so FFM never populated OSProcess.getBytesRead() while the JNA side did. The common carrier restores it, so both implementations report it again.

Net ~830 fewer lines. Full clean reactor build plus spotless/checkstyle/forbiddenapis/javadoc all pass locally.

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced Solaris/illumos system support with improved process and thread information retrieval through better /proc file parsing.
  • Improvements

    • Strengthened architecture for platform-specific implementations, enabling more reliable system data queries across Solaris environments.

dbwiddis added 2 commits June 10, 2026 18:03
Add pure-Java mirrors of the Solaris psinfo_t / lwpsinfo_t / prusage_t /
timestruc_t structs (SolarisPsInfo, SolarisLwpsInfo, SolarisPrUsage,
SolarisTimestruc) and a common PsInfo driver that parses
/proc/<pid>/{psinfo,usage} and /proc/<pid>/lwp/<tid>/{lwpsinfo,usage}
from a ByteBuffer. These contain no native code, so both the JNA and FFM
Solaris implementations can share them, mirroring the existing
oshi.driver.common.unix.aix carriers.
Rebase Solaris OSProcess, OSThread, FileSystem, NetworkParams, and
OperatingSystem onto abstract bases in oshi-common, with concrete
<Os>FooJNA (oshi-core) and <Os>FooFFM (oshi-core-ffm) subclasses, matching
the AIX and FreeBSD convention. OSFileStore has no native code, so it
becomes a single concrete common class like AixOSFileStore. The shared
attribute parsing now reads the common /proc carriers, removing the
duplicated updateAttributes logic between the JNA and FFM sides.

The JNA-only Kstat2 paths stay JNA-side: HAS_KSTAT2, the dual-path file
descriptor counts, system uptime/boot time, and the getSessions override
remain in SolarisOperatingSystemJNA / SolarisFileSystemJNA. FFM uses the
legacy kstat chain only, since kstat2 exists only on the JDK 17-capped
latest Solaris and illumos forked before it.

The driver split mirrors AIX: the buffer parsing lives in the common
PsInfo driver, the JNA PsInfo is renamed to PsInfoJNA and keeps only the
pread-based arg/env read, and PsInfoFFM keeps only the pargs-based read.
The now-unused psinfo/lwpsinfo/prusage JNA structs are removed from
SolarisLibc.

Also fixes an FFM gap: its prusage POJO had dropped pr_ioch, so FFM never
populated OSProcess.getBytesRead(); the common carrier restores it so both
implementations report it.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: ef3eef64-c52b-4cb0-bb18-e68a989f5b59

📥 Commits

Reviewing files that changed from the base of the PR and between 01b49fa and f3c9e59.

📒 Files selected for processing (7)
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSThread.java
  • oshi-core/src/main/java/oshi/driver/unix/solaris/PsInfoJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
  • oshi-core/src/test/java/oshi/driver/unix/solaris/PsInfoTest.java
🚧 Files skipped from review as they are similar to previous changes (6)
  • oshi-core/src/test/java/oshi/driver/unix/solaris/PsInfoTest.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSThread.java
  • oshi-core/src/main/java/oshi/driver/unix/solaris/PsInfoJNA.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (14)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 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/software/common/os/unix/solaris/SolarisFileSystem.java
🔇 Additional comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisFileSystem.java (1)

52-53: LGTM!


📝 Walkthrough

Walkthrough

This PR unifies Solaris support across JNA and FFM backends by extracting shared struct mirrors and abstract base classes into a common package, while moving platform-specific implementations into separate JNA and FFM modules. It introduces kstat2 capability detection in the JNA layer and refactors all Solaris components to use abstract extension points.

Changes

Shared Solaris Struct Mirrors and Pure-Java Drivers

Layer / File(s) Summary
Solaris struct mirrors and utility classes
oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisTimestruc.java, SolarisPsInfo.java, SolarisLwpsInfo.java, SolarisPrUsage.java
Four new pure-Java classes mirror Solaris binary structures (timestruc_t, psinfo_t, lwpsinfo_t, prusage_t) with ByteBuffer-based constructors for struct field deserialization and utility methods like toMillis() for timestamp conversion.
PsInfo parsing utility and module export
oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java, package-info.java, module-info.java, config/checkstyle-suppressions.xml
Added PsInfo utility with static query methods for reading Solaris /proc files (psinfo, lwpsinfo, usage) and returning parsed struct instances. Exported the new shared package and updated Checkstyle suppressions for struct mirror class names.

Abstract Base Classes for Solaris OS Components

Layer / File(s) Summary
SolarisOperatingSystem and FileSystem abstractions
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java, SolarisFileSystem.java
Converted to abstract base classes; removed kstat2 capability detection, uptime/boot-time queries, and descriptor-count logic from OS level. Established abstract createProcess() hook and made filesystem helper getFileStoreMatching() public.
SolarisNetworkParams abstraction with route-based gateway lookup
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisNetworkParams.java
Created abstract SolarisNetworkParams base implementing IPv4/IPv6 default gateway detection via native route commands with shared searchGateway() parsing for use by JNA and FFM.
SolarisOSProcess and SolarisOSThread abstractions
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java, SolarisOSThread.java
Refactored to abstract bases using shared struct mirrors. Introduced abstract queryArgsEnv() and createThread() hooks. Updated updateAttributes() to use struct-based conversions (toMillis(), bytesToString()) and memoized suppliers for process bitness, psinfo, and usage.
SolarisOSFileStore package relocation
oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSFileStore.java
Moved to common package with expanded documentation clarifying Solaris lacks native code and uses a single shared class for both JNA and FFM implementations.

JNA-Specific Solaris Implementation Layer

Layer / File(s) Summary
JNA kstat2 capability detection and system uptime/boot-time
oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
Introduced SolarisOperatingSystemJNA with static HAS_KSTAT2 capability check (verifying libkstat2.so presence/readability), memoized boot/uptime queries via kstat2 (Solaris 11.4+) with legacy kstat fallback, and Solaris-specific filesystem/network/process wiring.
SolarisFileSystemJNA with descriptor querying via kstat2/kstat
oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java
Created SolarisFileSystemJNA extending abstract base, implementing descriptor-count methods with kstat2-first logic and legacy kstat fallback via memoized supplier.
SolarisNetworkParamsJNA with libc gethostname
oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisNetworkParamsJNA.java
Created SolarisNetworkParamsJNA extending shared base, implementing hostname lookup via Solaris libc gethostname with fallback to parent; inherits gateway lookup from base class.
PsInfoJNA: address-space reader for argv/envp offsets
oshi-core/src/main/java/oshi/driver/unix/solaris/PsInfoJNA.java
Refactored to focus on /proc/<pid>/as address-space reading for argument and environment reconstruction using libc open/pread/close, removing /proc/*psinfo* parsing that moved to shared PsInfo.
SolarisOSProcessJNA and SolarisOSThreadJNA implementations
oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessJNA.java, SolarisOSThreadJNA.java
Created JNA implementations: SolarisOSProcessJNA delegates args/env to PsInfoJNA, implements soft/hard open-file limits via libc getrlimit, and creates SolarisOSThreadJNA instances; SolarisOSThreadJNA is a thin wrapper.
JNA implementation references and module bootstrap
oshi-core/src/main/java/oshi/SystemInfo.java, oshi/jna/platform/unix/SolarisLibc.java
Updated SystemInfo to instantiate SolarisOperatingSystemJNA, and removed embedded Solaris struct mirrors from SolarisLibc interface.

FFM-Specific Solaris Implementation Layer

Layer / File(s) Summary
SolarisOperatingSystemFFM base extension
oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java
Refactored to extend abstract SolarisOperatingSystem, removing duplicate OS-level behavior and kstat2 detection that now resides in JNA implementation.
SolarisFileSystemFFM base extension
oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemFFM.java
Updated to extend abstract SolarisFileSystem, removing descriptor-count and per-process limit overrides.
SolarisNetworkParamsFFM base extension
oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisNetworkParamsFFM.java
Updated to extend SolarisNetworkParams base, removing duplicate gateway-lookup overrides.
PsInfoFFM simplified to args/env-only reader
oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/PsInfoFFM.java
Simplified by removing embedded struct mirrors and /proc/*psinfo* parsing, leaving only queryArgsEnv(int pid) for pargs -e command-based reading.
SolarisOSProcessFFM and SolarisOSThreadFFM implementations
oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessFFM.java, SolarisOSThreadFFM.java
Updated to extend abstract bases: SolarisOSProcessFFM delegates args/env to PsInfoFFM and thread creation to SolarisOSThreadFFM; SolarisOSThreadFFM is a thin wrapper.

Global Reference Updates to HAS_KSTAT2 and Imports

Layer / File(s) Summary
HAS_KSTAT2 capability flag references consolidated to JNA
oshi-core/src/main/java/oshi/driver/unix/solaris/kstat/SystemPages.java, oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisCentralProcessor.java, SolarisHWDiskStore.java, SolarisNetworkIF.java, oshi-core/src/main/java/oshi/util/platform/unix/solaris/KstatUtil.java
Updated static imports and references to use SolarisOperatingSystemJNA.HAS_KSTAT2 instead of former SolarisOperatingSystem.HAS_KSTAT2.
FFM documentation and comments aligned to JNA source
oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/kstat/SystemPagesFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/Kstat2Functions.java
Updated inline documentation to reference SolarisOperatingSystemJNA.HAS_KSTAT2 and clarify FFM Kstat2 behavior/limitations.
Test imports updated to use shared struct mirrors
oshi-core/src/test/java/oshi/driver/unix/solaris/PsInfoTest.java
Updated imports to use SolarisPsInfo/SolarisLwpsInfo from shared oshi.driver.common.unix.solaris package.

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related issues

Possibly related PRs

  • oshi/oshi#3132: Both PRs modify module-info.java package export declarations; this PR adds an export for the Solaris /proc carrier package.
  • oshi/oshi#3326: Both PRs touch Solaris kstat2 plumbing in oshi-core/src/main/java/oshi/util/platform/unix/solaris/KstatUtil.java.
  • oshi/oshi#3339: Both PRs modify Solaris /proc struct mirrors and config/checkstyle-suppressions.xml rules for Solaris classes.

🐰 A rabbit surveyed the grand refactor's scope,
Pure-Java mirrors shared 'cross JNA and FFM—no hope
Of abstract bases alone; they split in two,
Each backend now concrete, with kstat2 wisdom anew!
What once was tangled now stands clear and bright,
The Solaris platform unifies in sight. 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 23.96% 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 clearly and specifically describes the main change: extracting shared Solaris common abstract bases to enable JNA/FFM implementation parity.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 Jun 11, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 299 lines in your changes missing coverage. Please review.
✅ Project coverage is 68.82%. Comparing base (5b99f86) to head (f3c9e59).

Files with missing lines Patch % Lines
...are/os/unix/solaris/SolarisOperatingSystemJNA.java 0.00% 51 Missing ⚠️
...oshi/driver/common/unix/solaris/SolarisPsInfo.java 0.00% 43 Missing ⚠️
...n/java/oshi/driver/common/unix/solaris/PsInfo.java 0.00% 37 Missing ⚠️
...shi/driver/common/unix/solaris/SolarisPrUsage.java 0.00% 33 Missing ⚠️
...hi/driver/common/unix/solaris/SolarisLwpsInfo.java 0.00% 29 Missing ⚠️
...tware/common/os/unix/solaris/SolarisOSProcess.java 0.00% 24 Missing ⚠️
...software/os/unix/solaris/SolarisFileSystemJNA.java 0.00% 23 Missing ⚠️
.../software/os/unix/solaris/SolarisOSProcessJNA.java 0.00% 18 Missing ⚠️
...ftware/common/os/unix/solaris/SolarisOSThread.java 0.00% 11 Missing ⚠️
...i/driver/common/unix/solaris/SolarisTimestruc.java 0.00% 5 Missing ⚠️
... and 13 more

❗ There is a different number of reports uploaded between BASE (5b99f86) and HEAD (f3c9e59). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (5b99f86) HEAD (f3c9e59)
solaris 1 0
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3367      +/-   ##
============================================
- Coverage     75.04%   68.82%   -6.22%     
  Complexity       76       76              
============================================
  Files           552      561       +9     
  Lines         22757    22416     -341     
  Branches       3759     3701      -58     
============================================
- Hits          17078    15428    -1650     
- Misses         3578     5115    +1537     
+ Partials       2101     1873     -228     
Flag Coverage Δ
freebsd 26.16% <0.00%> (+0.39%) ⬆️
linux 29.55% <0.00%> (+0.42%) ⬆️
macos 30.23% <0.00%> (+0.45%) ⬆️
openbsd 25.58% <0.00%> (+0.38%) ⬆️
solaris ?
windows 37.96% <0.00%> (+0.53%) ⬆️

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

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

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
oshi-core/src/main/java/oshi/driver/unix/solaris/PsInfoJNA.java (1)

193-195: ⚠️ Potential issue | 🟠 Major

Fix unsigned decoding of 32-bit pointers in getOffsetFromBuffer()

For 32-bit Solaris processes (pr_dmodel ⇒ increment == 4), getOffsetFromBuffer() returns buffer.getInt(...) cast to long without treating it as unsigned. Values ≥ 0x8000_0000 become negative and are then used as addresses for pread page selection and buffer.getString(...), breaking arg/env extraction for otherwise valid processes.

Suggested fix
 private static long getOffsetFromBuffer(Memory buffer, long offset, long increment) {
-        return increment == 8 ? buffer.getLong(offset) : buffer.getInt(offset);
+        return increment == 8 ? buffer.getLong(offset) : buffer.getInt(offset) & 0xffff_ffffL;
 }
🤖 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-core/src/main/java/oshi/driver/unix/solaris/PsInfoJNA.java` around lines
193 - 195, The getOffsetFromBuffer method is incorrectly treating 32-bit pointer
values as signed; modify the branch for increment == 4 in getOffsetFromBuffer to
convert the returned int to an unsigned long (e.g., use
Integer.toUnsignedLong(buffer.getInt(offset)) or bitwise mask & 0xFFFFFFFFL) so
values >= 0x80000000 are preserved as correct positive addresses; leave the
increment == 8 path using buffer.getLong(offset) unchanged.
oshi-core/src/test/java/oshi/driver/unix/solaris/PsInfoTest.java (1)

30-31: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Guard nullable /proc reads before dereferencing in the test.

Line 30 and Line 37 call nullable APIs; direct field access at Line 31/Line 38 can intermittently NPE when an LWP exits between enumerate/read.

Suggested fix
         SolarisPsInfo psinfo = PsInfo.queryPsInfo(pid);
+        assertNotNull(psinfo, "psinfo should be readable for current PID");
         assertThat("Process ID in structure should match PID", psinfo.pr_pid, is(pid));
@@
             int tid = ParseUtil.parseIntOrDefault(lwpidFile.getName(), 0);
             SolarisLwpsInfo lwpsinfo = PsInfo.queryLwpsInfo(pid, tid);
+            if (lwpsinfo == null) {
+                continue; // LWP may exit between listing and read
+            }
             assertThat("Thread ID in structure should match TID", lwpsinfo.pr_lwpid, is(tid));

Also applies to: 37-38

🤖 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-core/src/test/java/oshi/driver/unix/solaris/PsInfoTest.java` around
lines 30 - 31, Guard nullable returns before accessing fields: after calling
PsInfo.queryPsInfo(pid) (and similarly any LwpInfo or other query* methods used
later), assert or assume the returned object is non-null before dereferencing
its fields; e.g., add an assertNotNull("PsInfo should not be null", psinfo) (or
an assumeTrue/assumeNotNull to skip the test if transient), then perform
assertThat(psinfo.pr_pid, is(pid)). Apply the same null-check pattern for the
later call(s) (e.g., LwpInfo or other query methods) before accessing their
fields to prevent intermittent NPEs.
🤖 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/software/common/os/unix/solaris/SolarisFileSystem.java`:
- Around line 52-53: The method SolarisFileSystem.getFileStoreMatching(...) is
unnecessarily public; change its declaration from "public static
List<OSFileStore> getFileStoreMatching(...)" to package-private static (remove
the public modifier) so it's accessible to SolarisOSFileStore in the same
package but not exported from the API; update any Javadoc/comment if needed to
reflect the reduced visibility.

In
`@oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java`:
- Around line 419-431: In getProcessOpenFileLimit, guard access to split[index]
to avoid ArrayIndexOutOfBoundsException: after computing String[] split =
nofilesLine.get().split("\\D+"), check that split.length > index (and that
split[index] is non-empty if desired) and return -1 when the token isn't
present, instead of directly calling ParseUtil.parseLongOrDefault(split[index],
-1); this ensures getProcessOpenFileLimit handles cases like "nofiles 256
unlimited" safely.

In
`@oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSThread.java`:
- Around line 122-126: The code in SolarisOSThread updates userTime, kernelTime,
and contextSwitches only when prusage (usage) is non-null, leaving prior
contextSwitches stale if a later refresh returns null; modify the update block
for usage (in SolarisOSThread, where usage/prusage is read) to explicitly reset
contextSwitches to 0 when usage == null (and optionally reset userTime and
kernelTime to 0 as well) so stale values are not retained.

In
`@oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java`:
- Around line 167-174: In queryBootAndUptime(), change the Kstat2 path used in
KstatUtil.queryKstat2 to include the "kstat:/" prefix (use
"kstat:/misc/unix/system_misc") so boot_time/snaptime aren't null, and normalize
the boot_time fallback to seconds (if results[0] is null set boot =
System.currentTimeMillis() / 1000L) to match getSystemBootTime() expectations;
keep the snaptime conversion to seconds by dividing results[1] by 1_000_000_000L
and return the Pair<>(boot, snap) from the same method name.

In
`@oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessJNA.java`:
- Around line 47-48: The code currently calls
SolarisLibc.INSTANCE.getrlimit(SolarisLibc.RLIMIT_NOFILE, rlimit) and then uses
rlimit.rlim_cur / rlim_max without checking the call's return status; change
both usages (the calls around rlimit.rlim_cur and rlimit.rlim_max) to capture
the return value (e.g., int rc = SolarisLibc.INSTANCE.getrlimit(...)), verify rc
== 0 before reading rlimit fields, and on failure handle it consistently (log or
propagate an error and return a sentinel like -1 or throw) so you never consume
rlimit.rlim_* after a failed getrlimit. Ensure you update both places referenced
in the diff and use SolarisLibc.INSTANCE.getrlimit, SolarisLibc.RLIMIT_NOFILE,
and rlimit names to locate the changes.

---

Outside diff comments:
In `@oshi-core/src/main/java/oshi/driver/unix/solaris/PsInfoJNA.java`:
- Around line 193-195: The getOffsetFromBuffer method is incorrectly treating
32-bit pointer values as signed; modify the branch for increment == 4 in
getOffsetFromBuffer to convert the returned int to an unsigned long (e.g., use
Integer.toUnsignedLong(buffer.getInt(offset)) or bitwise mask & 0xFFFFFFFFL) so
values >= 0x80000000 are preserved as correct positive addresses; leave the
increment == 8 path using buffer.getLong(offset) unchanged.

In `@oshi-core/src/test/java/oshi/driver/unix/solaris/PsInfoTest.java`:
- Around line 30-31: Guard nullable returns before accessing fields: after
calling PsInfo.queryPsInfo(pid) (and similarly any LwpInfo or other query*
methods used later), assert or assume the returned object is non-null before
dereferencing its fields; e.g., add an assertNotNull("PsInfo should not be
null", psinfo) (or an assumeTrue/assumeNotNull to skip the test if transient),
then perform assertThat(psinfo.pr_pid, is(pid)). Apply the same null-check
pattern for the later call(s) (e.g., LwpInfo or other query methods) before
accessing their fields to prevent intermittent NPEs.
🪄 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: 4f1cd15d-7ca1-4cd4-a7a5-67e5d5dcb6ce

📥 Commits

Reviewing files that changed from the base of the PR and between 5b99f86 and 01b49fa.

📒 Files selected for processing (37)
  • config/checkstyle-suppressions.xml
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisLwpsInfo.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisPrUsage.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisPsInfo.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisTimestruc.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisNetworkParams.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSThread.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/PsInfoFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/kstat/SystemPagesFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/Kstat2Functions.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSFileStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSThreadFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/SystemInfo.java
  • oshi-core/src/main/java/oshi/driver/unix/solaris/PsInfoJNA.java
  • oshi-core/src/main/java/oshi/driver/unix/solaris/kstat/SystemPages.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisCentralProcessor.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java
  • oshi-core/src/main/java/oshi/jna/platform/unix/SolarisLibc.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisNetworkParamsJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSThreadJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/util/platform/unix/solaris/KstatUtil.java
  • oshi-core/src/test/java/oshi/driver/unix/solaris/PsInfoTest.java
💤 Files with no reviewable changes (2)
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSFileStoreFFM.java
  • oshi-core/src/main/java/oshi/jna/platform/unix/SolarisLibc.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). (14)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, macos-latest
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 26, windows-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: JMH Benchmarks, windows-latest
🧰 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/oshi/driver/common/unix/solaris/SolarisLwpsInfo.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisTimestruc.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/package-info.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisNetworkParams.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisPrUsage.java
  • oshi-common/src/main/java/module-info.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisPsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSThread.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSFileStore.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOperatingSystem.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisHWDiskStore.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSThreadJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOperatingSystemJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisCentralProcessor.java
  • oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisNetworkParamsJNA.java
🔇 Additional comments (19)
oshi-core/src/main/java/oshi/SystemInfo.java (1)

30-30: LGTM!

Also applies to: 122-122

oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisNetworkParamsJNA.java (1)

13-13: LGTM!

Also applies to: 19-31

oshi-core/src/main/java/oshi/software/os/unix/solaris/SolarisOSThreadJNA.java (1)

14-18: LGTM!

oshi-core/src/main/java/oshi/driver/unix/solaris/kstat/SystemPages.java (1)

7-7: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/unix/solaris/SolarisNetworkIF.java (1)

7-7: LGTM!

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

28-28: LGTM!

oshi-common/src/main/java/oshi/driver/common/unix/solaris/package-info.java (1)

1-8: LGTM!

oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisTimestruc.java (1)

14-31: LGTM!

oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisLwpsInfo.java (1)

16-67: LGTM!

oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisPrUsage.java (1)

17-76: LGTM!

oshi-common/src/main/java/oshi/driver/common/unix/solaris/SolarisPsInfo.java (1)

16-95: LGTM!

config/checkstyle-suppressions.xml (1)

33-37: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSProcess.java (1)

5-5: LGTM!

Also applies to: 36-39, 48-60, 87-87, 99-106, 139-140, 331-333, 354-357, 362-364, 369-376, 386-386, 412-418, 434-447

oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java (1)

40-56: LGTM!

Also applies to: 65-77, 85-96, 105-116, 124-130

oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisNetworkParams.java (1)

16-26: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/solaris/SolarisOSFileStore.java (1)

5-5: LGTM!

Also applies to: 12-13

oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisNetworkParamsFFM.java (1)

15-15: LGTM!

Also applies to: 17-21

oshi-core-ffm/src/main/java/oshi/driver/unix/solaris/kstat/SystemPagesFFM.java (1)

30-32: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/Kstat2Functions.java (1)

31-31: LGTM!

Several issues surfaced in review of code carried into oshi-common; all
pre-existed the parity refactor and are fixed here:

- PsInfoJNA.getOffsetFromBuffer: read 32-bit pointers as unsigned so high
  user addresses (>= 0x80000000) aren't sign-extended.
- SolarisOperatingSystemJNA.queryBootAndUptime: use the kstat:/ URI prefix
  ("kstat:/misc/unix/system_misc") so boot_time/snaptime resolve on Solaris
  11.4+, and keep the boot_time fallback in seconds.
- SolarisOSProcessJNA: check the getrlimit return status before reading
  rlim_cur/rlim_max, matching the AIX and FFM implementations.
- SolarisOSProcess.getProcessOpenFileLimit: guard the split index so a
  non-numeric plimit token (e.g. "nofiles ... unlimited") can't throw.
- SolarisOSThread: reset contextSwitches to 0 before the usage block so a
  later refresh that can't read usage doesn't retain a stale value.

Also tighten visibility and tests:
- SolarisFileSystem.getFileStoreMatching is package-private (only the
  same-package SolarisOSFileStore and getFileStores call it), matching AIX.
- PsInfoTest asserts the query results are non-null before dereferencing.
@dbwiddis
dbwiddis merged commit 6e7edc8 into oshi:master Jun 11, 2026
20 of 22 checks passed
@dbwiddis
dbwiddis deleted the solaris-common-base branch June 11, 2026 01:44
dbwiddis added a commit that referenced this pull request Jun 12, 2026
The FreeBSD, OpenBSD, and DragonFly OperatingSystem classes each duplicated
their entire body between the JNA and FFM backends (the method signatures were
identical; only the native calls and backend factory types differed).

Following the Solaris #3367 template, extract an abstract per-platform base in
oshi-common holding the ps-based process enumeration, process/thread counts,
services, and system uptime/boot time. The JNA and FFM subclasses are reduced to
the genuinely backend-specific bits: the OSProcess factory (a new createProcess
hook), the FileSystem/NetworkParams/InternetProtocolStats factories, getpid/
thread-id, the sysctl version query, and who sessions.

Per-platform notes:
- FreeBSD/DragonFly read boot time from a native sysctl struct, so the base
  declares an abstract queryBootTime() hook (memoized); OpenBSD text-parses it,
  so its base implements queryBootTime() concretely.
- OpenBSD's InternetProtocolStats and NetworkParams are common (non-native)
  classes, so they move into the base; FreeBSD/DragonFly keep their JNA/FFM
  factory overrides. DragonFly reuses FreeBSD's filesystem/IP/network impls and
  keeps its kernel-thread (pid <= 0) filter.

NetBSD already has a single common OperatingSystem class and is unchanged. The
JNA/FFM subclasses shrink from ~225-238 lines each to ~55-90.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant