Repository navigation
Unify ps-based BSD OSProcess parsing onto a shared BsdOSProcess base - #3372
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (4)
📜 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)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
🔇 Additional comments (5)
📝 WalkthroughWalkthroughThis PR centralizes BSD ps-driven process attribute parsing in a shared BsdOSProcess base, adds a BsdPsKeyword enum and an ordered ParseUtil mapping overload, and refactors FreeBSD, OpenBSD, DragonFly, and NetBSD (FFM and JNA variants) to use platform PS_KEYWORDS/PS_COMMAND_ARGS and the shared attribute population hooks. ChangesBSD Process Consolidation
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related issues
Possibly related PRs
🚥 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 |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (1)
81-92: 💤 Low valueInconsistent parallel stream usage across BSD platforms.
FreeBSD uses
.parallel()for thread detail parsing (line 88), while NetBSD and OpenBSD do not use parallel streams in their equivalentgetThreadDetails()methods. While this is functionally correct, consider aligning the implementations for consistency—either all platforms use parallel or none do.🤖 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/unix/freebsd/FreeBsdOSProcess.java` around lines 81 - 92, FreeBsdOSProcess.getThreadDetails currently calls .parallel() on the stream which is inconsistent with NetBSD/OpenBSD implementations; to align behavior remove the .parallel() call so the stream processing is sequential (locate the getThreadDetails method in FreeBsdOSProcess and delete the .parallel() between .skip(1) and .map), ensuring semantics and thread parsing remain the same across BSD platforms.
🤖 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/dragonflybsd/DragonFlyBsdOSProcess.java`:
- Around line 84-98: The method queryStartTimeFromProc currently returns
System.currentTimeMillis() on parse failures which makes
BsdOSProcess.updateAttributes treat the process as started now; change the
failure return value to -1L so the base-class fallback path (ETIME/ETIMES) is
used; locate queryStartTimeFromProc in DragonFlyBsdOSProcess and replace the
final return with -1L (ensuring callers like BsdOSProcess.updateAttributes will
detect the sentinel and use the elapsed-time fallback).
---
Nitpick comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java`:
- Around line 81-92: FreeBsdOSProcess.getThreadDetails currently calls
.parallel() on the stream which is inconsistent with NetBSD/OpenBSD
implementations; to align behavior remove the .parallel() call so the stream
processing is sequential (locate the getThreadDetails method in FreeBsdOSProcess
and delete the .parallel() between .skip(1) and .map), ensuring semantics and
thread parsing remain the same across BSD platforms.
🪄 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: 05e4b70c-bdbe-4092-8118-483cbb911740
📒 Files selected for processing (25)
config/checkstyle-suppressions.xmloshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/package-info.javaoshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/test/java/oshi/util/ParseUtilTest.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.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/oshi/software/common/os/unix/bsd/BsdPsKeyword.javaoshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/package-info.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.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/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java
🔇 Additional comments (41)
oshi-common/src/main/java/oshi/util/ParseUtil.java (1)
1395-1436: LGTM!oshi-common/src/test/java/oshi/util/ParseUtilTest.java (1)
926-946: LGTM!config/checkstyle-suppressions.xml (1)
65-68: LGTM!oshi-common/src/main/java/module-info.java (1)
50-50: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java (1)
13-16: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/bsd/package-info.java (1)
5-8: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (1)
7-82: LGTM!Also applies to: 100-111
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java (5)
1-70: LGTM!
207-245: LGTM!
254-315: LGTM!
323-367: LGTM!
375-424: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (1)
49-54: LGTM!Also applies to: 71-79
oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (4)
49-77: LGTM!
79-107: LGTM!
109-145: LGTM!
147-195: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java (1)
107-133: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java (2)
41-76: LGTM!
78-101: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (3)
26-46: LGTM!
48-68: LGTM!
106-128: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java (1)
34-36: LGTM!Also applies to: 127-142
oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (3)
28-56: LGTM!
58-102: LGTM!
143-161: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java (1)
33-35: LGTM!Also applies to: 124-138
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java (3)
34-55: LGTM!
57-94: LGTM!
96-132: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java (1)
31-34: LGTM!Also applies to: 119-140
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java (3)
25-61: LGTM!
63-103: LGTM!
105-139: LGTM!oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java (1)
1-118: LGTM!oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.java (1)
28-29: LGTM!Also applies to: 125-139
oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.java (1)
1-152: LGTM!oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java (1)
30-31: LGTM!Also applies to: 125-139
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java (1)
28-31: LGTM!Also applies to: 121-147
oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java (1)
212-217: LGTM!
Adds stringToEnumMap(Class, List<K> keys, values, delim), which maps an explicit ordered subset of enum keys rather than every constant in ordinal order. The existing all-values method now delegates to it. This lets a single enum back per-platform column subsets that vary in which columns are present and their order, with the final key still slurping the line remainder.
The FreeBSD, OpenBSD, DragonFly, and NetBSD OSProcess implementations each duplicated their ps-output parsing: updateAttributes(psMap) was byte-identical between the JNA and FFM backends, and ~85% similar across the four platforms, while each OperatingSystem class carried its own copy of the PsKeywords enum and PS_COMMAND_ARGS constant. Collapse this onto BsdOSProcess: - Add a single BsdPsKeyword master enum (union of all BSD ps columns). Each platform's OSProcess base declares its ordered PS_KEYWORDS subset and derives PS_COMMAND_ARGS from it; the OperatingSystem classes reference those instead of their own copies. - Move the no-arg updateAttributes() and a single shared updateAttributes(Map<BsdPsKeyword,String>) into BsdOSProcess. Per-platform differences (group vs user+rgid, nlwp vs separate thread count, systime/ cputime/time, elapsed-vs-/proc start time, comm/ucomm, args/command) are handled by checking which keys are present, with two protected hooks: queryStartTimeMillis() (DragonFly overrides to read /proc) and updateThreadCount() (OpenBSD/NetBSD override). - Move the (identical JNA/FFM) getThreadDetails() down into each platform's OSProcess base. The JNA/FFM OSProcess classes now hold only their native code (arguments, environment, bitness, rlimit, cwd, open files). Derived PS_COMMAND_ARGS strings are unchanged, so the ps invocations are identical. Also unifies a pre-existing JNA/FFM divergence: OpenBSD's FFM updateThreadCount clamped the count to at least 1 while JNA did not; the shared version keeps the clamp (a live process always has at least one thread), matching NetBSD.
testThreads read a thread's user time, called updateAttributes(), and asserted the user time alone was nondecreasing. On platforms that derive thread user time as (total - kernel) from coarse-resolution ps columns (e.g. FreeBSD: TIME minus SYSTIME), the user component can dip between two back-to-back reads: the ps syscall used to take the second reading bumps the thread's kernel time while the total rounds unchanged. The sibling testProcess avoids this by sleeping 500ms between reads; testThreads reads immediately, so it flaked. Assert the total CPU time (user + kernel, which maps to the monotonic ps TIME) is nondecreasing instead, keeping the kernel-time-nondecreasing check. Pre- existing flakiness, independent of the OSProcess parsing dedup.
4f4b514 to
2472109
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3372 +/- ##
============================================
- Coverage 75.18% 68.80% -6.39%
Complexity 76 76
============================================
Files 565 566 +1
Lines 22192 22094 -98
Branches 3662 3658 -4
============================================
- Hits 16686 15202 -1484
- Misses 3450 5026 +1576
+ Partials 2056 1866 -190
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 2
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/software/os/unix/openbsd/OpenBsdOSProcessJNA.java (1)
106-138:⚠️ Potential issue | 🟠 MajorGuard
ARGMAXbefore allocating JNAMemoryinqueryEnvironmentVariables()If the
kern.argmaxsysctl fails,ARGMAXis set to0, butqueryEnvironmentVariables()still doesnew Memory(ARGMAX).com.sun.jna.Memory(long)requires a strictly positive size and throwsIllegalArgumentExceptionfor0/negative values, so the fallback path can crash the first env-var query. Add the sameARGMAX > 0guard used byqueryArguments().Suggested fix
`@Override` protected Map<String, String> queryEnvironmentVariables() { + if (ARGMAX <= 0) { + return Collections.emptyMap(); + } // Get environment variables via sysctl(3) int[] mib = new int[4]; mib[0] = 1; // CTL_KERN mib[1] = 55; // KERN_PROC_ARGS mib[2] = getProcessID(); mib[3] = 3; // KERN_PROC_ENV // Allocate memory for environment variables try (Memory m = new Memory(ARGMAX); CloseableSizeTByReference size = new CloseableSizeTByReference(ARGMAX)) { // Fetch environment variables if (OpenBsdLibc.INSTANCE.sysctl(mib, mib.length, m, size, null, size_t.ZERO) == 0) { // Returns a null-terminated list of pointers to the actual data Map<String, String> env = new LinkedHashMap<>(); // To iterate the pointer-list long offset = 0; // Get the data base address to calculate offsets long baseAddr = Pointer.nativeValue(m); long maxAddr = baseAddr + size.longValue(); // Get the address of the data. If null (0) we're done iterating long argAddr = Pointer.nativeValue(m.getPointer(offset)); while (argAddr > baseAddr && argAddr < maxAddr) { String envStr = m.getString(argAddr - baseAddr); int idx = envStr.indexOf('='); if (idx > 0) { env.put(envStr.substring(0, idx), envStr.substring(idx + 1)); } offset += Native.POINTER_SIZE; argAddr = Pointer.nativeValue(m.getPointer(offset)); } return Collections.unmodifiableMap(env); } } return Collections.emptyMap();🤖 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/software/os/unix/openbsd/OpenBsdOSProcessJNA.java` around lines 106 - 138, The method queryEnvironmentVariables() allocates new Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard used in queryArguments() so we bail out early (return Collections.emptyMap()) when ARGMAX is non-positive, preventing IllegalArgumentException from com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check immediately before the Memory allocation/try-with-resources block.oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)
114-115:⚠️ Potential issue | 🔴 CriticalFix
sysctlcall-state allocation in DragonFly (queryBitness)
DragonFlyBsdOSProcessFFM.queryBitness()allocatescallStatewitharena.allocate(ADDRESS)and passes it toFreeBsdLibcFunctions.sysctl(...). ButFreeBsdLibcFunctions.sysctlusesCAPTURE_CALL_STATEand its javadoc requirescallStateto be allocated withForeignFunctions.CAPTURED_STATE_LAYOUTfor errno capture; the otherFreeBsdLibcFunctions.sysctlcall sites in this cohort allocateCAPTURED_STATE_LAYOUT(e.g.,FreeBsdOSProcessFFM). This ADDRESS-vs-layout mismatch can break captured errno handling and make the downcall unsafe.🤖 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-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java` around lines 114 - 115, In DragonFlyBsdOSProcessFFM.queryBitness(), the callState is incorrectly allocated with arena.allocate(ADDRESS) before calling FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e., arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of the sysctl invocation the same and ensure the arena lifecycle remains correct.
♻️ Duplicate comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (1)
84-98:⚠️ Potential issue | 🟠 Major | ⚡ Quick winReturn the hook sentinel on parse failure to preserve elapsed-time fallback.
On Line 97, returning
System.currentTimeMillis()causesBsdOSProcess.updateAttributes()to treat failures as "started now," which collapses uptime to ~1 ms instead of usingpselapsed time. This hook should return-1Lwhen/procparsing fails so the base-class fallback path (ETIME/ETIMES) is used.Suggested fix
- return System.currentTimeMillis(); + return -1L;🤖 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/unix/dragonflybsd/DragonFlyBsdOSProcess.java` around lines 84 - 98, In DragonFlyBsdOSProcess.queryStartTimeFromProc change the failure return value to -1L instead of System.currentTimeMillis() so parse or missing /proc data signals a sentinel; ensure any branches where parsing fails or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its ETIME/ETIMES elapsed-time fallback rather than treating the process as "started now."
🤖 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/bsd/BsdOSProcess.java`:
- Around line 39-42: The memoized identity fields (bitness, commandLine,
arguments, environmentVariables) are cached for the instance lifetime and can
become stale after PID reuse; update the class so these identity values are not
permanently memoized — either remove memoize() for those Suppliers and call
queryBitness/queryCommandLine/queryArguments/queryEnvironmentVariables directly,
or clear/reset their caches inside updateAttributes() whenever the process
identity changes (compare startTime or another identity field) so the Suppliers
(or backing fields) are refreshed; refer to the fields bitness, commandLine,
arguments, environmentVariables, the memoize helper, and the updateAttributes
method/OSProcess identity checks when making the change.
- Around line 260-268: The code in BsdOSProcess currently sets group = user when
BsdPsKeyword.GROUP is missing, which can produce inconsistent metadata; change
the branch handling psMap missing GROUP to not substitute the user name —
instead set group to an empty/unknown value (e.g., empty string or null) and
still set groupID = psMap.get(BsdPsKeyword.RGID); optionally attempt to resolve
the group name from the RGID (via existing group lookup utilities) and assign
that to group if resolution succeeds. Ensure you only modify the else branch
referencing psMap, BsdPsKeyword.GROUP, GID, RGID, group, groupID, and user.
---
Outside diff comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java`:
- Around line 114-115: In DragonFlyBsdOSProcessFFM.queryBitness(), the callState
is incorrectly allocated with arena.allocate(ADDRESS) before calling
FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the
allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e.,
arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe
and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of
the sysctl invocation the same and ensure the arena lifecycle remains correct.
In
`@oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java`:
- Around line 106-138: The method queryEnvironmentVariables() allocates new
Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard
used in queryArguments() so we bail out early (return Collections.emptyMap())
when ARGMAX is non-positive, preventing IllegalArgumentException from
com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check
immediately before the Memory allocation/try-with-resources block.
---
Duplicate comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java`:
- Around line 84-98: In DragonFlyBsdOSProcess.queryStartTimeFromProc change the
failure return value to -1L instead of System.currentTimeMillis() so parse or
missing /proc data signals a sentinel; ensure any branches where parsing fails
or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its
ETIME/ETIMES elapsed-time fallback rather than treating the process as "started
now."
🪄 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: 44f0698e-e7cf-42a1-b80c-c6d4768e4183
📒 Files selected for processing (22)
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.javaoshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/test/java/oshi/util/ParseUtilTest.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
🚧 Files skipped from review as they are similar to previous changes (13)
- oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
- oshi-common/src/test/java/oshi/util/ParseUtilTest.java
- oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
- oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
- oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
- oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
- oshi-common/src/main/java/oshi/util/ParseUtil.java
- oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java
- oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.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 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 26, windows-latest
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 26, macos-latest
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 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/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java
📚 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/dragonflybsd/DragonFlyBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
🔇 Additional comments (14)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (4)
7-52: LGTM!
58-67: LGTM!
69-77: LGTM!
100-111: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (4)
7-54: LGTM!
60-69: LGTM!
71-79: LGTM!
81-92: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (4)
7-69: LGTM!
73-87: LGTM!
90-145: LGTM!
148-194: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)
42-67: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (1)
52-55: LGTM!Also applies to: 59-101, 144-160
There was a problem hiding this comment.
Caution
Inline review comments failed to post. This is likely due to GitHub's internal server error or limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.
Actionable comments posted: 2
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/software/os/unix/openbsd/OpenBsdOSProcessJNA.java (1)
106-138:⚠️ Potential issue | 🟠 MajorGuard
ARGMAXbefore allocating JNAMemoryinqueryEnvironmentVariables()If the
kern.argmaxsysctl fails,ARGMAXis set to0, butqueryEnvironmentVariables()still doesnew Memory(ARGMAX).com.sun.jna.Memory(long)requires a strictly positive size and throwsIllegalArgumentExceptionfor0/negative values, so the fallback path can crash the first env-var query. Add the sameARGMAX > 0guard used byqueryArguments().Suggested fix
`@Override` protected Map<String, String> queryEnvironmentVariables() { + if (ARGMAX <= 0) { + return Collections.emptyMap(); + } // Get environment variables via sysctl(3) int[] mib = new int[4]; mib[0] = 1; // CTL_KERN mib[1] = 55; // KERN_PROC_ARGS mib[2] = getProcessID(); mib[3] = 3; // KERN_PROC_ENV // Allocate memory for environment variables try (Memory m = new Memory(ARGMAX); CloseableSizeTByReference size = new CloseableSizeTByReference(ARGMAX)) { // Fetch environment variables if (OpenBsdLibc.INSTANCE.sysctl(mib, mib.length, m, size, null, size_t.ZERO) == 0) { // Returns a null-terminated list of pointers to the actual data Map<String, String> env = new LinkedHashMap<>(); // To iterate the pointer-list long offset = 0; // Get the data base address to calculate offsets long baseAddr = Pointer.nativeValue(m); long maxAddr = baseAddr + size.longValue(); // Get the address of the data. If null (0) we're done iterating long argAddr = Pointer.nativeValue(m.getPointer(offset)); while (argAddr > baseAddr && argAddr < maxAddr) { String envStr = m.getString(argAddr - baseAddr); int idx = envStr.indexOf('='); if (idx > 0) { env.put(envStr.substring(0, idx), envStr.substring(idx + 1)); } offset += Native.POINTER_SIZE; argAddr = Pointer.nativeValue(m.getPointer(offset)); } return Collections.unmodifiableMap(env); } } return Collections.emptyMap();🤖 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/software/os/unix/openbsd/OpenBsdOSProcessJNA.java` around lines 106 - 138, The method queryEnvironmentVariables() allocates new Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard used in queryArguments() so we bail out early (return Collections.emptyMap()) when ARGMAX is non-positive, preventing IllegalArgumentException from com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check immediately before the Memory allocation/try-with-resources block.oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)
114-115:⚠️ Potential issue | 🔴 CriticalFix
sysctlcall-state allocation in DragonFly (queryBitness)
DragonFlyBsdOSProcessFFM.queryBitness()allocatescallStatewitharena.allocate(ADDRESS)and passes it toFreeBsdLibcFunctions.sysctl(...). ButFreeBsdLibcFunctions.sysctlusesCAPTURE_CALL_STATEand its javadoc requirescallStateto be allocated withForeignFunctions.CAPTURED_STATE_LAYOUTfor errno capture; the otherFreeBsdLibcFunctions.sysctlcall sites in this cohort allocateCAPTURED_STATE_LAYOUT(e.g.,FreeBsdOSProcessFFM). This ADDRESS-vs-layout mismatch can break captured errno handling and make the downcall unsafe.🤖 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-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java` around lines 114 - 115, In DragonFlyBsdOSProcessFFM.queryBitness(), the callState is incorrectly allocated with arena.allocate(ADDRESS) before calling FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e., arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of the sysctl invocation the same and ensure the arena lifecycle remains correct.
♻️ Duplicate comments (1)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (1)
84-98:⚠️ Potential issue | 🟠 Major | ⚡ Quick winReturn the hook sentinel on parse failure to preserve elapsed-time fallback.
On Line 97, returning
System.currentTimeMillis()causesBsdOSProcess.updateAttributes()to treat failures as "started now," which collapses uptime to ~1 ms instead of usingpselapsed time. This hook should return-1Lwhen/procparsing fails so the base-class fallback path (ETIME/ETIMES) is used.Suggested fix
- return System.currentTimeMillis(); + return -1L;🤖 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/unix/dragonflybsd/DragonFlyBsdOSProcess.java` around lines 84 - 98, In DragonFlyBsdOSProcess.queryStartTimeFromProc change the failure return value to -1L instead of System.currentTimeMillis() so parse or missing /proc data signals a sentinel; ensure any branches where parsing fails or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its ETIME/ETIMES elapsed-time fallback rather than treating the process as "started now."
🤖 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/bsd/BsdOSProcess.java`:
- Around line 39-42: The memoized identity fields (bitness, commandLine,
arguments, environmentVariables) are cached for the instance lifetime and can
become stale after PID reuse; update the class so these identity values are not
permanently memoized — either remove memoize() for those Suppliers and call
queryBitness/queryCommandLine/queryArguments/queryEnvironmentVariables directly,
or clear/reset their caches inside updateAttributes() whenever the process
identity changes (compare startTime or another identity field) so the Suppliers
(or backing fields) are refreshed; refer to the fields bitness, commandLine,
arguments, environmentVariables, the memoize helper, and the updateAttributes
method/OSProcess identity checks when making the change.
- Around line 260-268: The code in BsdOSProcess currently sets group = user when
BsdPsKeyword.GROUP is missing, which can produce inconsistent metadata; change
the branch handling psMap missing GROUP to not substitute the user name —
instead set group to an empty/unknown value (e.g., empty string or null) and
still set groupID = psMap.get(BsdPsKeyword.RGID); optionally attempt to resolve
the group name from the RGID (via existing group lookup utilities) and assign
that to group if resolution succeeds. Ensure you only modify the else branch
referencing psMap, BsdPsKeyword.GROUP, GID, RGID, group, groupID, and user.
---
Outside diff comments:
In
`@oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java`:
- Around line 114-115: In DragonFlyBsdOSProcessFFM.queryBitness(), the callState
is incorrectly allocated with arena.allocate(ADDRESS) before calling
FreeBsdLibcFunctions.sysctl (which uses CAPTURE_CALL_STATE); change the
allocation to use ForeignFunctions.CAPTURED_STATE_LAYOUT (i.e.,
arena.allocate(ForeignFunctions.CAPTURED_STATE_LAYOUT)) so errno capture is safe
and consistent with other callers (see FreeBsdOSProcessFFM); keep the rest of
the sysctl invocation the same and ensure the arena lifecycle remains correct.
In
`@oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.java`:
- Around line 106-138: The method queryEnvironmentVariables() allocates new
Memory(ARGMAX) without checking ARGMAX may be 0; add the same ARGMAX > 0 guard
used in queryArguments() so we bail out early (return Collections.emptyMap())
when ARGMAX is non-positive, preventing IllegalArgumentException from
com.sun.jna.Memory; locate queryEnvironmentVariables and insert the ARGMAX check
immediately before the Memory allocation/try-with-resources block.
---
Duplicate comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java`:
- Around line 84-98: In DragonFlyBsdOSProcess.queryStartTimeFromProc change the
failure return value to -1L instead of System.currentTimeMillis() so parse or
missing /proc data signals a sentinel; ensure any branches where parsing fails
or seconds <= 0 return -1L so BsdOSProcess.updateAttributes can use its
ETIME/ETIMES elapsed-time fallback rather than treating the process as "started
now."
🪄 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: 44f0698e-e7cf-42a1-b80c-c6d4768e4183
📒 Files selected for processing (22)
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.javaoshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.javaoshi-common/src/main/java/oshi/util/ParseUtil.javaoshi-common/src/test/java/oshi/util/ParseUtilTest.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.javaoshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
🚧 Files skipped from review as they are similar to previous changes (13)
- oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdPsKeyword.java
- oshi-common/src/test/java/oshi/util/ParseUtilTest.java
- oshi-core/src/test/java/oshi/software/os/shared/OperatingSystemTest.java
- oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdOSProcess.java
- oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemJNA.java
- oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOperatingSystemFFM.java
- oshi-common/src/main/java/oshi/util/ParseUtil.java
- oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemJNA.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOperatingSystemFFM.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOperatingSystemFFM.java
- oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java
- oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
📜 Review details
🔇 Additional comments (14)
oshi-common/src/main/java/oshi/software/common/os/unix/dragonflybsd/DragonFlyBsdOSProcess.java (4)
7-52: LGTM!
58-67: LGTM!
69-77: LGTM!
100-111: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdOSProcess.java (4)
7-54: LGTM!
60-69: LGTM!
71-79: LGTM!
81-92: LGTM!oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (4)
7-69: LGTM!
73-87: LGTM!
90-145: LGTM!
148-194: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)
42-67: LGTM!oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (1)
52-55: LGTM!Also applies to: 59-101, 144-160
🛑 Comments failed to post (2)
oshi-common/src/main/java/oshi/software/common/os/unix/bsd/BsdOSProcess.java (2)
39-42:
⚠️ Potential issue | 🟠 Major | 🏗️ Heavy liftMemoized identity fields can go stale after PID reuse.
updateAttributes()repopulates the instance from whatever process currently owns this PID, butbitness,arguments,environmentVariables, andcommandLineare cached for the lifetime of the object. If a caller reads any of those once and the PID is later recycled, the instance will mix old-process identity data with new-process counters/state. This shared base is now the single place to prevent that, either by rejecting refresh when process identity changes or by avoiding lifetime memoization on a mutableOSProcess.Also applies to: 87-90, 229-245, 294-303
🤖 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/unix/bsd/BsdOSProcess.java` around lines 39 - 42, The memoized identity fields (bitness, commandLine, arguments, environmentVariables) are cached for the instance lifetime and can become stale after PID reuse; update the class so these identity values are not permanently memoized — either remove memoize() for those Suppliers and call queryBitness/queryCommandLine/queryArguments/queryEnvironmentVariables directly, or clear/reset their caches inside updateAttributes() whenever the process identity changes (compare startTime or another identity field) so the Suppliers (or backing fields) are refreshed; refer to the fields bitness, commandLine, arguments, environmentVariables, the memoize helper, and the updateAttributes method/OSProcess identity checks when making the change.
260-268:
⚠️ Potential issue | 🟠 Major | ⚡ Quick winDon't substitute the user name for the group name.
When
GROUPis missing, this storesgroupID = RGIDbutgroup = user. Those fields can legitimately refer to different principals, so callers can get internally inconsistent process metadata on DragonFly and any other platform that takes this branch. A safer fallback is to leavegroupunknown/empty here, or resolve it fromRGID.💡 Minimal safe fallback
} else { - this.group = this.user; + this.group = ""; this.groupID = psMap.get(BsdPsKeyword.RGID); }🤖 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/unix/bsd/BsdOSProcess.java` around lines 260 - 268, The code in BsdOSProcess currently sets group = user when BsdPsKeyword.GROUP is missing, which can produce inconsistent metadata; change the branch handling psMap missing GROUP to not substitute the user name — instead set group to an empty/unknown value (e.g., empty string or null) and still set groupID = psMap.get(BsdPsKeyword.RGID); optionally attempt to resolve the group name from the RGID (via existing group lookup utilities) and assign that to group if resolution succeeds. Ensure you only modify the else branch referencing psMap, BsdPsKeyword.GROUP, GID, RGID, group, groupID, and user.
- DragonFlyBsdOSProcess.queryStartTimeFromProc: return the -1 sentinel on /proc read/parse failure instead of System.currentTimeMillis(), so updateAttributes() falls back to elapsed time rather than treating the process as started now. - OpenBsdOSProcess/NetBsdOSProcess.getThreadDetails: parallelize the thread-row stream to match FreeBSD/DragonFly. The pipeline is stateless and each OSThread is independent (Collectors.toList preserves encounter order), so results are unchanged. - DragonFlyBsdOSProcessFFM.queryBitness: allocate the captured-call-state segment with CAPTURED_STATE_LAYOUT instead of ADDRESS, matching the other FFM sysctl callers, so errno capture is correctly sized. - OpenBsdOSProcessJNA.queryEnvironmentVariables: guard on ARGMAX > 0 (as queryArguments already does) to avoid new Memory(0) throwing when the kern.argmax sysctl is unavailable.
Summary
Builds on #3370 (which extracted the shared
BsdOSProcessbase holding the BSD-family field storage and accessors). This PR unifies the remaining duplication: theps-output parsing.Before this change, each platform's
updateAttributes(psMap)was byte-identical between the JNA and FFM backends and ~85% similar across FreeBSD/OpenBSD/DragonFly/NetBSD, while eachOperatingSystemclass carried its own copy of thePsKeywordsenum +PS_COMMAND_ARGS.BsdPsKeywordmaster enum (union of all BSDpscolumns). Each platform'sOSProcessbase declares its orderedPS_KEYWORDSsubset and derivesPS_COMMAND_ARGSfrom it; theOperatingSystemclasses reference those instead of per-backend copies.ParseUtil.stringToEnumMap(Class, List<K> keys, values, delim)overload that maps an explicit ordered subset (the last key slurps the line remainder). The existing all-values method delegates to it. This is needed becausestringToEnumMapis positional by enum ordinal, so a single master enum can't be parsed with the all-values form — each platform requests a different column subset/order.updateAttributes(Map<BsdPsKeyword,String>)and no-argupdateAttributes()inBsdOSProcess, reading defensively by present key. Per-platform differences are handled by two protected hooks:queryStartTimeMillis()(DragonFly overrides to read/proc) andupdateThreadCount()(OpenBSD/NetBSD override).getThreadDetails()moves into each platform'sOSProcessbase.The JNA/FFM
OSProcessclasses now hold only their native code (arguments, environment, bitness, rlimit, cwd, open files). DerivedPS_COMMAND_ARGSstrings are byte-identical to before, so thepsinvocations are unchanged.Solaris and AIX source process data from
/procpsinfo structs and perfstat rather thanps, so they are out of scope.Notes
updateThreadCountclamped the count to at least 1 while JNA did not; the shared version keeps the clamp (a live process always has at least one thread), matching NetBSD.OperatingSystemTest.testThreadswas pre-existing flaky: it asserted a thread's user-time component was nondecreasing, but platforms that derive it asTIME - SYSTIMEfrom coarse-resolutionpscolumns can see it dip between two back-to-back reads (thepssyscall bumps kernel time while the total rounds unchanged). It now asserts total CPU time (user + kernel, which maps to the monotonicpsTIME) is nondecreasing.Testing
All five
unix.yamlVM jobs pass, exercising the refactored code on real FreeBSD, OpenBSD, DragonFly, and NetBSD systems (plus OpenIndiana). Local spotless / checkstyle / forbidden-APIs / javadoc and a clean full-reactor build also pass.Summary by CodeRabbit
Bug Fixes
New Features
Refactor
Tests