Skip to content

Resolve the nullness conditions Sonar reported after the jSpecify sweep - #3637

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:sonar-nullness
Aug 15, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:sonar-nullness

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

Sonar's java:S2589 and java:S2583 flagged 25 conditions whose result the declared nullability
makes constant — the fallout of the jSpecify arc finally giving Sonar contracts to reason about. They
are not one category: half are dead tests, half are declarations that were wrong. The remedy differs,
so each was checked individually.

The value really can be null — the test was right, the declaration wrong

  • ForeignFunctions.downcall treats a null resLayout as "void return", and Kernel32FFM,
    Wtsapi32FFM, BStrFFM and Ole32FFM all pass one. NullAway never saw this: those callers
    live in the native mapping packages, which we deliberately marked @NullUnmarked, so the literal
    null was never checked against the declaration. Sonar reads the declaration itself and caught
    what our own configuration had blinded us to. That single finding justifies the sweep.
  • Passing null as callInArenaOrDefault's default makes the result nullable, but the type
    argument was inferred from the lambda's non-null return, so the declared type of each local said
    otherwise. The locals now say @Nullable and inference follows. Same for the local receiving
    WindowsDisplayFFM's byte @Nullable [] EDID read. This is also the root of the S4449 batch,
    which reported the same mismatch from the argument side.
  • readPropertiesFromClassLoader can be handed the context class loader, which may be null.
  • ParseUtil's hex parsers and Lpstat's line parsers are documented to fail soft on the malformed
    input real system output produces, so their arguments are annotated rather than their guards
    deleted — removing the guards would have been a behavior change.

The value cannot be null — the test was dead

  • FileUtil.readAllBytes returns an empty array, never null, which readAllBytesAsBuffer
    inherited while its javadoc still promised null. That one stale contract explains eight of the
    findings — PsInfo ×4, NetBsdOSProcess, both DragonFly OSProcess twins, and DrmEdid.
  • ExecutingCommand.getFirstAnswer returns an empty string, so the BSD sysctl overload that supplies
    a default cannot yield null.
  • OSFileStore.getLogicalVolume and getOptions are non-null API.
  • OperatingSystem.getCurrentProcess is documented never to return null and substitutes a stub, so
    WindowsOperatingSystemFFM's guard was unreachable. Removing it also matches the JNA twin,
    which never had one.

No behavior change, and no CHANGELOG entry

Every deleted test was unreachable and every added annotation widens a contract. Verified by
cancelling the annotation-only lines from the diff against master: the remainder is exactly those
deletions, nothing else.

Full gate on macOS: spotless:apply sortpom:sort spotless:check checkstyle:check install forbiddenapis:check javadoc:javadoc plus -Perror-prone clean install — all modules green, 1565
tests, 0 failures, and NullAway still reports zero findings now that it runs at ERROR.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of empty or unavailable system data across Solaris, NetBSD, BSD, Linux, Windows, and DragonFly BSD platforms.
    • Prevented null-related parsing failures when processing hexadecimal values, printer information, hostnames, display data, and process arguments.
    • Improved filesystem, power-source, network, and native system-call fallback behavior.
    • Corrected Windows current-thread handling when process information is unavailable.
  • Documentation

    • Clarified behavior when files cannot be read.

Sonar's S2589 and S2583 flagged 25 conditions whose result the declared
nullability makes constant. They split into two kinds, and the remedy differs:

The value really can be null, so the test was right and the declaration wrong:

- ForeignFunctions.downcall treats a null resLayout as "void return", and
  Kernel32FFM, Wtsapi32FFM, BStrFFM and Ole32FFM all pass one. NullAway never
  saw this: those callers live in the native mapping packages, which are
  deliberately @NullUnmarked, so the literal null was never checked against the
  declaration. Sonar reads the declaration itself and caught it.
- Passing null as callInArenaOrDefault's default makes the result nullable, but
  the type argument was inferred from the lambda's non-null return, so each
  local now says @nullable and the inference follows. Same for the local
  receiving WindowsDisplayFFM's byte @nullable [] EDID read.
- readPropertiesFromClassLoader can be handed the context class loader, which
  may be null.
