Repository navigation
Support parameterized log messages in ExceptionUtil and callInArena helpers - #3530
Conversation
…elpers #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.
📝 WalkthroughWalkthroughChangesException logging and FFM fallback consolidation
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested reviewers: 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 #3530 +/- ##
============================================
+ Coverage 78.69% 78.80% +0.10%
- Complexity 3838 3947 +109
============================================
Files 698 698
Lines 24060 24009 -51
Branches 3977 3963 -14
============================================
- Hits 18935 18920 -15
+ Misses 2932 2898 -34
+ Partials 2193 2191 -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:
|
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/ExceptionUtil.java`:
- Around line 43-48: Preserve the existing fixed-arity public overloads for
ExceptionUtil.logAtLevel(..., Throwable), the get*OrDefault and getOptional(...)
log/message methods, and runOrLog(..., String) by restoring each original
signature as a forwarding overload. Keep the new varargs variants alongside
them, delegating from fixed-arity methods without changing existing behavior or
JVM method descriptors.
In `@oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java`:
- Line 31: Restore the static ERROR import in SmcUtilFFM while retaining the
existing WARN import, so the smcOpen call at line 123 continues to compile with
its current logging level.
🪄 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: 9a7b92c6-0d6f-4cf8-a8c4-72437adb4744
📒 Files selected for processing (20)
oshi-common/src/main/java/oshi/util/ExceptionUtil.javaoshi-common/src/test/java/oshi/util/ExceptionUtilTest.javaoshi-common/src/test/java/oshi/util/LogUtilTest.javaoshi-core-ffm/src/main/java/oshi/driver/unix/aix/PsInfoFFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/DeviceTreeFFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Cfgmgr32FFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/KstatUtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfDataUtilFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.javaoshi-core-ffm/src/test/java/oshi/ffm/ForeignFunctionsTest.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.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: Analyze (java)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (3)
📚 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/hardware/platform/mac/MacHWDiskStoreFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsCentralProcessorFFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/DeviceTreeFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacNetworkIfFFM.javaoshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Cfgmgr32FFM.javaoshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/driver/unix/aix/PsInfoFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.javaoshi-core-ffm/src/main/java/oshi/software/os/windows/WindowsOSProcessFFM.javaoshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/PerfDataUtilFFM.javaoshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.javaoshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/KstatUtilFFM.javaoshi-common/src/main/java/oshi/util/ExceptionUtil.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.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/ExceptionUtil.java
🔇 Additional comments (10)
oshi-core-ffm/src/main/java/oshi/ffm/ForeignFunctions.java (1)
162-191: LGTM!Also applies to: 218-239, 266-287, 314-335, 362-383, 595-599
oshi-core-ffm/src/test/java/oshi/ffm/ForeignFunctionsTest.java (1)
120-171: LGTM!oshi-core-ffm/src/main/java/oshi/driver/unix/aix/PsInfoFFM.java (1)
10-11: LGTM!Also applies to: 63-142
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.java (1)
11-12: LGTM!Also applies to: 25-25, 142-172
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.java (1)
18-19: LGTM!Also applies to: 66-98
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java (1)
10-12: LGTM!Also applies to: 147-165, 193-202
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/unix/solaris/KstatUtilFFM.java (1)
7-8: LGTM!Also applies to: 120-128, 210-236, 251-274
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/Advapi32UtilFFM.java (1)
38-38: LGTM!Also applies to: 371-430
oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdOSProcessFFM.java (1)
11-19: LGTM!Also applies to: 66-90, 99-127
oshi-core/src/main/java/oshi/software/os/mac/MacOSFileStoreJNA.java (1)
7-7: LGTM!Also applies to: 39-49
* 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.
Completes the sweep started in #3528. That PR converted the catch blocks whose 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 had no way to express. This adds that support and converts 27 of them.
No user-facing change, so no CHANGELOG entry.
ExceptionUtil— modified in place, no new methodsmsgwas already the last parameter, so appendingObject... argsto the 18 logging overloads leaves every existing call site compiling unchanged. Caller arguments fill the leading placeholders in order, then the exception message fills a final one:Safe to change in place because
ExceptionUtilis not@oshi.annotation.PublicApi, and japicmp is configured to gate only@PublicApitypes.ForeignFunctions— five new overloads, default value secondcallInArena*takes the default value last, leaving no room for a trailing varargs, so it needs new overloads rather than an in-place change. They take the default second, matchingExceptionUtil's existing(operation, defaultValue, log, level, msg, args...)order so both utilities read the same way.Second rather than merely swapped with the message on purpose. With the default fourth, this call — whose
TisString, so message and default have the same type — matches both overloads:Java resolves fixed-arity before varargs, so it would silently bind to the older overload with the two transposed. That is reachable in practice (
KstatUtilFFM.dataLookupStringreturnsString). Putting the default second makes argument three aLoggerin one form and aLogLevelin the other, so the two cannot collide at any arity.ForeignFunctionsTestpins this down.The two that stayed
WindowsGraphicsCardFFM.getGraphicsCards— the body bothcontinues the enclosing loop and increments an enclosing local. A lambda can do neither.PerfDataUtilFFM.queryWildcardCounters— the nested add-counter catch aborts the whole method; a helper cannot express "abort the enclosing lambda" from inside it. The outer catch in the same method was converted, so this one now sits inside that lambda, where itsreturnstill exits the method as before.Notable conversions
WindowsOSProcessFFM.queryUserInfo/queryGroupInfoassigned an enclosing local read after the try. They were near-identical twins differing only in the token class and one noun, so both now delegate to a singlequeryTokenAccountInfowhose lambda returns the pair directly.InstalledAppsDataFFMhad acontinueskipping the current registry key. Inside arunOrLoglambda the equivalent isreturn— the enclosing loop still advances.PerfDataUtilFFM.queryCountersneeded its query handle read into an effectively-final local so the per-counter lambdas could capture it. Previously it was assigned inside the try with a null guard infinally; the handle is read immediately after a checkedPdhOpenQuery, so hoisting it changes nothing (in both forms a throw before the assignment leaves the handle unclosed).Verification
Clean full-reactor
install: 1127 + 84 + 71 + 30 tests, 0 failures. Spotless, checkstyle, forbidden-apis and javadoc all clean. New tests cover argument ordering, the zero-argument path being unchanged, the success path logging nothing, and the overload-resolution hazard above.Also ran the FFM provider live on macOS (M2 Max) over the affected paths. Specifically checked that
en0still resolves toWi-FithroughSCNetworkInterfacerather than falling back to the raw interface name — a broken conversion ofMacNetworkIfFFM.queryIfDisplayName, the site that prompted this whole sweep, would otherwise have looked healthy.Summary by CodeRabbit
New Features
{}placeholders and additional arguments.Bug Fixes
Tests