Repository navigation
Make the operating system layer's nullability contracts honest - #3622
Conversation
Fifth group of the backlog #3618 left at WARN. Takes oshi-common from 158 warnings to 103 and clears oshi.software.common. Eighteen process attribute fields now start as empty strings rather than null. They are populated by updateAttributes, which LinuxOSProcess and MacOSProcess call from their constructors but the AbstractProcOSProcess, BsdOSProcess and SolarisOSProcess hierarchies do not, so the window between construction and the first update was real for some callers and merely unprovable for the rest. AbstractOSThread already declared its name this way; the rest now match. A getter that reached a field early returned null through a signature promising otherwise, and returns an empty string now. Five overrides repeat an annotation their interface already carries, because an override cannot narrow a parameter: the filter and sort of the three process listing methods, and the prior snapshot of the two getXxxCpuLoadBetweenTicks methods. getProcess(int) is annotated in five implementations of the interface that has documented returning null for a process that is not running since #3614. The rest were documented but unstated: the release-file readers on Linux, the plist readers on macOS, the ps output columns on the BSDs, and the file store lookups whose name argument is null to mean "match everything". BsdOSProcess and BsdOSThread read a ps column that may be missing, which previously threw from charAt(0) partway through an update; an absent state column now falls through to OTHER, leaving the rest of the update intact.
The abstract signatures in WindowsOperatingSystem and WindowsOSProcess now declare the pid collection, thread map, perf counter block and WTS info as optional, and an override cannot narrow a parameter, so the implementations repeat the annotation. Only the override mismatches are addressed. The forwarding calls and returns those signatures surface in the same files belong to the group that covers oshi-core and oshi-core-ffm.
|
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 (28)
📜 Recent review details⏰ Context from checks skipped due to timeout. (9)
🧰 Additional context used📓 Path-based instructions (3)**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (7)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-07-06T19:25:59.225ZApplied to files:
📚 Learning: 2026-07-30T00:35:22.638ZApplied to files:
📚 Learning: 2026-08-03T00:46:14.953ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-08-15T03:54:58.500ZApplied to files:
🔇 Additional comments (29)
📝 WalkthroughWalkthroughThe pull request adds JSpecify ChangesNullability rollout
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk: 🔵 Low · up to Windows process thread details may still have an inaccurate nullability contract when no thread map is available, which could cause misleading API guarantees or follow-up static-check work. The change remains mergeable with explicit owner awareness. Possibly related issues
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❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3622 +/- ##
============================================
- Coverage 80.07% 79.98% -0.09%
+ Complexity 3868 200 -3668
============================================
Files 697 697
Lines 24231 24252 +21
Branches 3999 4001 +2
============================================
- Hits 19402 19398 -4
- Misses 2715 2724 +9
- Partials 2114 2130 +16
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:
|
…st (#3628) * Make the Windows registry and WMI drivers' nullability contracts honest Third step of draining oshi-core and oshi-core-ffm, covering the registry, WMI and performance-data drivers in both implementations. Reactor findings 292 -> 253. ApplicationInfo's getters each document an empty string for a value the platform did not report, but the constructor stored what it was given, so a Windows application whose registry key omits DisplayVersion or Publisher reached callers with null from getVersion() or getVendor(). The constructor now normalizes all three strings, which also makes the call-site normalization added for macOS in #3622 redundant rather than load-bearing. The rest is contract marking. The performance-data readers that return null on a failed registry read say so, as do HkeyUserDataFFM's account lookup and the registry readers behind the installed-application list. The optional arguments are annotated: the WMI process-id filter, the perf-counter process name, and the counter text array that is null when the registry read failed. Three lookups into maps the surrounding code has already proved complete are read through defaults instead: the counter offset and size maps, which are filled in one loop from the same key, so an absent offset now falls into the existing unusable-size branch rather than throwing; the window z-order map, which the line above populates when absent; and the counter index map, whose absent entry now logs and returns null instead of throwing inside a synchronized read. None is reachable. Two more instance-filter expressions tested a nullable argument with Util.isBlank, which the analyzer cannot see through, and are rewritten as the null-or-empty check that method performs. Also raises two Windows comparison-test tolerances that measure the wall-clock gap between two process-data collections rather than anything about the values. Both overran their floor by a hair on recent runs - 1267 against 1200 in RegistryComparisonTest, 579 against 564 in NativeComparisonTest, where the floor had never governed because the 10%-of-uptime term is computed from a JVM only a few seconds old. Both floors are now 1500ms. The uptime derivation itself is unchanged by this arc: the registry path still takes its reference time from the perf-data triplet and the perf-counter path from currentTimeMillis. Part of #3593. * Address review: correct two contracts the annotations left half-stated - The uptime-tolerance comment blamed memoization, but setUp sets the memoizer expiration to 0, so what the tolerance covers is only the cost of two sequential collections. Says so now. - Win32Process.buildWmiClassNameWithPidFilter null-checks its argument and its javadoc documents null, but the parameter did not say so; queryCommandLines already passes a @nullable set straight into it. - HkeyPerformanceDataUtilFFM's javadoc did not mention the null return its annotation declares, while the JNA twin's already did. - Documents the null pidsToQuery contract on both queryCommandLines twins.
* Make the remaining Unix and FFM nullability contracts honest Tenth and last step of draining oshi-core and oshi-core-ffm. Covers AIX, FreeBSD, NetBSD, OpenBSD, the sysctl and foreign-function utilities, and the handful of leftovers elsewhere. The reactor now reports zero NullAway findings. Most of it is the familiar shape: a query that reports "no such entry" or "the native call failed" with null, whose abstract declaration in oshi-common already documented it - the AIX disk and interface stats, the AIX TCP and UDP stats, the FreeBSD and OpenBSD host and domain names, and the FreeBSD CPU tick arrays. The sysctl families needed the contract stated once at the bottom. Both the JNA and FFM helpers pass a null buffer on the first call to ask only for the size, and return null when the call fails; the per-platform wrappers hand that result straight back. Annotating the two call interfaces and the wrappers propagated through every BSD and macOS caller. Four things worth calling out: - ForeignFunctions' three pointer readers are documented as returning null for a null pointer, and getByteArrayFromNativePointer needed the array form of the annotation - byte @nullable [] - since a byte cannot itself be null. - The logging varargs are @nullable Object... through both ForeignFunctions and ExceptionUtil, because the values being reported are often the very lookup arguments that were null. - ParseUtil's two byte-array parsers were left non-null on purpose. They dereference the array immediately, so annotating them would have declared a contract they do not honor; the FreeBSD FFM caller checks its own read instead. - NativeHandle.get() is @nullable, as its javadoc has always said, and close() reads the handle into a local so the isNull() guard is one the analyzer can follow. Its three consumers check the value they were already relying on. The one suppression in the arc is on NativeHandleTest.testNullCloserThrows, which passes null for a @nonnull parameter deliberately: rejecting it is what the test asserts. Part of #3593. * Add the missing tests, and fix a null check that missed the NULL segment Tests for the behavior this arc changed, which several of its commits altered without covering: - ForeignFunctions' three raw pointer readers, for a null pointer, for MemorySegment.NULL, and - so the guards cannot quietly cost the readers their job - a round trip through a real segment. Writing these showed the three pointer parameters were declared non-null while every body tests for null and every javadoc documents it, so they are annotated now. - FreeBsdNetworkParams.getDomainName, which converts the resolver's null to the empty string its interface promises. - ApplicationInfo's constructor, which normalizes an absent name, version or vendor. That was changed in #3628 and went out untested. - BsdOSProcess with a ps row missing its STATE column, which used to throw partway through updateAttributes. Changed in #3622, also untested. Lspv's skip of a volume with no type or partition count stays untested: the maps it reads are filled together from one lspv run, so the path is unreachable through the public parser without adding a seam for its own sake. Review fixes: - MacNetworkParamsFFM and WindowsOSProcessFFM tested the handle for null but not for the NULL segment, which NativeHandle.isNull() covers and which a failed getaddrinfo or OpenProcessToken produces. They now test both, written against the local so the analyzer can still follow it. - queryProcesses documents its null pid filter on both twins, matching queryCommandLines. - FreeBsdNetworkParams.queryDomainName's javadoc claimed subclasses return an empty string on failure; they return null, which is what its annotation says. - The FreeBSD FFM stat suppliers hold a nullable segment.
Fifth group of the backlog #3618 left at WARN, following #3619, #3620 and #3621. Takes
oshi-commonfrom 158 warnings to 103 and clearsoshi.software.common.Eighteen process attribute fields now start empty rather than null
AbstractOSProcess.name, and the user, group, id, working directory and command-line-backup fields onMacOSProcess,AbstractProcOSProcess,BsdOSProcessandLinuxOSProcess, are populated byupdateAttributesrather than by a constructor.Whether that leaves a window depends on the subclass:
LinuxOSProcessandMacOSProcesscallupdateAttributesfrom their constructors, while theAbstractProcOSProcess,BsdOSProcessandSolarisOSProcesshierarchies do not. So the gap is real for some callers and merely unprovable for the rest, and either way a getter reaching a field early returnednullthrough a signature promising otherwise.AbstractOSThreadalready declaredprotected volatile String name = "";. The rest now match it, which is a defensive guard rather than a new convention.A real failure on the BSDs
BsdOSProcess.updateAttributesread thepsstate column aspsMap.get(BsdPsKeyword.STATE).charAt(0), andBsdOSThreaddid the same. Apsvariant that does not emit that column would throw partway through the update, leaving the process or thread object half-populated with no indication why. An absent state column now falls through toOTHERand the rest of the update completes.Five overrides repeat what their interface already says
An override cannot narrow a parameter, so these restate an annotation the API has carried since #3614: the
filterandsortarguments of the three process listing methods, and the prior snapshot ofgetProcessCpuLoadBetweenTicksandgetThreadCpuLoadBetweenTicks.getProcess(int)is annotated in five implementations.OperatingSystem.getProcess(int)has documented returningnullfor a process that is not running since #3614, so those signatures had been contradicting the interface.The rest were documented but unstated
The release-file readers on Linux (
readOsRelease,readLsbRelease,execLsbRelease,readDistribRelease), the plist readers on macOS, thepsoutput columns on the BSDs, and thegetFileStoreMatchingimplementations whose name argument isnullto mean "match everything".queryStatvfsandqueryContextSwitchesreturnlong @Nullable []— note the annotation goes after the type for an array, since@Nullable long[]would annotate the element type instead.Scope
The second commit matches the overrides in
WindowsOperatingSystemandWindowsOSProcess's JNA and FFM implementations, since the abstract signatures changed here. The forwarding calls and returns those same signatures surface in those files are left for the group that coversoshi-coreandoshi-core-ffm; the reactor total drops 554 to 505.Verification
Full gate green locally on macOS/JDK 25:
./mvnw clean spotless:apply sortpom:sort checkstyle:check install forbiddenapis:check javadoc:javadoc, 1561 tests passing, plus./mvnw -Perror-prone clean install -DskipTestsbuilding successfully across the reactor.Summary by CodeRabbit