Repository navigation
Finish the two findings the previous round did not clear - #3639
Conversation
Both survived #3638, and re-reading them after the scans refreshed showed why. WindowsGpuStats: the safe-publication finding was on cachedAdlIndex, not the adjacent cachedNvmlDevice I made volatile. I inferred which field the reported line held instead of counting, and fixed the wrong one; the finding simply moved down with it. cachedAdlIndex and prevUtilTicks are both written after construction on a @threadsafe class and are volatile now. closed is not, and does not need to be: its only accessors are synchronized. Making prevUtilTicks volatile also has to fix how it is read. The old code tested it for null and then dereferenced it, two reads of a field another thread can write between; it now reads once into a local, which removes the race as well as the visibility gap. NetBsdCentralProcessor: the possessive quantifiers did not satisfy S8786 - Sonar still reported backtracking on a pattern that by definition does none. Rather than argue with it, the pattern turned out to be unnecessary. The call site trims both halves of the split immediately afterwards, so matching the surrounding whitespace achieved nothing that the trim did not; splitting on a plain "=" is equivalent, takes the JDK's single-character fast path rather than the regex engine, and leaves nothing for the rule to report. parseCpTime's tests cover real sysctl output and are unchanged.
|
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 (2)
📜 Recent review details⏰ Context from checks skipped due to timeout. (12)
🧰 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:
**/*.{java,xml,md}📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (7)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-12T19:34:56.879ZApplied 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:
🔇 Additional comments (3)
📝 WalkthroughWalkthroughThe PR simplifies NetBSD CPU time key/value parsing and updates Windows GPU statistics for cross-thread field visibility. GPU utilization now snapshots previous ticks locally before calculating deltas. ChangesNetBSD CPU time parsing
Windows GPU state visibility
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The PR makes localized fixes to GPU statistics publication and NetBSD key-value parsing; no actionable merge-blocking risk remains after normal checks and review. Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 #3639 +/- ##
============================================
- Coverage 79.98% 79.93% -0.06%
+ Complexity 4109 203 -3906
============================================
Files 697 697
Lines 24292 24291 -1
Branches 4012 4012
============================================
- Hits 19430 19416 -14
- Misses 2724 2736 +12
- Partials 2138 2139 +1
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:
|
Making prevUtilTicks volatile in #3639 traded a CodeQL safe-publication finding for a Sonar one: S3077 objects that volatile alone does not make a non-primitive field thread-safe. That is true in general and not here. GpuTicks is @immutable, a final class whose two long fields are final, so a reader either sees the old reference or a fully constructed new one; there is no partially published state for volatile to fail to protect. Suppressed the way SmcKeyCache's volatile list already is, with the same reason.
Everything sat under "Bug Fixes and Improvements", which put the release's headline change in the wrong place and left one entry carrying three different kinds of change at once. New Features: the JSpecify adoption, rewritten to lead with what a consumer gets rather than what the sweep did to the build, and ParseUtil's new getStringValueOrEmpty, which was a clause in the middle of that paragraph. Behavior Changes: the null-to-sentinel list, promoted out of its sub-bullet. Someone whose code tests those getters for null now has dead branches, and that was the least visible thing in the section. #3616 moves here from Bug Fixes, being the same kind of change. Removals: #3608's 14 WMI forwarding shims, Util.isBlankOrUnknown and ParseUtil.slash, with a note that they sit outside the semver-guaranteed API and are listed only because removing them can break a compile. Bug Fixes and Improvements keeps #3589 and #3611/#3612, gains the hardening work split out of the JSpecify entry, and gains #3639, which had no entry at all: the Windows GPU utilization path tested its cached tick sample for null and then dereferenced it in a second read, so a concurrent poll could throw. Dependency bumps get no entries; none changed anything user-visible.
Both of these survived #3638. Re-reading them once the Sonar and Code Quality scans refreshed on
current master showed why — and in one case the reason was my own mistake.
WindowsGpuStats— I fixed the wrong fieldThe
java/safe-publicationfinding was oncachedAdlIndex, not the adjacentcachedNvmlDeviceImade volatile in #3638. I inferred which field the reported line number held rather than counting it,
so the finding just moved down one line with my change.
cachedAdlIndexandprevUtilTicksare both written after construction on a@ThreadSafeclass, andare volatile now.
closedis not, and does not need to be — its only accessors aresynchronized,which is why CodeQL never flagged it.
Making
prevUtilTicksvolatile also required fixing how it is read. The old code tested it for nulland then dereferenced it — two reads of a field another thread can write in between:
It now reads once into a local, which removes the race as well as the visibility gap.
NetBsdCentralProcessor— the regex was unnecessary, not just unluckyThe possessive quantifiers from #3638 did not satisfy
java:S8786; Sonar still reportedbacktracking on a pattern that by definition does none. Rather than argue with the rule, I looked at
the call site again:
Both halves are trimmed immediately afterwards, so matching the surrounding whitespace in the pattern
achieved nothing the trim did not. Splitting on a plain
"="is equivalent, takes the JDK'ssingle-character fast path rather than the regex engine, and leaves nothing for the rule to report.
The
Patternconstant and its import are gone.parseCpTime's tests cover realsysctloutput —user = 2930, nice = 42, sys = 1334, ...withasserted tick values — and are unchanged.
After this
Sonar should hold at the 5 known false positives; Code Quality at the 2 informational findings you
have been dismissing (
ParseUtil's overload pair and the deliberately unreadUdevprobe).Full gate on macOS:
spotless:apply spotless:check checkstyle:check install forbiddenapis:check javadoc:javadocplus-Perror-prone clean install— all modules green, 1326 oshi-common tests, 0failures, NullAway zero at
ERROR.Summary by CodeRabbit