Repository navigation
Resolve the nullness conditions Sonar reported after the jSpecify sweep - #3637
Conversation
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.
|
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 (18)
💤 Files with no reviewable changes (1)
📜 Recent review details⏰ Context from checks skipped due to timeout. (9)
🧰 Additional context used📓 Path-based instructions (4)**/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.{java,xml,md}📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/src/main/java/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (10)📚 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-15T14:25:48.170ZApplied to files:
📚 Learning: 2026-08-15T15:43:29.296ZApplied to files:
📚 Learning: 2026-04-12T19:34:56.879ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-08-15T15:59:20.875ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (17)
📝 WalkthroughWalkthroughThe 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. ChangesNullability contract cleanup
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to 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
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 #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
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:
|
Sonar's
java:S2589andjava:S2583flagged 25 conditions whose result the declared nullabilitymakes 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.downcalltreats a nullresLayoutas "void return", andKernel32FFM,Wtsapi32FFM,BStrFFMandOle32FFMall pass one. NullAway never saw this: those callerslive in the native mapping packages, which we deliberately marked
@NullUnmarked, so the literalnullwas never checked against the declaration. Sonar reads the declaration itself and caughtwhat our own configuration had blinded us to. That single finding justifies the sweep.
nullascallInArenaOrDefault's default makes the result nullable, but the typeargument was inferred from the lambda's non-null return, so the declared type of each local said
otherwise. The locals now say
@Nullableand inference follows. Same for the local receivingWindowsDisplayFFM'sbyte @Nullable []EDID read. This is also the root of theS4449batch,which reported the same mismatch from the argument side.
readPropertiesFromClassLoadercan be handed the context class loader, which may be null.ParseUtil's hex parsers andLpstat's line parsers are documented to fail soft on the malformedinput 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.readAllBytesreturns an empty array, never null, whichreadAllBytesAsBufferinherited while its javadoc still promised null. That one stale contract explains eight of the
findings —
PsInfo×4,NetBsdOSProcess, both DragonFlyOSProcesstwins, andDrmEdid.ExecutingCommand.getFirstAnswerreturns an empty string, so the BSD sysctl overload that suppliesa default cannot yield null.
OSFileStore.getLogicalVolumeandgetOptionsare non-null API.OperatingSystem.getCurrentProcessis documented never to return null and substitutes a stub, soWindowsOperatingSystemFFM'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:javadocplus-Perror-prone clean install— all modules green, 1565tests, 0 failures, and NullAway still reports zero findings now that it runs at
ERROR.Summary by CodeRabbit
Bug Fixes
Documentation