Repository navigation
Make the GPU vendor utilities' nullability contracts honest - #3626
Conversation
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (13)
📜 Recent review details⏰ Context from checks skipped due to timeout. (7)
🧰 Additional context used📓 Path-based instructions (4)**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{java,xml,md}📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (8)📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-07-30T00:35:22.638ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-08-03T00:46:14.953ZApplied to files:
📚 Learning: 2026-08-15T14:25:48.170ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-04-11T05:51:49.185ZApplied to files:
🔇 Additional comments (24)
📝 WalkthroughWalkthroughThe 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. ChangesGPU nullability contracts
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to 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
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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 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
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:
|
…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.
First step of draining
oshi-coreandoshi-core-ffm, now thatoshi-commonis at zero. Covers theNVML 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/NvmlLibraryin the JNA holders, and the ten ADLMethodHandles 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
@Nullableandread into a local that is checked at its use site, so the guarantee the
AVAILABLE/LIBRARY_LOADEDflag 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 guardscannot fire in practice. The alternative —
@SuppressWarnings("NullAway.Init")— was considered andrejected: it would leave a future dereference that forgets the guard unchecked, on exactly the path
where an NPE is nastiest.
Contract marking
findDevice,findDeviceByName,readBusIds,readName,acquireHandleByBusId/ByName, and the ADL adapter enumeration — now say so.@Nullabledevice identifier, which is whatNvmlQuery.queryhas always accepted and answered with its sentinel. This is what closes the
getVramTotal(findDevice(...))chain end to end.DxgiUtil.normalizeNameandregistryValueToVramtake a@Nullableargument, as their javadoc andtheir own tests already assert.
One twin inconsistency
WindowsGpuStatsdeclarednvmlFindDeviceandnvmlFindDeviceByNamenon-null while itsLinuxGpuStatstwin declared both@Nullable— a miss from #3621. The two now agree; the Windowscaller already null-checked both results, so this is a declaration fix only.
Scope boundary
MacGpuStatsandWindowsGraphicsCardJNAstill carry three findings each. They are IOKit/IOReportand 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:javadocplus-Perror-prone clean install. All modules green, 1561tests, 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
Refactor