- ParseUtil's hex parsers and Lpstat's line parsers are documented to fail soft
  on the malformed input real system output produces, so their arguments are
  annotated rather than their guards removed.

The value cannot be null, so the test was dead:

- FileUtil.readAllBytes returns an empty array, never null, which its
  readAllBytesAsBuffer wrapper inherited while its javadoc still promised null.
  That one contract explains eight of the findings, in PsInfo, NetBsdOSProcess,
  both DragonFly OSProcess twins and DrmEdid.
- ExecutingCommand.getFirstAnswer returns an empty string, so the BSD sysctl
  overload that supplies a default cannot yield null.
- OSFileStore.getLogicalVolume and getOptions are non-null API.
- OperatingSystem.getCurrentProcess is documented never to return null and
  substitutes a stub, so WindowsOperatingSystemFFM's guard was unreachable.
  Removing it also matches the JNA twin, which never had one.

No behavior change: every deleted test was unreachable, and every added
annotation widens a contract. Verified by cancelling the annotation-only lines
from the diff - the remainder is exactly those deletions.
@coderabbitai

coderabbitai Bot commented Aug 15, 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 Plus

Run ID: 6013cb25-a4bc-4932-8edc-52a1eefbfd2b

📥 Commits

Reviewing files that changed from the base of the PR and between 6128729 and cbecc48.

📒 Files selected for processing (18)
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
💤 Files with no reviewable changes (1)
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (9)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
🧰 Additional context used
📓 Path-based instructions (4)
**/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

**/src/main/java/**/*.java: Before writing any parsing helper, check whether ParseUtil already has one.
Do not use fully-qualified class names in
code or in javadoc — including inside {@link ...}. Import the type and link the simple name.
Every public and protected type and method needs javadoc.
New files get a current-year-only
header (Copyright 2026 The OSHI Project Contributors / SPDX-License-Identifier: MIT)
new classes are
expected to declare one
Do not reach for @Nullable to make a null return legal: the convention is a sentinel, not a
null

System calls are expensive, and callers poll. Values that are constant (CPU model,
serial number) or expensive-but-slow-changing are wrapped in
oshi.util.Memoizer.memoize(supplier, ...)

Files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
oshi-common/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-common/src/main/java/**/*.java: oshi-common may not reference com.sun.jna.**, java.lang.foreign.**, or any
System.load/loadLibrary. It must stay pure JDK.

Files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
**/*.{java,xml,md}

📄 CodeRabbit inference engine (AGENTS.md)

Do not commit generated output, target/, or IDE files.

Files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
oshi-core-ffm/src/main/java/**/*.java

📄 CodeRabbit inference engine (AGENTS.md)

oshi-core-ffm may not reference com.sun.jna.**.

Files:

  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
🧠 Learnings (10)
📚 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/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.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-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
📚 Learning: 2026-07-30T00:35:22.638Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3547
File: oshi-common/src/main/java/oshi/hardware/common/platform/unix/BsdFirmware.java:82-82
Timestamp: 2026-07-30T00:35:22.638Z
Learning: In OSHI, treat changes as “API-breaking” only when they affect classes (or relevant API surface) annotated with `PublicAPI`. Public classes/members that are not annotated with `PublicAPI` should be reviewed as internal implementation details, even if they are public (e.g., classes like `oshi.hardware.common.platform.unix.BsdFirmware`). Also, respect intentional visibility decisions used for tests—e.g., methods like `BsdFirmware.parseDmesg(List<String>)` may be intentionally package-private to support tests within the same package; avoid widening visibility or altering signatures unless the related `PublicAPI` contract requires it.

Applied to files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
📚 Learning: 2026-08-03T00:46:14.953Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3566
File: oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdNetworkParams.java:18-22
Timestamp: 2026-08-03T00:46:14.953Z
Learning: In the OSHI Java codebase, do not require duplicate Javadoc on public methods annotated with Override when the inherited Javadoc from the parent declaration adequately documents the method. The general public-member Javadoc requirement should not flag these overrides solely because they lack redundant documentation.

