Skip to content

Make the GPU vendor utilities' nullability contracts honest - #3626

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:jspecify-gpu-util
Aug 15, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:jspecify-gpu-util

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

First step of draining oshi-core and oshi-core-ffm, now that oshi-common is at zero. Covers the
NVML and ADL vendor libraries and the DXGI helpers — the densest cluster left, 62 findings in 4 files.
Reactor findings 406 → 341.

The library handles

The vendor library handles — AdlLibrary/NvmlLibrary in the JNA holders, and the ten ADL
MethodHandles plus the malloc stub in the FFM twin — are null whenever the library failed to load,
which is the normal case on a machine without that vendor's GPU. Each is now declared @Nullable and
read into a local that is checked at its use site, so the guarantee the AVAILABLE / LIBRARY_LOADED
flag carries is one the analyzer can see.

No reachable behavior change. Every call site was already downstream of that flag, or of an
adlInit() / nvmlInit() that returns successfully only when the library loaded, so the new guards
cannot fire in practice. The alternative — @SuppressWarnings("NullAway.Init") — was considered and
rejected: it would leave a future dereference that forgets the guard unchecked, on exactly the path
where an NPE is nastiest.

Contract marking

  • The lookups that report "no such device" with null — findDevice, findDeviceByName, readBusIds,
    readName, acquireHandleByBusId/ByName, and the ADL adapter enumeration — now say so.
  • The metric getters they feed take a @Nullable device identifier, which is what NvmlQuery.query
    has always accepted and answered with its sentinel. This is what closes the
    getVramTotal(findDevice(...)) chain end to end.
  • DxgiUtil.normalizeName and registryValueToVram take a @Nullable argument, as their javadoc and
    their own tests already assert.

One twin inconsistency

WindowsGpuStats declared nvmlFindDevice and nvmlFindDeviceByName non-null while its
LinuxGpuStats twin declared both @Nullable — a miss from #3621. The two now agree; the Windows
caller already null-checked both results, so this is a declaration fix only.

Scope boundary

MacGpuStats and WindowsGraphicsCardJNA still carry three findings each. They are IOKit/IOReport
and WMI code rather than vendor-library code, so they belong to the macOS and Windows PRs rather than
being decided twice here.

No CHANGELOG entry: no user-visible behavior changed. Verified by diffing against master and
cancelling every line whose only difference is an annotation — ten of the thirteen files have no
residue at all, and the residue in the other three is the field-to-local hoist and its guard.

Verified with the full gate on macOS: spotless:apply sortpom:sort checkstyle:check install forbiddenapis:check javadoc:javadoc plus -Perror-prone clean install. All modules green, 1561
tests, 0 failures. Neither vendor library is present on this machine, so the ADL and NVML paths are
unverified beyond compilation.

Part of #3593.

Summary by CodeRabbit

  • Bug Fixes

    • Improved GPU monitoring reliability when optional vendor libraries or native handles are unavailable.
    • Prevented null-related failures during GPU discovery and metric collection.
    • Preserved existing fallback values when GPU information cannot be retrieved.
  • Refactor

    • Clarified nullable GPU identifiers and lookup results across supported platforms, improving API safety and tooling guidance.

First step of draining oshi-core and oshi-core-ffm, covering the NVML and ADL
vendor libraries and the DXGI helpers. Reactor findings 406 -> 341.

The vendor library handles — AdlLibrary/NvmlLibrary in the JNA holders, and the
ten ADL MethodHandles plus the malloc stub in the FFM twin — are null whenever
the library failed to load, which is the normal case on a machine without that
vendor's GPU. Each is now declared @nullable and read into a local that is
checked at its use site, so the guarantee the AVAILABLE/LIBRARY_LOADED flag
carries is one the analyzer can see. No reachable behavior changes: every call
site was already downstream of that flag, or of an adlInit()/nvmlInit() that
returns only when the library loaded, so the new guards cannot fire in practice.

The rest is contract marking. The lookups that report "no such device" with null
— findDevice, findDeviceByName, readBusIds, readName, acquireHandle*, and the
ADL adapter enumeration — say so, and the metric getters they feed take a
@nullable device identifier, which is what NvmlQuery.query has always accepted
and answered with its sentinel. DxgiUtil.normalizeName and registryValueToVram
take a @nullable argument, as their javadoc and their own tests already assert.

