Skip to content

Route no-argument catch-log-return blocks through ExceptionUtil - #3528

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:exceptionutil-noarg-catch-sweep
Jul 26, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:exceptionutil-noarg-catch-sweep

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

#3444 consolidated the try/catch-log-return-default pattern onto ExceptionUtil, but it only reached part of the codebase. Sweeping every catch (Throwable) in main source turns up 47 blocks still hand-rolling it with a message that needs no arguments beyond the exception — so the existing helpers cover them with no API change.

This converts 36. No user-facing change, so no CHANGELOG entry.

What moved where

21 sites ExceptionUtil.getOrDefault / get{Int,Long,Boolean,Double}OrDefault / getOptionalInt / runOrLog
15 sites ForeignFunctions.callInArena{,Int,Long,Double,Boolean}OrDefault, where the body already opened a confined arena

Most are a straight unwrap. A few restructure slightly:

  • Advapi32UtilFFM.querySystemBootTime — the three "no boot event found" paths (empty log, no matching record, throwable) all now return 0L and share the single uptime fallback, instead of duplicating the fallback expression.
  • LinuxOperatingSystemFFM.getThreadId — uses getOptionalInt rather than a sentinel, so a successful gettid of any value is still distinguishable from a failure that should fall through to procfs.
  • WindowsBluetoothDeviceFFM / NetStatFFM / CupsPrinterFFM / MacFileSystemFFM / ProcessWtsDataFFM — the accumulator is passed as the default, so a partial result on failure is preserved exactly as before.
  • SmcUtilFFM.smcOpen and MacHWDiskStoreFFM.getDisks keep an outer try/finally for their native cleanup, since callInArena* has no finally hook.

The 11 that stay

All for one reason: the try body assigns locals declared outside it, which a lambda cannot do.

  • 7 static-initializer library-binding blocks — AdlUtilFFM, NvmlFunctions, SystemdFunctions, UdevFunctions, LinuxLibcFunctions, Kstat2Functions, DxgiFFM. Each binds 5–11 method handles into enclosing locals.
  • MacDisplayFFM.synthesize and WindowsCentralProcessorFFM.queryProcessorId assign locals read after the try.
  • IWbemLocatorFFM.connectServer and IWbemServicesFFM.execQuery free a BSTR in a finally that is assigned inside the try; converting needs an array holder, which reads worse than what is there.

One behavior change

Sites that logged ("...: {}", t.getMessage()) now also attach the throwable as the SLF4J cause, so those lines gain a stack trace. That is inherent to the ExceptionUtil contract and already true of every call site converted in #3444 — this makes the remainder consistent rather than introducing something new. All affected sites are debug/trace/warn.

Also fixes a pre-existing fully-qualified oshi.util.LogLevel.WARN in FreeBsdOSProcessFFM.

Verification

Clean full-reactor install: 1122 + 84 + 67 + 30 tests, 0 failures. Spotless, checkstyle, forbidden-apis and javadoc all clean.

Because several conversions restructure control flow rather than just swapping a wrapper, I also ran the FFM provider live on macOS (M2 Max) over the affected paths — disk stores, file stores, network interfaces, displays, CPU tick array, processor identifier and power sources all return real data.

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of system, hardware, process, network, and service information retrieval when native platform calls fail.
    • Standardized fallback behavior, preserving safe defaults such as empty results, optional values, or sentinel values.
    • Improved consistency of diagnostic logging across macOS, Windows, Linux, Solaris, FreeBSD, and related platform integrations.

PR #3444 consolidated the try/catch-log-return-default pattern onto
ExceptionUtil, but it only reached part of the codebase. A sweep of every
`catch (Throwable)` in main source turns up 47 remaining blocks that log a
message needing no arguments beyond the exception itself, which the existing
helpers already handle with no API change.

This converts 36 of them:

- 21 to ExceptionUtil.getOrDefault / get{Int,Long,Boolean,Double}OrDefault /
  getOptionalInt / runOrLog
- 15 to ForeignFunctions.callInArena{,Int,Long,Double,Boolean}OrDefault, where
  the body already opened a confined arena

The remaining 11 cannot become lambdas, all for the same reason: the try body
assigns locals declared outside it.

- 7 are static-initializer library-binding blocks (AdlUtilFFM, NvmlFunctions,
  SystemdFunctions, UdevFunctions, LinuxLibcFunctions, Kstat2Functions,
  DxgiFFM), each binding 5-11 method handles into enclosing locals.
- MacDisplayFFM and WindowsCentralProcessorFFM assign locals read after the try.
- IWbemLocatorFFM and IWbemServicesFFM free a BSTR in a finally block that is
  assigned inside the try.

Sites logging `("...: {}", t.getMessage())` now also attach the throwable as the
SLF4J cause, so those lines gain a stack trace. That is inherent to the
ExceptionUtil contract and already true of the call sites converted in #3444;
this makes the rest consistent.

Also fixes a pre-existing fully-qualified `oshi.util.LogLevel.WARN` in
FreeBsdOSProcessFFM.