Applied to files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
📚 Learning: 2026-08-15T14:25:48.170Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3625
File: oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxNetworkIF.java:65-69
Timestamp: 2026-08-15T14:25:48.170Z
Learning: In OSHI Java code, treat `oshi.util.Util.isBlank(String)` as equivalent to `value == null || value.isEmpty()`: it does not consider whitespace-only strings blank. Do not report a behavior change when code replaces `!Util.isBlank(value)` with the equivalent `value != null && !value.isEmpty()` condition.

Applied to files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.java
📚 Learning: 2026-08-15T15:43:29.296Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3628
File: oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.java:108-108
Timestamp: 2026-08-15T15:43:29.296Z
Learning: In the OSHI Java codebase, use the sentinel-over-null convention at public API boundaries. Private helpers may return an explicitly JSpecify-annotated nullable value when the caller handles the missing result clearly and locally; callers must check for null before accessing the result. For example, methods such as lookupAccountBySid(String) may return String Nullable [] when queryUserSessions() performs the required null check.

Applied to files:

  • oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java
  • oshi-common/src/main/java/oshi/util/SystemInfoHelper.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java
  • oshi-common/src/main/java/oshi/util/FileUtil.java
  • oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java
  • oshi-common/src/main/java/oshi/util/ParseUtil.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
  • oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java
  • oshi-common/src/main/java/oshi/driver/common/unix/solaris/PsInfo.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
📚 Learning: 2026-08-02T23:56:23.866Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3565
File: oshi-core-ffm/src/main/java/oshi/ffm/platform/unix/PosixLibcFunctions.java:51-56
Timestamp: 2026-08-02T23:56:23.866Z
Learning: For Java FFM bindings in the oshi-core-ffm module, assume a 64-bit JVM and 64-bit operating system. Do not flag 32-bit native ABI or memory-layout compatibility concerns, consistent with the project's JDK 25 support policy, unless that policy changes.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java
📚 Learning: 2026-08-15T15:59:20.875Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3629
File: oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsPowerSourceFFM.java:75-75
Timestamp: 2026-08-15T15:59:20.875Z
Learning: For OSHI backend twin classes whose filenames end in JNA.java or FFM.java, do not flag missing Javadoc on public forwarding constructors when config/checkstyle-suppressions.xml exempts them. Treat the documented abstract parent constructor as the contract location and avoid requiring duplicate Javadoc for the forwarded parameters.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.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/DragonFlyBsdOSProcessJNA.java
🔇 Additional comments (17)
oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java (1)

587-595: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxPowerSourceFFM.java (1)

18-18: LGTM!

Also applies to: 55-56

oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java (1)

81-84: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxNetworkParamsFFM.java (1)

15-15: LGTM!

Also applies to: 34-42, 54-78

oshi-core-ffm/src/main/java/oshi/software/os/mac/MacNetworkParamsFFM.java (1)

24-24: LGTM!

Also applies to: 86-94

oshi-common/src/main/java/oshi/util/FileUtil.java (1)

196-196: LGTM!

Also applies to: 398-400

oshi-common/src/main/java/oshi/util/ParseUtil.java (1)

1302-1303: LGTM!

Also applies to: 1325-1326

oshi-common/src/main/java/oshi/util/driver/unix/Lpstat.java (1)

12-12: LGTM!

Also applies to: 156-159, 179-182, 193-196

oshi-common/src/main/java/oshi/util/common/platform/unix/bsd/BsdSysctlUtil.java (1)

54-58: LGTM!

oshi-common/src/main/java/oshi/util/SystemInfoHelper.java (1)

399-399: LGTM!

oshi-common/src/main/java/oshi/util/driver/linux/DrmEdid.java (1)

61-64: LGTM!

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

44-49: LGTM!

Also applies to: 69-71, 88-90, 108-110

oshi-common/src/main/java/oshi/hardware/common/platform/unix/netbsd/NetBsdCentralProcessor.java (1)

63-64: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java (1)

93-97: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java (1)

51-55: LGTM!

oshi-core/src/main/java/oshi/software/os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java (1)

42-46: LGTM!

oshi-metrics/src/main/java/oshi/metrics/FileSystemMetrics.java (1)

7-7: LGTM!

Also applies to: 63-64


