Skip to content

Clear the open SonarQube findings - #3540

Merged
dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:sonar-triage-2026-07-27
Jul 28, 2026
Merged

dbwiddis merged 3 commits into
oshi:masterfrom
dbwiddis:sonar-triage-2026-07-27

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 28, 2026 •

Copy link
Copy Markdown
Member

Clears the SonarCloud backlog: 8 findings fixed in code, 10 suppressed with an inline reason, and the 4 remaining S3776 complexity findings accepted in SonarCloud rather than refactored.

Fixed

Rule Where Change
S1128 ×2 DxgiFFM, Shell32FFM Genuinely redundant. Both classes extend ForeignFunctions / WindowsForeignFunctions and inherit callInArenaOrDefault; spotless can't detect this because the bare name is textually referenced.
S135 ×2 SmcKeyIndex scan loop, parseConfiguredKeys Restructured as if/else. Behaviour identical.
S6353 SmcKeyIndex GPU key mask ^Tg[0-9][0-9A-Za-z]$ → ^Tg\d[\dA-Za-z]$. Identical without UNICODE_CHARACTER_CLASS.
S1192 SysctlFFM ×5 The failure message was concatenated eagerly at every call site, formatting the sysctl name on every call whether or not it failed. Now uses the parameterized callInArena*OrDefault overloads (#3530) with one shared constant, so the name is only formatted on the failure path.
S1602 AdlUtilFFM.adlUninit Added the block-lambda guard comment matching BStrFFM. Collapsing the block would reintroduce #3422; VoidInvokeExactSourceTest already guards the code, this stops the rule nagging toward the bug.

Suppressed

Each carries // NOSONAR squid:Sxxxx plus the reason, and a javadoc note where one wasn't already present.

  • S1168 ×5 (SmcKeyIndex ×3, both SmcUtil twins) — null and empty are different answers. Empty is a cacheable "this machine has no GPU temperature keys"; returning it after a failed read would cache the failure and disable GPU temperature for the lifetime of the JVM.
  • S3077 ×2 (gpuTemperatureKeys) — false positive. Only ever assigned an unmodifiable copy of a completed discovery, so the volatile write safely publishes an immutable value. Memoizer carries the same suppression.
  • S5786 ×3 (test classes) — the module system only opens public types to the JUnit platform, so public is required, not redundant. SystemInfoTest carries the same suppression.

Accepted in SonarCloud, not refactored

The four S3776 cognitive-complexity findings, per the project's standing policy. Three are an artifact of the ExceptionUtil / callInArena conversions in #3528 and #3530 — moving a method body into a callInArenaOrDefault lambda adds a nesting level Sonar scores, with no change to the logic. Shell32FFM.CommandLineToArgv went from roughly at-threshold to 18 that way.

Verification

Pre-commit gate clean on oshi-common,oshi-core,oshi-core-ffm (spotless, checkstyle, install, forbiddenapis, javadoc), plus a clean full-reactor install from root. All tests pass. NativeComparisonTest under -Pnative-comparison passes on an M2 Max including sensors(), so JNA/FFM parity is intact.

No CHANGELOG entry: no user-observable behaviour changes.

Summary by CodeRabbit

  • Bug Fixes
    • Improved macOS GPU temperature key discovery so unreadable probes no longer get treated as confirmed absence; empty results are still reported correctly when all reads succeed.
  • Documentation
    • Clarified GPU temperature key cache semantics, including safe publication and that “null” indicates discovery failure.
    • Refined messaging around sysctl retrieval failure logging.
  • Tests
    • Expanded macOS sensor discovery tests to cover failure-handling and cache behavior under module discovery.
  • Refactor
    • Centralized repeated sysctl failure text and adjusted minor native/language cleanups.

Eight are fixed in code and ten are suppressed with an inline reason.

Fixed:

- S1128 x2: DxgiFFM and Shell32FFM extend ForeignFunctions and
  WindowsForeignFunctions respectively, so they inherit
  callInArenaOrDefault and the static import is redundant. Spotless
  cannot detect this because the bare name is textually referenced.
- S135 x2: restructure the SmcKeyIndex scan loop and
  parseConfiguredKeys as if/else. Behaviour is unchanged.
- S6353: write the GPU key mask as ^Tg\d[\dA-Za-z]$. Without
  UNICODE_CHARACTER_CLASS this is identical to the [0-9] form.
- S1192: SysctlFFM concatenated its failure message eagerly at all five
  call sites, formatting the sysctl name on every call whether or not it
  failed. Use the parameterized callInArena*OrDefault overloads with a
  single shared constant so the name is only formatted on failure.
- S1602: add the block-lambda guard comment to AdlUtilFFM.adlUninit,
  matching BStrFFM. Collapsing the block would reintroduce #3422.

Suppressed:

- S1168 x5: null and empty are different answers. Empty is a cacheable
  "this machine has no GPU temperature keys"; returning it after a
  failed read would cache the failure and disable GPU temperature for
  the lifetime of the JVM.
- S3077 x2: gpuTemperatureKeys is only ever assigned an unmodifiable
  copy of a completed discovery, so the volatile write safely publishes
  an immutable value. Memoizer carries the same suppression.
- S5786 x3: the module system only opens public types to the JUnit
  platform, so public on these test classes is required rather than
  redundant. SystemInfoTest carries the same suppression.

The four remaining S3776 findings are accepted in SonarCloud rather than
refactored. Three of them are an artifact of the ExceptionUtil and
callInArena conversions in #3528 and #3530: moving a method body into a
callInArenaOrDefault lambda adds a nesting level that Sonar scores,
without changing the logic.
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: bae178f0-14a9-43aa-bc6a-c9d5b56117fb

📥 Commits

Reviewing files that changed from the base of the PR and between f3286f5 and a7ffe4c.

📒 Files selected for processing (1)
  • oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout. (5)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)