Verified with a clean full-reactor build and a live run of the FFM provider on
macOS covering the restructured paths: disk stores, file stores, network
interfaces, displays, CPU ticks, processor identifier and power sources.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

FFM native integrations now use shared helpers for confined-arena lifecycle management, exception logging, and default results. The native operations, cleanup paths, sentinel values, and platform-specific behavior remain otherwise intact across macOS, Windows, Linux, FreeBSD, and Solaris code.

Changes

FFM error-handling consolidation

Layer / File(s) Summary
Native lifecycle and utility wrappers
oshi-core-ffm/src/main/java/oshi/{driver,ffm}/...
Low-level native-handle, network, WTS, SMC, and kstat operations use shared exception and default-value helpers.
Windows API arena wrappers
oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/...
DXGI, Kernel32, Shell32, and Advapi32 methods delegate arena management, logging, and fallback results to shared wrappers.
ADL initialization and sensor queries
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
ADL initialization, enumeration, capability checks, and sensor queries use centralized helper-based failure handling.
Hardware and device enumeration
oshi-core-ffm/src/main/java/oshi/hardware/platform/...
CPU ticks, disks, printers, Bluetooth devices, EDID data, and file-system queries use shared native-call wrappers.
Operating-system process and service paths
oshi-core-ffm/src/main/java/oshi/software/...
Process identifiers, resource limits, privileges, and Windows service queries use standardized exception-to-default handling.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • oshi/oshi#3525: Changes the logging-level API used by the same FFM helper methods.
  • oshi/oshi#3490: Overlaps with the AdlUtilFFM capability and adapter-enumeration code.
  • oshi/oshi#3352: Overlaps with Advapi32UtilFFM arena-wrapper refactors.

Poem

A rabbit hops through arenas bright,
Catch blocks vanish into night.
Defaults land where errors flee,
Native paths stay tidy as can be.
“Thump!” says Bun, “the wrappers agree!”

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 34.15% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main refactor of routing catch-log-return blocks through shared helpers, though it omits the ForeignFunctions portion.
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.

@codecov

codecov Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.36842% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 78.63%. Comparing base (09ba9f1) to head (543aa0e).

Files with missing lines Patch % Lines
.../oshi/hardware/platform/mac/MacHWDiskStoreFFM.java 64.51% 12 Missing and 10 partials ⚠️
...shi/software/os/linux/LinuxOperatingSystemFFM.java 33.33% 2 Missing and 2 partials ⚠️
...shi/ffm/util/platform/windows/Advapi32UtilFFM.java 57.14% 2 Missing and 1 partial ⚠️
...re/platform/windows/WindowsBluetoothDeviceFFM.java 75.00% 1 Missing ⚠️
...i/hardware/platform/windows/WindowsDisplayFFM.java 50.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3528      +/-   ##
============================================
+ Coverage     78.51%   78.63%   +0.11%     
- Complexity     3837     3958     +121     
============================================
  Files           698      698              
  Lines         24106    24061      -45     
  Branches       3989     3977      -12     
============================================
- Hits          18927    18920       -7     
+ Misses         2984     2943      -41     
- Partials       2195     2198       +3     
Flag Coverage Δ
freebsd 31.23% <2.10%> (+0.05%) ⬆️
linux 35.17% <2.10%> (+0.07%) ⬆️
macos 36.10% <46.31%> (+0.02%) ⬆️
openbsd 30.41% <0.00%> (+0.04%) ⬆️
solaris 31.68% <3.15%> (+0.06%) ⬆️
windows 43.39% <13.68%> (+0.08%) ⬆️

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.

@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-core-ffm/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java`:
- Around line 106-107: The gettid fallback in the hasSyscallGettid
initialization currently uses the default DEBUG level and an unused placeholder.
Update the getBooleanOrDefault call to pass WARN explicitly and remove the
trailing "{}" from its message, preserving the existing fallback behavior and
log text.
🪄 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: e6b5cf4c-525d-4eb1-9bef-cc6fbf58763b

📥 Commits

Reviewing files that changed from the base of the PR and between 09ba9f1 and 543aa0e.

📒 Files selected for processing (20)
  • oshi-core-ffm/src/main/java/oshi/driver/mac/net/NetStatFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/NativeHandle.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/DxgiFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Kernel32FFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Shell32FFM.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/main/java/oshi/ffm/util/platform/unix/solaris/KstatUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/CupsPrinterFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsBluetoothDeviceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
  • GitHub Check: Test JDK 25, OpenIndiana (+ JNA==FFM)
  • GitHub Check: Test JDK 25, FreeBSD (+ JNA==FFM)
  • GitHub Check: Test JDK 25, OpenBSD (+ JNA==FFM)
  • 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)
🧰 Additional context used
🧠 Learnings (1)
📚 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/NativeHandle.java
  • oshi-core-ffm/src/main/java/oshi/driver/mac/net/NetStatFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Shell32FFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/CupsPrinterFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/KstatUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsBluetoothDeviceFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/DxgiFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Kernel32FFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
🔇 Additional comments (23)
oshi-core-ffm/src/main/java/oshi/ffm/util/gpu/AdlUtilFFM.java (2)

10-15: LGTM!

Also applies to: 189-203, 225-260, 273-281


331-349: LGTM!

Also applies to: 362-379, 392-409, 422-441, 454-474

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java (1)

84-110: LGTM!

oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java (1)

7-9: LGTM!

Also applies to: 250-349

oshi-core-ffm/src/main/java/oshi/hardware/platform/unix/CupsPrinterFFM.java (1)

8-10: LGTM!

Also applies to: 54-101

oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsBluetoothDeviceFFM.java (1)

11-17: LGTM!

Also applies to: 64-89

oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsDisplayFFM.java (1)

9-9: LGTM!

Also applies to: 92-110

oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java (1)

9-9: LGTM!

Also applies to: 21-21, 68-187

oshi-core-ffm/src/main/java/oshi/driver/mac/net/NetStatFFM.java (1)

10-11: LGTM!

Also applies to: 92-92, 149-150

oshi-core-ffm/src/main/java/oshi/driver/windows/registry/ProcessWtsDataFFM.java (1)

10-10: LGTM!

Also applies to: 24-24, 75-75, 112-113

oshi-core-ffm/src/main/java/oshi/ffm/NativeHandle.java (1)

7-8: LGTM!

Also applies to: 94-94

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

10-10: LGTM!

Also applies to: 28-28, 104-120

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/KstatUtilFFM.java (1)

28-30: LGTM!

Also applies to: 88-104, 164-165

oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/DxgiFFM.java (1)

11-12: LGTM!

Also applies to: 84-135

oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Kernel32FFM.java (1)

20-20: LGTM!

Also applies to: 73-77, 113-153

oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Shell32FFM.java (1)

10-11: LGTM!

Also applies to: 47-88

oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java (3)

13-13: LGTM!

Also applies to: 35-36, 77-111


442-502: LGTM!


519-532: LGTM!

oshi-core-ffm/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java (1)

8-20: LGTM!

Also applies to: 146-148, 151-152

oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdOSProcessFFM.java (1)

9-17: LGTM!

Also applies to: 101-101, 111-117

oshi-core-ffm/src/main/java/oshi/software/os/unix/solaris/SolarisOSProcessFFM.java (1)

7-9: LGTM!

Also applies to: 68-75

oshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOperatingSystemFFM.java (1)

10-12: LGTM!

Also applies to: 92-122, 148-205

@dbwiddis
dbwiddis merged commit 2a2b53a into oshi:master Jul 26, 2026
17 checks passed
@dbwiddis
dbwiddis deleted the exceptionutil-noarg-catch-sweep branch July 26, 2026 22:19
dbwiddis added a commit that referenced this pull request Jul 26, 2026
…elpers (#3530)

#3528 converted the catch blocks whose log message needed no argument but the
exception. The 29 that remained all log extra context - a path, a pid, a
registry key - which the helpers could not express. This adds that support and
converts 27 of them.

ExceptionUtil gains `Object... args` on its 18 logging overloads in place,
adding no new methods: `msg` was already the last parameter, so every existing
call site still compiles. Caller arguments fill the leading placeholders in
order and the exception message fills a final one, so a message carries one {}
per argument plus a trailing one.

ForeignFunctions cannot do the same, because callInArena* takes the default
value last and leaves no room for a trailing varargs. It gains five overloads
that take the default value *second*, matching ExceptionUtil's
(operation, defaultValue, log, level, msg, args...) order.

Second rather than merely swapped with the message on purpose. With the default
fourth, a no-argument call whose T is String - reachable, e.g.
KstatUtilFFM.dataLookupString - would match both overloads, and Java resolves
fixed-arity before varargs, so it would silently bind to the older one with
message and default transposed. Putting the default second makes argument three
a Logger in one form and a LogLevel in the other, so they cannot collide at any
arity. ForeignFunctionsTest covers this.

Two sites could not be converted:

- WindowsGraphicsCardFFM.getGraphicsCards: the body both `continue`s the
  enclosing loop and increments an enclosing local.
- PerfDataUtilFFM.queryWildcardCounters: the nested add-counter catch aborts the
  whole method, which a helper cannot express from inside the enclosing lambda.

WindowsOSProcessFFM.queryUserInfo and queryGroupInfo assigned an enclosing local
read after the try. They were near-identical twins, so both now delegate to one
queryTokenAccountInfo method whose lambda returns the pair directly.

Verified with a clean full-reactor build and a live run of the FFM provider on
macOS. Checked en0 still resolves to "Wi-Fi" via SCNetworkInterface rather than
falling back to the raw interface name, which is what a broken conversion of
MacNetworkIfFFM.queryIfDisplayName would have looked like.
dbwiddis added a commit that referenced this pull request Jul 28, 2026
* Clear the open SonarQube findings

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.

* Do not report an unreadable SMC key block as a confirmed absence

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.

* Make the skipped-block test prove the scan never reached the key

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.
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