Repository navigation
Consolidate sysctl utilities into shared helpers and fix int-width sysctl misread (#3517) - #3518
Conversation
The command-line `sysctl -n` implementation was duplicated in three places: oshi-common's NetBsdSysctlUtil, and the "Backup versions" blocks of the JNA OpenBsdSysctlUtil and FFM OpenBsdSysctlUtilFFM. Move the oshi-common NetBsdSysctlUtil to a generic oshi.util.common.platform.unix.bsd.BsdSysctlUtil (usable by any BSD-family OS incl. macOS) and delete the two OpenBSD duplicates. Repoint all command-line String call sites (7 NetBSD, 5 OpenBSD JNA, 5 OpenBSD FFM) to the shared class. The int[]/MIB and Memory/MemorySegment native overloads remain in their platform-specific util classes. Add BsdSysctlUtilTest exercising success and failure paths of all three overloads, enabled on every platform that ships a sysctl command (gated via a PlatformEnum helper), giving the shared class full coverage. Remove the now-redundant command-line tests from OpenBsdSysctlUtilFFMTest.
The four JNA sysctl utility classes (mac SysctlUtil, FreeBSD BsdSysctlUtil, NetBsd/OpenBsd SysctlUtil) each carried a near-identical copy of the buffer-sizing, error-logging, and result-decoding logic; the only real difference was the native call itself — sysctlbyname(String) on mac/FreeBSD vs sysctl(int[]) on NetBSD/OpenBSD, both declared on the shared CLibrary interface. Introduce oshi.jna.util.SysctlUtilJNA which owns that shared logic. Each per-platform class now supplies its native call as a SysctlCall lambda and delegates. Log level (WARN vs ERROR) and the mac logWarning variants are preserved via parameters. Two correctness fixes folded into the shared long helper while extracting: - Read int-width OIDs at their real size. Some OIDs exposed via the long API are kernel ints (e.g. FreeBSD hw.clockrate is a 4-byte int). The kernel writes only 4 bytes into the 8-byte buffer; getLong(0) then reads 4 valid + 4 uninitialized bytes (new Memory() is not zeroed), yielding garbage like 6.2 EHz for the CPU vendor frequency. sysctl reports the bytes written via oldlenp, so read getInt (zero-extended, unsigned) when 4 bytes were written and getLong otherwise. Latent pre-existing bug. - Log the MIB as Arrays.toString(name) on NetBSD/OpenBSD instead of the raw int[] (default Object.toString, e.g. "[I@1a2b3c"), matching FFM. Extraction plus these fixes changes only the JNA side, so the JNA/FFM comparison tests (-Paggregate-coverage) validate it against the unchanged FFM implementations.
Mirror the JNA extraction on the FFM side. The three FFM sysctl utility classes (mac SysctlUtilFFM, FreeBSD BsdSysctlUtilFFM, OpenBSD OpenBsdSysctlUtilFFM) each repeated the same arena management, buffer sizing, and result decoding; the only difference was the native call — sysctlbyname(String) on mac/FreeBSD vs sysctl(int[]) on OpenBSD. Introduce oshi.ffm.util.SysctlFFM which owns that shared logic. Each per-platform class keeps a small private method that allocates its name/MIB segment, invokes its native function, and logs any errno, passed to the helper as a SysctlOp lambda. The mac-only sysctl(int[], MemorySegment) buffer variant (different return shape) is left in place. The shared long helper reads int-width OIDs at their real size (getInt when the kernel wrote 4 bytes, zero-extended), matching the JNA fix. FFM was not observably affected (arena.allocate zero-fills, so an over-wide read was already unsigned-correct), but honoring oldlenp keeps the two implementations symmetric and robust. Committed after the JNA extraction so the JNA/FFM comparison tests (-Paggregate-coverage) exercise the FFM change against the already-refactored JNA side.
Assert that the processor's vendor-advertised frequency and max frequency, when both are known (> 0), are within an order of magnitude of each other. Both describe the same CPU, so a large divergence indicates a corrupted native read. This directly reproduces the hw.clockrate int-as-long bug fixed earlier in this branch: before the fix, FreeBSD reported a vendor frequency of ~6.2 EHz against a ~2.6 GHz max (~9 orders of magnitude apart), which this test would have caught. Runs on every platform in CI via the live CentralProcessorTest.
📝 WalkthroughWalkthroughThe change consolidates BSD sysctl utilities, adds shared FFM and JNA result handlers, updates NetBSD and OpenBSD consumers, handles int-width values through long APIs, exports the common BSD package, and adds sysctl and processor-frequency tests. ChangesBSD sysctl consolidation
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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.
🧹 Nitpick comments (1)
oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java (1)
86-100: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winConsider a direct unit test for the 4-byte widening branch.
A test using a stub
SysctlCallthat writes only 4 bytes into the 8-byte buffer (and setsoldlenpaccordingly) would directly validate the#3517fix without depending on platform-specific sysctl output.🤖 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/jna/util/SysctlUtilJNA.java` around lines 86 - 100, Add a focused unit test for the sysctl method’s 4-byte widening branch, using a stub SysctlCall that writes a 4-byte value to the buffer and sets the provided size reference to INT_SIZE. Assert that sysctl returns the expected unsigned widened value, without relying on platform-specific sysctl behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java`:
- Around line 86-100: Add a focused unit test for the sysctl method’s 4-byte
widening branch, using a stub SysctlCall that writes a 4-byte value to the
buffer and sets the provided size reference to INT_SIZE. Assert that sysctl
returns the expected unsigned widened value, without relying on
platform-specific sysctl behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 4cc1b3df-9887-4528-bc36-70c7511d8e76
📒 Files selected for processing (34)
CHANGELOG.mdoshi-common/src/main/java/module-info.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.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/util/common/platform/unix/bsd/BsdSysctlUtil.javaoshi-common/src/main/java/oshi/util/common/platform/unix/bsd/package-info.javaoshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtilTest.javaoshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SysctlUtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/freebsd/BsdSysctlUtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.javaoshi-core-ffm/src/test/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFMTest.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.javaoshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.javaoshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.javaoshi-core/src/main/java/oshi/util/platform/unix/freebsd/BsdSysctlUtil.javaoshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.javaoshi-core/src/main/java/oshi/util/platform/unix/openbsd/OpenBsdSysctlUtil.javaoshi-core/src/test/java/oshi/hardware/platform/shared/CentralProcessorTest.java
💤 Files with no reviewable changes (1)
- oshi-core-ffm/src/test/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFMTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
- GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
- GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
- GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (4)
📚 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/openbsd/OpenBsdHWDiskStoreJNA.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.javaoshi-common/src/main/java/oshi/util/common/platform/unix/bsd/package-info.javaoshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemFFM.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryFFM.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.javaoshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.javaoshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.javaoshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.javaoshi-core/src/main/java/oshi/util/platform/unix/openbsd/OpenBsdSysctlUtil.javaoshi-core/src/main/java/oshi/util/platform/unix/freebsd/BsdSysctlUtil.javaoshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SysctlUtilFFM.javaoshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/freebsd/BsdSysctlUtilFFM.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/module-info.javaoshi-common/src/main/java/oshi/util/common/platform/unix/bsd/package-info.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.javaoshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
🔇 Additional comments (34)
oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java (1)
5-21: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdGlobalMemory.java (1)
17-17: LGTM!Also applies to: 67-71
oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.java (1)
20-20: LGTM!Also applies to: 154-164
oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOperatingSystem.java (1)
22-22: LGTM!Also applies to: 38-40
oshi-common/src/test/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtilTest.java (1)
1-78: LGTM!oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorFFM.java (1)
24-24: LGTM!Also applies to: 36-41
oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemFFM.java (1)
18-18: LGTM!Also applies to: 62-78
oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryFFM.java (1)
21-21: LGTM!Also applies to: 50-55
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java (1)
9-9: LGTM!Also applies to: 20-20
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdCentralProcessorJNA.java (1)
17-17: LGTM!Also applies to: 28-34
oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java (1)
9-9: LGTM!Also applies to: 20-20
oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/package-info.java (1)
1-9: LGTM!oshi-common/src/main/java/module-info.java (1)
61-61: LGTM!oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java (1)
14-14: LGTM!Also applies to: 34-59, 71-71
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdComputerSystem.java (1)
17-17: LGTM!Also applies to: 61-78
oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdHWDiskStore.java (1)
23-23: LGTM!Also applies to: 52-52
oshi-core/src/main/java/oshi/jna/util/SysctlUtilJNA.java (2)
86-100: Correct fix for the reported width bug.Reading only the kernel-reported byte count (
size.longValue()) and explicitly zero-extending 4-byte results viaParseUtil.unsignedIntToLongcorrectly resolves the FreeBSDhw.clockrate-style bug from#3517, independent of whatever garbage bytes may exist in the unwritten portion of the malloc'd buffer.
64-75: LGTM!Also applies to: 112-132, 144-179
oshi-core/src/main/java/oshi/util/platform/mac/SysctlUtil.java (1)
2-17: LGTM!Also applies to: 25-28, 50-52, 63-65, 88-90, 101-103, 114-116
oshi-core/src/main/java/oshi/util/platform/unix/freebsd/BsdSysctlUtil.java (1)
2-17: LGTM!Also applies to: 26-26, 38-40, 51-53, 64-66, 77-79, 90-92
oshi-core/src/main/java/oshi/util/platform/unix/netbsd/NetBsdSysctlUtil.java (1)
7-33: LGTM!Also applies to: 64-66, 77-79, 90-92, 103-105, 116-118
oshi-core/src/main/java/oshi/util/platform/unix/openbsd/OpenBsdSysctlUtil.java (1)
7-30: LGTM!Based on learnings, this class lives in an implementation-detail subpackage rather than the root public API (
oshi,oshi.hardware,oshi.software.os), so removing the legacy command-line-based overloads here is not a public API break.Also applies to: 39-43, 52-56, 65-69, 78-82, 91-94
Source: Learnings
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdComputerSystemJNA.java (1)
18-18: LGTM!Also applies to: 62-78
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdGlobalMemoryJNA.java (1)
20-20: LGTM!Also applies to: 52-57
oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (1)
43-43: LGTM!Also applies to: 113-115, 125-125, 157-157
oshi-common/src/test/java/module-info.test (1)
61-62: LGTM!CHANGELOG.md (1)
10-10: LGTM!oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java (1)
1-167: LGTM!oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SysctlUtilFFM.java (1)
11-11: LGTM!Also applies to: 23-23, 58-59, 70-71, 94-95, 106-107, 118-118, 144-148
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/freebsd/BsdSysctlUtilFFM.java (1)
18-18: LGTM!Also applies to: 44-44, 55-55, 66-66, 77-77, 87-98
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/openbsd/OpenBsdSysctlUtilFFM.java (1)
20-20: LGTM!Also applies to: 46-47, 58-59, 70-71, 82-83, 93-105
oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreFFM.java (1)
13-13: LGTM!Also applies to: 32-32
oshi-core/src/main/java/oshi/hardware/platform/unix/openbsd/OpenBsdHWDiskStoreJNA.java (1)
13-13: LGTM!Also applies to: 32-32
oshi-core/src/test/java/oshi/hardware/platform/shared/CentralProcessorTest.java (1)
15-15: LGTM!Also applies to: 77-90
) SolarisCentralProcessorJNA.queryProcessorId2() (the Kstat2 path) read clock_MHz and passed it straight to ProcessorIdentifier as the vendor frequency, omitting the * 1_000_000L conversion to Hz that both the non-Kstat2 path in the same class and the FFM implementation apply. On a SPARC system this reported a ~5067 Hz vendor frequency against a ~5.07 GHz max. Caught by the CentralProcessorTest.testVendorFreqSanity() assertion added in #3518 (vendor and max frequency must be within an order of magnitude).
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3518 +/- ##
============================================
+ Coverage 78.16% 78.24% +0.07%
- Complexity 76 3720 +3644
============================================
Files 694 697 +3
Lines 24251 24104 -147
Branches 4029 3994 -35
============================================
- Hits 18957 18861 -96
+ Misses 3078 3046 -32
+ Partials 2216 2197 -19
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:
|
Summary
Consolidates the duplicated
sysctlutility code into three shared helpers and fixes a latent bug the consolidation surfaced.Before this change the
sysctllogic was copied across eight classes: the command-linesysctl -nimplementation existed in three places, and the JNA and FFM native bodies were near-identical per key-type (sysctlbyname(String)for macOS/FreeBSD,sysctl(int[])for NetBSD/OpenBSD), differing only in which nativeINSTANCE/function was called.Changes
Command-line (
oshi-common) — Move the NetBSD-specific command-lineNetBsdSysctlUtilto a genericoshi.util.common.platform.unix.bsd.BsdSysctlUtil(usable by any BSD-family OS, including macOS) and repoint all command-line call sites: the 7 NetBSD common classes, and the "backup"Stringoverloads of the JNAOpenBsdSysctlUtiland FFMOpenBsdSysctlUtilFFM(which duplicated it). Three copies → one.JNA (
oshi-core) — Extract the shared buffer-sizing/error/decoding logic intooshi.jna.util.SysctlUtilJNA; each per-platform class supplies its native call as a lambda. Preserves per-method log levels and the macOSlogWarningvariants.FFM (
oshi-core-ffm) — Mirror the extraction intooshi.ffm.util.SysctlFFM, using the existingcallInArena*helpers.Bug fix (closes JNA sysctl(name, long) reads uninitialized bytes for int-width OIDs (FreeBSD hw.clockrate -> 6.2 EHz) #3517) — The shared
longhelper now honors the byte count the kernel reports viaoldlenp: when the OID is a 4-byte int (e.g. FreeBSDhw.clockrate) it reads aParseUtil.unsignedIntToLongwidenedintrather thangetLongover a buffer whose high 4 bytes were never written. Previouslynew Memory()(unzeroed, unlike an FFM arena) left those bytes asmallocgarbage, intermittently reporting an absurd CPU vendor frequency (e.g. 6.2 EHz). Applied to both JNA and FFM for symmetry. ACentralProcessorTestassertion that vendor and max frequency stay within an order of magnitude reproduces the bug and guards against regressions on every platform.Also fixes a minor latent issue: the NetBSD/OpenBSD JNA classes logged the raw
int[]MIB ([I@...) on failure; they now logArrays.toString, matching FFM.Testing
BsdSysctlUtilTestcovers the shared command-line class (success + failure paths of all overloads), gated to platforms that ship asysctlcommand.CentralProcessorTest.testVendorFreqSanity()reproduces JNA sysctl(name, long) reads uninitialized bytes for int-width OIDs (FreeBSD hw.clockrate -> 6.2 EHz) #3517.NativeComparisonTest(-Paggregate-coverage).Closes #3517.
Summary by CodeRabbit
Bug Fixes
Improvements
Tests