📝 Walkthrough

Walkthrough

SMC GPU key discovery and caching semantics were refined, FFM utility handling was consolidated, ADL teardown invocation was adjusted, and macOS JPMS test visibility documentation was expanded.

Changes

SMC discovery updates

Layer / File(s) Summary
SMC key matching and failure handling
oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java, oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java
GPU key matching, scan failure handling, configured-key validation, and related tests were updated.
SMC cache contract
oshi-core/src/main/java/oshi/util/platform/mac/SmcUtil.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java
GPU temperature cache publication and discovery-failure semantics were documented.

FFM utility updates

Layer / File(s) Summary
FFM imports and sysctl logging
oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/DxgiFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Shell32FFM.java, oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java
Static imports were removed where inherited access is used, and sysctl failure messages were centralized.
ADL teardown invocation
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
ADL context destruction now uses a block lambda for void native invocation.

JPMS test discovery documentation

Layer / File(s) Summary
Public test visibility
oshi-core-ffm/src/test/java/oshi/ffm/MacSensorsPlausibilityFFMTest.java, oshi-core/src/test/java/oshi/util/platform/mac/MacSensorsPlausibilityTest.java
Javadoc explains public visibility requirements for JPMS/JUnit discovery, with NOSONAR annotations added to class declarations.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • oshi/oshi#3536: Refines the shared macOS GPU SMC key discovery and parsing logic updated here.

Poem