WindowsGpuStats declared nvmlFindDevice and nvmlFindDeviceByName non-null while
its LinuxGpuStats twin declared both @nullable; the two now agree, and the
Windows caller already null-checked both results.

Part of #3593.
@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: ea61bf81-cd1f-4b1f-9340-efde16645a19

📥 Commits

Reviewing files that changed from the base of the PR and between c950727 and 8668b37.

📒 Files selected for processing (13)
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/util/common/gpu/NvmlQuery.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Error Prone
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Analyze (java)
🧰 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-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-common/src/main/java/oshi/util/common/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.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/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
**/*.{java,xml,md}

📄 CodeRabbit inference engine (AGENTS.md)

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

Files:

  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-common/src/main/java/oshi/util/common/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.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/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
🧠 Learnings (8)
📚 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-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-common/src/main/java/oshi/util/common/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.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-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-common/src/main/java/oshi/util/common/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.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/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.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-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-common/src/main/java/oshi/util/common/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.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-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsFFM.java
  • oshi-common/src/main/java/oshi/util/common/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java
  • oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
  • oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.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/util/common/gpu/NvmlQuery.java
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java
  • oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsGpuStatsJNA.java
📚 Learning: 2026-04-11T05:51:49.185Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3139
File: oshi-core-java25/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java:36-58
Timestamp: 2026-04-11T05:51:49.185Z
Learning: For OSHI Linux GPU stats implementations (e.g., LinuxGpuStats and its LinuxGpuStatsJNA/LinuxGpuStatsFFM subclasses), treat NVML "nvml*" methods (such as nvmlGetVramUsed, nvmlGetCoreClockMhz, nvmlGetMemoryClockMhz, nvmlGetTemperature, nvmlGetPowerDraw, nvmlGetFanSpeedPercent) as having a documented failure sentinel: they are contractually expected to return -1 (long/double) on failure. The base class/implementations should use guards like `if (val >= 0)` before consuming NVML results and should fall back to sysfs/hwmon paths when the value is negative. In review, do not flag subclass pass-through of the -1 sentinel as a missing clamp/contract violation; only flag issues if the -1 sentinel is altered or NVML failure results are used without the expected `>= 0` guard or fallback behavior.

Applied to files:

  • oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxGpuStatsFFM.java
🔇 Additional comments (24)
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java (3)

21-21: LGTM!

Also applies to: 148-148, 164-164, 179-179, 200-200, 215-215


331-331: LGTM!

Also applies to: 351-351, 383-383


393-395: LGTM!

Also applies to: 397-404, 414-414, 424-424, 434-434, 444-444, 454-454, 464-464

oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java (6)

14-14: LGTM!

Also applies to: 58-58


113-117: LGTM!

Also applies to: 130-133, 149-160, 176-182, 196-202


214-214: LGTM!

Also applies to: 240-240, 262-262


300-380: LGTM!


413-413: LGTM!

Also applies to: 438-438, 473-475


477-486: LGTM!

Also applies to: 488-497, 499-508, 510-519, 521-530, 532-541, 543-552, 554-561

oshi-common/src/main/java/oshi/driver/common/windows/gpu/DxgiUtil.java (1)

64-67: LGTM!

Also applies to: 90-90

oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsGpuStats.java (1)

103-111: LGTM!

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

78-78: LGTM!

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

7-8: LGTM!

Also applies to: 29-36

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

10-11: LGTM!

Also applies to: 55-62

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

7-8: LGTM!

Also applies to: 29-36

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

10-11: LGTM!

Also applies to: 55-62

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

14-14: LGTM!

Also applies to: 241-241

oshi-core/src/main/java/oshi/util/gpu/DxgiUtilJNA.java (1)

54-54: LGTM!

Also applies to: 64-64

oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java (3)

28-28: LGTM!

Also applies to: 75-87


175-182: LGTM!

Also applies to: 187-195, 205-207, 235-243, 262-262, 289-291


348-350: LGTM!

Also applies to: 362-362, 381-383, 395-395, 432-434, 448-448, 465-467, 479-479

oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java (3)

13-13: LGTM!

Also applies to: 55-61


112-118: LGTM!

Also applies to: 133-136, 165-171, 182-182, 203-205


262-272: LGTM!

Also applies to: 293-303, 344-346, 356-356, 375-385


📝 Walkthrough

Walkthrough

The PR adds JSpecify nullability contracts across GPU utilities and lookup methods. JNA and FFM ADL/NVML implementations now guard unavailable native bindings and preserve existing fallback values.

Changes

GPU nullability contracts

Layer / File(s) Summary
Shared and platform nullability contracts
oshi-common/src/main/java/oshi/..., oshi-core/src/main/java/oshi/hardware/..., oshi-core-ffm/src/main/java/oshi/hardware/...
DXGI inputs, NVML identifiers, and GPU lookup results now declare their existing nullable behavior.
ADL native binding guards
oshi-core/src/main/java/oshi/util/gpu/AdlUtilJNA.java, oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
ADL calls now validate local native bindings and return existing failure values when bindings are unavailable.
FFM NVML nullable flow
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/NvmlUtilFFM.java
FFM NVML lookup and metric APIs accept nullable identifiers and annotate nullable intermediate results.
JNA NVML null-safe calls
oshi-core/src/main/java/oshi/util/gpu/NvmlUtilJNA.java
JNA NVML calls guard unavailable library handles and preserve existing metric sentinel handling.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 8668b

This PR clarifies nullable GPU-library and helper contracts while preserving existing behavior; all stated checks pass, so no actionable merge-blocking risk remains beyond normal review.

Possibly related PRs

  • oshi/oshi#3089: Introduces the GPU utility APIs and native implementations updated here.
  • oshi/oshi#3542: Modifies overlapping NvmlQuery and NVML device identifier handling.
  • oshi/oshi#3621: Updates overlapping GPU nullability contracts.

Poem

A rabbit checks each native call,
No missing handle makes it fall.
Null IDs pass through clear and bright,
Sentinels guard the metrics right.
Hop, hop—GPU types now agree!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.86% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: correcting nullability contracts across GPU vendor utilities.
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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.99%. Comparing base (c950727) to head (8668b37).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3626      +/-   ##
============================================
- Coverage     80.03%   79.99%   -0.05%     
  Complexity     3861     3861              
============================================
  Files           697      697              
  Lines         24262    24262              
  Branches       4000     4000              
============================================
- Hits          19418    19408      -10     
- Misses         2713     2721       +8     
- Partials       2131     2133       +2     
Flag Coverage Δ
linux 37.70% <ø> (+<0.01%) ⬆️
macos 38.55% <ø> (-0.04%) ⬇️
windows 45.33% <ø> (ø)

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 1ca26f4 into oshi:master Aug 15, 2026
29 of 31 checks passed
@dbwiddis
dbwiddis deleted the jspecify-gpu-util branch August 15, 2026 14:58
dbwiddis added a commit that referenced this pull request Aug 15, 2026
…racts honest (#3632)

Seventh step of draining oshi-core and oshi-core-ffm, and the last macOS group.
Covers the hardware components and the operating-system layer in both
implementations, including the MacGpuStats twins deferred from #3626.

As with the macOS utilities, most of this is declarations catching up with
documentation. The IO registry views report an absent parent, an exhausted
iterator or a card with no accelerator entry by returning null, and each already
said so - MacGpuStats.queryPerfStats even carries a paragraph explaining why
null and an empty map are different answers there, because getTemperature
latches a card as having no sensor only when the dictionary was present. The
display synthesis, the medium-type traversal and the localized display name
report failure the same way, as does getProcess for a process that is not
running, which OperatingSystem has always declared @nullable.

Two contracts were stated in a way the analyzer reads differently from a reader:

- IOKitProvider.withMatchingService returns null when no service matches,
  whatever T is, and its extractor may itself report an absent property with
  null. Declaring <T extends @nullable Object> T said neither; it is now
  <T> @nullable T taking a Function<RegistryEntry, @nullable T>.
- RegistryEntry.lookupControllerVidPid returns a two-element array whose
  elements may each be absent - @nullable String[] - not a nullable array.

MacCentralProcessor.platformExpert tested its result with Util.isBlank, which
the analyzer cannot see through; the explicit null-or-empty check is the same
test it performs.

Part of #3593.
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