📝 Walkthrough

Walkthrough

The PR aligns nullability annotations and runtime checks across utility, Unix platform, FFM, Windows, and metrics code. It removes redundant null checks, documents empty-buffer behavior, and supports nullable FFM return layouts.

Changes

Nullability contract cleanup

Layer / File(s) Summary
Utility nullability contracts
oshi-common/src/main/java/oshi/util/..., oshi-common/src/main/java/oshi/util/common/..., oshi-common/src/main/java/oshi/util/driver/...
Utility documentation and method parameters now describe nullable values. Hex parsing preserves default returns for null input. Several checks now use empty-value semantics.
Unix platform query checks
oshi-common/src/main/java/oshi/driver/..., oshi-common/src/main/java/oshi/hardware/..., oshi-common/src/main/java/oshi/software/..., oshi-core/src/main/java/..., oshi-metrics/src/main/java/...
Solaris, NetBSD, and DragonFly BSD query paths remove redundant null checks. Filesystem mode parsing also assumes non-null options.
FFM nullability and process handling
oshi-core-ffm/src/main/java/oshi/ffm/..., oshi-core-ffm/src/main/java/oshi/hardware/..., oshi-core-ffm/src/main/java/oshi/software/...
FFM results and locals receive @Nullable annotations. downcall supports void descriptors when the return layout is null. Windows current-thread lookup removes its null-process fallback.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to cbecc

This PR narrows nullability contracts and removes unreachable checks without changing intended runtime behavior; no actionable merge-blocking risk remains after normal checks and review.

Possibly related PRs

  • oshi/oshi#3583: Establishes the non-null getCurrentProcess() behavior used by the Windows FFM change.
  • oshi/oshi#3614: Continues the same JSpecify nullability rollout across utility and platform code.
  • oshi/oshi#3619: Modifies the Solaris PsInfo nullability contract in the same methods.

Poem

A rabbit checks each buffer bright,
And marks null paths in gentle light.
FFM calls now know their shape,
Empty results need no escape.
@Nullable hops across the code—
Clean contracts lighten every load.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 53.33% 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 summarizes the PR's main purpose: resolving Sonar nullness findings after the jSpecify sweep.
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.
✨ 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.

@codecov

codecov Bot commented Aug 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 30.76923% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.93%. Comparing base (6128729) to head (cbecc48).

Files with missing lines Patch % Lines
...n/java/oshi/driver/common/unix/solaris/PsInfo.java 25.00% 0 Missing and 3 partials ⚠️
...n/platform/unix/netbsd/NetBsdCentralProcessor.java 0.00% 1 Missing ⚠️
...oftware/common/os/unix/netbsd/NetBsdOSProcess.java 0.00% 1 Missing ⚠️
...mmon/src/main/java/oshi/util/SystemInfoHelper.java 0.00% 0 Missing and 1 partial ⚠️
.../src/main/java/oshi/util/driver/linux/DrmEdid.java 0.00% 0 Missing and 1 partial ⚠️
...os/unix/dragonflybsd/DragonFlyBsdOSProcessFFM.java 0.00% 1 Missing ⚠️
...os/unix/dragonflybsd/DragonFlyBsdOSProcessJNA.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             master    #3637     +/-   ##
===========================================
  Coverage     79.92%   79.93%             
+ Complexity     4101      199   -3902     
===========================================
  Files           697      697             
  Lines         24292    24289      -3     
  Branches       4012     4010      -2     
===========================================
  Hits          19415    19415             
- Misses         2730     2735      +5     
+ Partials       2147     2139      -8     
Flag Coverage Δ
freebsd 33.50% <7.69%> (+<0.01%) ⬆️
linux 37.67% <0.00%> (-0.02%) ⬇️
macos 38.54% <15.38%> (-0.04%) ⬇️
openbsd 32.68% <7.69%> (-0.01%) ⬇️
solaris 34.24% <15.38%> (+0.04%) ⬆️
windows 45.30% <7.69%> (-0.01%) ⬇️

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.

@dbwiddis
dbwiddis merged commit c9d9924 into oshi:master Aug 15, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the sonar-nullness branch August 16, 2026 22:29
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