I hopped through SMC keys in a row,
While FFM logs began to glow.
A native lambda closed with care,
JPMS tests stood proudly there.
“Clean code!” cried Bunny, with a cheer.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: resolving open SonarQube findings across the codebase.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java`:
- Around line 97-104: Update the candidate-read loop in SmcKeyIndex so an
uncertain read followed by a non-matching key does not produce a cacheable empty
list. Track whether any matching Tg key was successfully established, return
null when reads failed and none was found, and preserve an empty result only for
a confirmed absence; add a regression test covering a failed sole Tg key
followed by Th00.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4c222fdc-9247-49da-81c9-1146b676c510

📥 Commits

Reviewing files that changed from the base of the PR and between 2e58283 and b94e813.

📒 Files selected for processing (10)
  • oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java
  • oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/DxgiFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Shell32FFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java
  • oshi-core-ffm/src/test/java/oshi/ffm/MacSensorsPlausibilityFFMTest.java
  • oshi-core/src/main/java/oshi/util/platform/mac/SmcUtil.java
  • oshi-core/src/test/java/oshi/util/platform/mac/MacSensorsPlausibilityTest.java
💤 Files with no reviewable changes (2)
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Shell32FFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/DxgiFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout. (3)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.

Applied to files:

  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java
  • oshi-core/src/main/java/oshi/util/platform/mac/SmcUtil.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java
  • oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.

Applied to files:

  • oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java
🔇 Additional comments (11)
oshi-core-ffm/src/main/java/oshi/ffm/util/SysctlFFM.java (1)

37-42: LGTM!

Also applies to: 59-63, 83-83, 108-108, 132-132, 148-148, 173-173

oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java (1)

201-204: LGTM!

oshi-core-ffm/src/test/java/oshi/ffm/MacSensorsPlausibilityFFMTest.java (1)

34-39: LGTM!

oshi-core/src/test/java/oshi/util/platform/mac/MacSensorsPlausibilityTest.java (1)

36-41: LGTM!

oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java (4)

45-45: LGTM!


79-83: LGTM!


113-113: LGTM!


200-204: LGTM!

oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java (1)

26-30: LGTM!

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java (1)

121-125: LGTM!

Also applies to: 380-380

oshi-core/src/main/java/oshi/util/platform/mac/SmcUtil.java (1)

106-110: LGTM!

Also applies to: 352-352

@codecov

codecov Bot commented Jul 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.45455% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 78.86%. Comparing base (2c72f54) to head (a7ffe4c).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
...ava/oshi/util/common/platform/mac/SmcKeyIndex.java 95.45% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3540      +/-   ##
============================================
- Coverage     78.92%   78.86%   -0.07%     
- Complexity       76     3649    +3573     
============================================
  Files           699      699              
  Lines         24082    24083       +1     
  Branches       3985     3986       +1     
============================================
- Hits          19006    18992      -14     
- Misses         2884     2895      +11     
- Partials       2192     2196       +4     
Flag Coverage Δ
linux 35.44% <95.45%> (+0.04%) ⬆️
macos 36.38% <95.45%> (-0.03%) ⬇️
windows 43.66% <95.45%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

findKeys distinguishes null ("could not read, ask again later") from an
empty list ("this machine has no such keys"), because the caller caches
the empty list and would otherwise disable the sensor for the lifetime
of the JVM. Two paths could reach empty after a failed read.

In the forward scan, readAny was satisfied by the key that ends the
block rather than by a match, so an index of [TB0T, Tg0f, Th00] whose
Tg0f is unreadable returned an empty list: the scan read Th00, set
readAny, and broke out having matched nothing.

In the binary search, probe substitutes a neighbouring key for an
unreadable one so a single bad index cannot abort discovery. That
substitution can move the landing point past the block, so for
[TB0T, TCMb, Tg0f, Th00] with Tg0f unreadable the scan never attempted
the only matching key, and no scan-side check could have caught it.

Track failed reads through a single wrapper around the lookup function
so both paths are covered, and return null when nothing matched and any
read failed. An empty result from a run with no failed read is still
returned and still cacheable, and a partial result is still returned,
so the existing skip-rather-than-stop behaviour is unchanged.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java`:
- Around line 130-137: Update
testFailedSearchProbeThatSkipsTheBlockIsNotReportedAsAbsent so the flaky reader
returns null only on the first read of index 2, then returns keys[2] on
subsequent reads. Track that read state within the test’s IntFunction,
preserving the existing assertion so an incorrect forward-scan retry exposes the
regression.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5a29b0f0-5533-47ba-9498-5983ddb8e1e0

📥 Commits

Reviewing files that changed from the base of the PR and between b94e813 and f3286f5.

📒 Files selected for processing (2)
  • oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java
  • oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-common/src/main/java/oshi/util/common/platform/mac/SmcKeyIndex.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyze (java)
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🔇 Additional comments (3)
oshi-common/src/test/java/oshi/util/common/platform/mac/SmcKeyIndexTest.java (3)

26-30: LGTM!


120-128: LGTM!


140-146: LGTM!

testFailedSearchProbeThatSkipsTheBlockIsNotReportedAsAbsent failed the
sole matching index permanently, so a null result did not distinguish
the case it names -- the binary search substituting a neighbour and
landing past the block -- from the scan reaching that index and failing
both its reads. Both produce null.

Fail only the first read, which the search consumes. A null result now
proves the scan never attempted the index, because the scan retries once
and would have recovered Tg0f and returned a non-empty list. This also
separates the test from testFailedSoleMatchIsNotReportedAsAbsent, which
keeps a permanently failing index.
@dbwiddis
dbwiddis merged commit 8948ac4 into oshi:master Jul 28, 2026
16 checks passed
@dbwiddis
dbwiddis deleted the sonar-triage-2026-07-27 branch July 28, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant