Repository navigation
Mark the API and util packages, and the modules, for nullability - #3618
Conversation
|
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 (38)
📜 Recent review details⏰ Context from checks skipped due to timeout. (11)
🧰 Additional context used📓 Path-based instructions (4)**/*.{java,properties}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (6)📚 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-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-03-29T20:01:01.877ZApplied to files:
🔇 Additional comments (38)
📝 WalkthroughWalkthroughThe PR integrates JSpecify nullability across OSHI modules and packages. It adds explicit nullable contracts, updates affected tests, and configures Error Prone and NullAway analysis. ChangesJSpecify nullability rollout
Estimated code review effort: 3 (Moderate) | ~20 minutes Merge Risk: ⚪ Minimal · up to This PR adds nullability coverage and related build/test corrections without any identified merge-blocking risk; it is merge-ready after normal checks and review. 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3618 +/- ##
============================================
- Coverage 79.99% 79.96% -0.03%
- Complexity 3864 4224 +360
============================================
Files 696 696
Lines 24219 24219
Branches 3997 3997
============================================
- Hits 19373 19367 -6
- Misses 2720 2728 +8
+ Partials 2126 2124 -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:
|
Establishes the end state for #3593 across oshi-common, oshi-core and oshi-core-ffm. NullAway runs at WARN until the backlog it reports is drained, following the precedent set for the SLF4J check in #3597; it goes back to ERROR once the count reaches zero. Two mechanisms, aimed at what each can actually reach. A package annotation is the only one every consumer sees: a JDK 8 user has no module system at all, and a JDK 9+ user on the classpath does not resolve module annotations either. So the packages a caller touches are annotated individually -- those holding @publicapi types, and the whole oshi.util tree, which callers do sometimes reach for. Everything below that line is per-OS implementation, abstract bases and drivers, which the project already documents as not meant for outside use; those are covered by @NullMarked on the module declaration, which exists to let us check our own code and needs no per-package upkeep as packages are added. The native mapping packages are opted out with @NullUnmarked. The struct and library bindings under oshi.jna and oshi.ffm.platform describe someone else's memory layout rather than our contracts, and are already exempt from the javadoc rules for the same reason. Their utility packages, oshi.jna.util and oshi.ffm.util, are not opted out. oshi-common and oshi-core compile their sources at release 8, which predates JPMS and therefore excludes module-info.java, leaving the module annotation invisible to NullAway. Under -Perror-prone only, they now compile at release 9 with module-info.java included. The released jars are unchanged, still built at release 8. oshi-core and oshi-core-ffm gain the jspecify dependency and a requires static clause, since oshi-common declares it optional and it is therefore not transitive. -Xmaxerrs joins the -Xmaxwarns that #3597 set. NullAway reports at ERROR once the backlog is drained, and javac caps errors at 100 by default just as silently as warnings: a survey of oshi-common reported exactly 100 findings until this was set, against a real 288. Marking oshi.driver.common.windows.wmi showed WmiResult.getValue declaring a non-null return that every caller in WmiUtil immediately null-checks, so a WMI row without the property was already returning null through a signature that promised otherwise. NetBsdCentralProcessor.parseCpTime likewise null-checks the argument it declared non-null. Both are annotated now. Two tests asserted on a map lookup without checking it was present, and one called main(null).
1a881a7 to
a78cba1
Compare
* Resolve the Windows registry package's nullability findings Adds PerfCounterValues, giving the two performance-data classes typed lookups into their property maps. HkeyPerformanceDataUtil.getCounterIndices returns null unless it resolved an index for every constant of the counter enum, so the maps are all-or-nothing and a missing key means the data was assembled inconsistently rather than that a counter is optional. The accessors say so, naming the property instead of failing later with a bare NullPointerException, and the call sites lose their casts. Annotates the returns that were already documented as nullable: getCounterIndices, RegistryValueUtil.registryValueToString, and the four buildXxxMap methods, plus registryValueToLong's argument, which it null-checks. * Make the driver package's nullability contracts honest Clears oshi.driver.common, the first group of the backlog left at WARN by #3618. oshi-common goes from 306 warnings to 229; one finding remains in DxgiUtil, which belongs with the GPU group. The two performance-data classes gain PerfCounterValues, a set of typed lookups into their property maps. HkeyPerformanceDataUtil.getCounterIndices returns null unless it resolved an index for every constant of the counter enum, so the maps are all-or-nothing and a missing key means the data was assembled inconsistently rather than that a counter is optional. The accessors say so, naming the property instead of failing later with a bare NullPointerException, and the call sites lose their casts. Three contracts were wrong rather than merely unstated. PdhCounterProperty .getInstance returns the PDH instance filter, which the enum constants for counters without one set to null literally; the interface and PerfCounter now say so. Lscfg documents that its model, serial and version may each be absent and returns them in a tuple; the tuple type parameters now permit that. The psinfo readers on Solaris and AIX return null when the process is gone. The tuple classes therefore declare their type parameters as extending @nullable Object. This permits a nullable element without requiring one, and is forced by oshi.util.tuples being marked: its type variables otherwise default to non-null, which no caller storing an absent value can satisfy. Lspv reads three maps it fills together and its comment notes they share keys; that is now expressed rather than assumed. AixBaseboard and the Solaris process and thread classes follow the drivers they call, as do the JNA and FFM forwarding twins of the performance-data classes. Making these honest surfaces 25 warnings in oshi-core and oshi-core-ffm, in the Windows registry and operating system stack. Resolving them here would mean editing nine more files and changing an abstract signature in the operating system group, so they are left for the group that covers those modules; the warning count tracks them. * Preserve the nullable result through the memoized Solaris queries CodeRabbit review of #3619. SolarisOSProcess.getPsInfo documented returning null when the psinfo could not be read, but declared otherwise, and the suppliers feeding it were typed non-null despite memoizing a query that returns null for a process that has exited. Memoizer's type parameter now extends @nullable Object. It holds whatever the supplier produces, and a memoized nullable value is otherwise silently absorbed by the type variable, which is why this was not reported. PsInfoJNA.queryArgsEnv and queryArgsEnvAddrs receive that value and both already open by checking it for null; they now say so. * Say in the javadoc that the psinfo argument may be absent CodeRabbit review of #3619. Both methods accept a null psinfo and check for it, but their parameter descriptions still said "a populated SolarisPsInfo". queryArgsEnv's return also needed a word: unlike queryArgsEnvAddrs, which documents returning null, it always returns a pair and reports failure as empty collections. queryArgsEnvAddrs's @return already documented its null, so it is unchanged.
Fourth group of the backlog #3618 left at WARN. Takes oshi-common from 172 warnings to 158 and clears the GPU classes; the reactor drops 568 to 554 with nothing newly surfaced. Two of these describe themselves. LinuxGpuStats caches the NVML device id in a field commented "null means not yet resolved, empty string means unavailable", which is three states in a type that admitted two. findDrmInfo documents "the PCI slot address, or null to use first-match" on both overloads, and is passed as a Function whose input the callers may not know. The rest follow: WindowsGpuStats' two lazily populated caches, MacGpuStats' sampler, which is null when the IOReport subscription could not be created and which the constructor already checks and logs, and DxgiUtil.findMatch with its JNA forwarder. LinuxGraphicsCard and its native-free subclass are here rather than with the peripherals group, because they share findDrmInfo and the DRM lookup function with the GpuStats classes; splitting them would mean deciding one contract in two places.
* Make the operating system layer's nullability contracts honest 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. * Match the overrides in the Windows JNA and FFM implementations 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.
* Make CentralProcessor's nullability contracts honest Sixth group of the backlog #3618 left at WARN. Takes oshi-common from 103 warnings to 59 and clears CentralProcessor across all eight platform implementations. initProcessorCounts returns a quartet whose physical processor and cache lists several platforms cannot discover: AIX and Solaris pass null for one or both outright, and the BSDs pass a value that may be absent. The abstract signature now says so. processTickData took sixteen counter lists and null-checked all of them, but the check for the ten utility counters sat inside the USE_CPU_UTILITY branch, which the analyzer cannot correlate with the same flag being read later. That guard also discarded the whole sample: with the utility counters enabled but any one of them unavailable, it returned all-zero ticks, throwing away the five raw counters that had been read successfully. The utility counters now refine the raw ticks when they are all present, and are skipped when they are not. Windows lazily initializes its NUMA node map and utility multiplier. The map now starts empty rather than null, following AbstractOSThread and the process attributes in the previous group, and the capacity tick supplier, which only exists when the utility counters are in use, is checked where it is read. The rest were documented but unstated: the cpuid and IORegistry readers, the per-core property pairs on Apple Silicon whose compatible and cluster-type values are read separately and may each be absent, the BSD cache string parser, and the udev enumeration that returns null when udev is unavailable. * Do not give the NUMA map a field initializer CodeRabbit review of #3623. AbstractCentralProcessor's constructor calls initProcessorCounts, and the Windows implementations populate the NUMA node map from there. A field initializer on the subclass runs after the superclass constructor, so the empty map added in the previous commit overwrote the map that had just been built. On a NUMA machine every NUMA-qualified counter instance would then fail to resolve, and processTickData would skip it and report zero ticks. The field carries no initializer now. It is genuinely null until that virtual call assigns it, so it says so, and the getter substitutes an empty map for readers.
* Make the system identity classes' nullability contracts honest Seventh group of the backlog #3618 left at WARN. Takes oshi-common from 59 warnings to 19 and clears ComputerSystem, Baseboard and Firmware across every platform. Only the peripherals group remains. These classes read manufacturer, model, serial number, UUID and firmware version from whatever the platform will say: dmidecode, lshw, lsattr, smbios, the IORegistry, WMI. Each of those may report nothing, and each class carries the values in a tuple or a small holder whose fields were declared non-null. The public getters must not change: Baseboard.getManufacturer and its neighbours are @publicapi and promise a value. They returned the tuple element straight through, so a platform that reported nothing returned null through that promise. They now report Constants.UNKNOWN, which is what the rest of the API does for a value it could not read. Solaris asked smbTypesMap for three sections that the smbios output need not contain, then dereferenced the results, and built the map with a get().put() that assumed the section already existed. Both go through getOrDefault/computeIfAbsent now. MacBaseboard and MacComputerSystem spell out the blank test for the manufacturer they default to "Apple Inc.", since Util.isBlank is a predicate the analyzer cannot see through. * Address review: drop annotations the normalization makes unreachable - LsattrStrings normalizes every field through getStringValueOrUnknown in its constructor, so the fields and accessors cannot be null. The @nullable stays on the constructor parameters, which are the raw parsed values. - FreeBsdComputerSystem.readDmiDecode likewise normalizes every component before returning, so the memoized Quintet's type arguments are non-null and the getters' getStringValueOrUnknown wrappers were redundant. parseDmiDecode keeps its nullable component types; it is the raw parse. - MacBaseboard.decodeProperty duplicated what ParseUtil.decodeNulTerminated already does: it accepts a null array and returns an empty string. The call sites test the result with isBlank or getStringValueOrUnknown, which treat null and empty alike, so calling ParseUtil directly is equivalent.
NullAway has run at WARN since #3618 so the backlog it exposed could be drained without blocking the build. That backlog is now zero across oshi-common, oshi-core and oshi-core-ffm, so the check moves to ERROR and a signature that contradicts its annotations fails the build rather than adding to a list. Verified by building the whole reactor under -Perror-prone with the flip in place: zero findings, BUILD SUCCESS. Updates the two pom comments that still described this as groundwork for annotations that had not landed, and the FAQ, which claimed only oshi.hardware and oshi.software.os were marked and that a violation fails CI - the first was out of date and the second was not true while the check ran at WARN. Re-summarizes the CHANGELOG for the whole arc as one entry: what was adopted, then what the sweep fixed, then the user-facing behavior changes as a list. One pull request link per line, for readability of the raw markdown.
Establishes the end state for #3593 across
oshi-common,oshi-coreandoshi-core-ffm, then leaves NullAway at WARN while the backlog it reports is drained. It returns to ERROR once the count reaches zero — the same approach #3597 took with the SLF4J check, which spent a release cycle at WARN while its 74 sites were fixed.Nothing here changes behavior. The two bug fixes described at the end were found by the marking.
Two mechanisms, each aimed at what it can reach
A package annotation is the only one every consumer sees. A JDK 8 user has no module system at all, and a JDK 9+ user on the classpath does not resolve module annotations either — those are only observed when the jar is on the module path. So the split is by audience rather than by convenience:
@PublicApitypes —oshi,oshi.hardware,oshi.software.os,oshi.util,oshi.spi,oshi.annotation,oshi.ffm@NullMarkedonpackage-info.javaoshi.utiltree, which callers do sometimes reach for@NullMarkedonpackage-info.java@NullMarkedonmodule-info.javaThe second group is what the project already documents as not meant for outside use. Marking it at the module level exists so we can check our own code, and it needs no upkeep as packages are added — which is the one real weakness of per-package marking.
The native mappings are opted out
@NullUnmarkedonoshi.jna,oshi.jna.common,oshi.jna.platform.*,oshi.ffm.commonandoshi.ffm.platform.*. Those describe someone else's memory layout rather than our contracts, and are already exempt from the javadoc rules for the same reason.Their utility packages are not opted out:
oshi.jna.utilandoshi.ffm.util.*follow the rules like any other code, andoshi.jna.util.SysctlUtilJNAduly reports findings.Build changes this needs
oshi-commonandoshi-corecompile at release 9 under-Perror-proneonly. Their sources target release 8, which predates JPMS and therefore excludesmodule-info.javafrom the compilation — so NullAway never sees the module annotation and marking the module does nothing. Under this profile the whole module compiles at release 9 withmodule-info.javaincluded. The released jars are unchanged, still built at release 8 by the default profile, and every test job still compiles at release 8, so a Java 9+ API would still fail there.oshi-coreandoshi-core-ffmgain the jspecify dependency andrequires static org.jspecify, sinceoshi-commondeclares itoptionaland it is therefore not transitive.-Xmaxerrsjoins the-Xmaxwarnsthat #3597 set. NullAway reports at ERROR once the backlog is drained, and javac caps errors at 100 by default just as silently as it caps warnings. This is not hypothetical: a survey ofoshi-commonreported exactly 100 findings until this was set, against a real 288.Two false contracts the marking exposed
WmiResult.getValuedeclared a non-null return that every caller already distrusted. All four call sites inWmiUtildoObject o = result.getValue(...); if (o == null) {...}. A WMI row that does not carry the requested property returns null through a signature promising otherwise, so the null check was load-bearing and the signature was wrong.NetBsdCentralProcessor.parseCpTimeopens withif (cpTimeStr == null || cpTimeStr.isEmpty())on a parameter it declared non-null.Two tests also asserted on a map lookup without checking the key was present — a miss would have failed with a
NullPointerExceptionrather than naming the key — and one calledmain(null)where an empty array says the same thing.Where the backlog stands
682 warnings:
oshi-common306,oshi-core-ffm219,oshi-core157; 648 in main sources and 34 in tests. Largest clusters areoshi.driver.common.windows.registry54,oshi.ffm.util.gpu38,oshi.hardware.common.platform.windows31,oshi.hardware.common.platform.mac24,oshi.util.gpu24.oshi-demohas nomodule-info.javaand is left alone for now.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 -DskipTestsover the whole reactor building successfully at WARN.Note the
cleanon that last command. Without it Maven finds the classes up to date, skips recompilation, and Error Prone reports success having analysed nothing.Summary by CodeRabbit