Repository navigation
Log the throwable instead of its message, and escalate Slf4jDoNotLogMessageOfExceptionExplicitly to ERROR - #3611
Conversation
…RROR The errorprone-slf4j check Slf4jDoNotLogMessageOfExceptionExplicitly was adopted at WARN in #3610 with a 74-site backlog left to drain. This drains it and moves the check to the plugin's default ERROR severity. Every one of the 74 log statements substituted the exception's message into the log text instead of passing the exception itself. Passing the throwable is better on three counts: the stack trace and cause chain reach the logs rather than a single message line; getMessage() returns null for exceptions constructed without one, which logged the literal text "null"; and SLF4J defers all rendering when the level is disabled, whereas getMessage() is evaluated at the call site regardless. Where the message ended in a placeholder that only existed to hold the exception text, the placeholder is dropped along with any separator left dangling in front of it. Three shared format constants (COM_EXCEPTION_MSG in oshi-common, shared by both Sensors twins, and COM_EXCEPTION_FMT in each WmiQueryHandler twin) lost their trailing placeholder instead, covering eleven call sites between them. AbstractNetworkIF built its InstantiationException from the SocketException's message and discarded the exception, so the stack trace getNetworks() now logs would have stopped there. It attaches the cause via initCause, since InstantiationException has no (String, Throwable) constructor. ExceptionUtil.logAtLevel appends both t.getMessage() and t to an Object[] before dispatching, which these checks cannot see through, so its callers are untouched here and left for a follow-up.
|
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 (47)
📜 Recent review details⏰ Context from checks skipped due to timeout. (11)
🧰 Additional context used📓 Path-based instructions (4)**/*.{java,properties}📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (6)📚 Learning: 2026-04-06T04:45:47.644ZApplied 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-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
🪛 PMD (7.26.0)oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java[Low] 85-85: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 0 argument but found 1 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/util/platform/windows/RegistryUtil.java[Low] 71-71: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 2 arguments but found 3 (InvalidLogMessageFormat (Error Prone)) oshi-core-ffm/src/main/java/oshi/driver/windows/registry/InstalledAppsDataFFM.java[Low] 121-121: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 2 arguments but found 3 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/software/os/windows/WindowsOSProcessJNA.java[Low] 215-215: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 3 arguments but found 4 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupJNA.java[Low] 53-53: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 0 argument but found 1 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/util/platform/unix/solaris/KstatUtil.java[Low] 278-278: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 2 arguments but found 3 (InvalidLogMessageFormat (Error Prone)) [Low] 328-328: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 1 argument but found 2 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/util/platform/windows/WmiQueryHandler.java[Low] 210-210: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 2 arguments but found 3 (InvalidLogMessageFormat (Error Prone)) [Low] 212-212: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 2 arguments but found 3 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/util/platform/windows/PerfCounterWildcardQuery.java[Low] 153-154: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 1 argument but found 2 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/software/os/windows/WindowsOperatingSystemJNA.java[Low] 373-373: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 0 argument but found 1 (InvalidLogMessageFormat (Error Prone)) oshi-core-ffm/src/main/java/oshi/ffm/util/platform/windows/WmiQueryHandlerFFM.java[Low] 427-427: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 2 arguments but found 3 (InvalidLogMessageFormat (Error Prone)) [Low] 429-429: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 2 arguments but found 3 (InvalidLogMessageFormat (Error Prone)) oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java[Low] 90-90: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 0 argument but found 1 (InvalidLogMessageFormat (Error Prone)) oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsLogicalVolumeGroupFFM.java[Low] 52-52: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 0 argument but found 1 (InvalidLogMessageFormat (Error Prone)) oshi-core/src/main/java/oshi/driver/windows/registry/HkeyUserData.java[Low] 87-87: InvalidLogMessageFormat (Error Prone): Too many arguments, expected 1 argument but found 2 (InvalidLogMessageFormat (Error Prone)) 🔇 Additional comments (48)
📝 WalkthroughWalkthroughThe change standardizes exception logging across OSHI modules. Logging calls now pass throwable objects directly to SLF4J. ChangesException logging standardization
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This change routes exceptions to logging so stack traces and causes are preserved without changing the public API; no actionable merge-blocking risk remains after normal checks and review. 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 #3611 +/- ##
============================================
+ Coverage 79.81% 79.84% +0.03%
- Complexity 4108 4231 +123
============================================
Files 696 696
Lines 24220 24220
Branches 4057 4057
============================================
+ Hits 19330 19339 +9
+ Misses 2728 2719 -9
Partials 2162 2162
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:
|
…a helpers (#3612) * Log the throwable, not its message, in ExceptionUtil and the FFM arena helpers PR #3611 drained the 74-site Slf4jDoNotLogMessageOfExceptionExplicitly backlog and escalated that check to ERROR, but Error Prone cannot see through an argument array: ExceptionUtil.logAtLevel built an Object[] holding both t.getMessage() and t before dispatching, so the same defect it now forbids at every LOG call site was still being applied on behalf of 200 callers, invisibly. Drop the getMessage() element, so only the throwable is appended and the logging backend renders it with its stack trace and cause chain. Correspondingly stop ForeignFunctions.logThrowable synthesizing a ": {}" suffix on its caller's message, and drop the now-redundant trailing placeholder from the 71 messages that carried one. The remaining 129 call sites already omitted it -- their getMessage() was an extra argument SLF4J silently discarded. Two call sites were losing a real argument to that substitution, and now report it: HkeyUserDataFFM.getSubKeys never logged the registry key path (its second placeholder had no argument and printed literally), and HkeyPerformanceDataUtilFFM.readPerfDataBuffer never logged the object name, even though both sibling log calls in the same lambda do. Also fix ForeignFunctions.dlopenWithFlags, which copied the failure's message into the UnsatisfiedLinkError it throws and dropped the throwable, so the trace dead-ended; UnsatisfiedLinkError has no (String, Throwable) constructor, so attach the cause with initCause. Three fully-qualified oshi.util.LogLevel.WARN references in files already static-importing WARN are de-qualified in passing. * Widen the argument copy to Object[] and align the msg javadoc Arrays.copyOf preserves the source array's runtime component type. Passing a typed array to logAtLevel's varargs parameter is legal Java, and in that case the copy came back as e.g. a String[], so appending the throwable to it threw ArrayStoreException from inside the catch block - replacing the failure being reported with an unrelated one. Ask for an Object[] explicitly, and pin it with a test that passes a String[] (the cast there is a compile-time no-op, so the array really is a String[] at runtime). Only the two generic getOrDefault overloads documented that placeholders correspond to the explicit arguments with none reserved for the exception; the primitive, optional, and runnable overloads all just said "the log message". Give them the same wording, since they forward to the same contract.
* Adopt jSpecify and document API nullability (Phase 1) Phase 1 of the jSpecify rollout proposed in #3593: mark the two packages that define the public API, oshi.hardware and oshi.software.os, as @NullMarked so that every type usage in a signature there is non-null unless it is explicitly annotated @nullable. The dependency is compile-time metadata only. It is declared optional in oshi-common/pom.xml, requires static in the module descriptor, and an optional OSGi Import-Package, so it does not reach a consumer's runtime classpath and does not become a transitive compile dependency. Very little of the API turns out to be nullable, because OSHI reports an unreadable value as a sentinel rather than null. The genuine exceptions are now annotated and documented: OperatingSystem.getProcess(int), the optional filter/sort arguments of the three process-listing methods, the three OSVersionInfo fields and getters, PowerSource.getManufactureDate(), InternetProtocolStats.IPConnection.getState() (null for UDP), the ProcessorIdentifier microarchitecture argument, ApplicationInfo's additionalInfo map, the OSProcess/OSThread ...CpuLoadBetweenTicks arguments, and equals(@nullable Object). Marking the packages surfaced two bugs: DisplayInfoImpl's synthetic constructor stored its nullable arguments as-is, so getSerialNo(), getPreferredResolution(), getModel(), and getProductSerialNumber() could return null even though DisplayInfo documents them non-null, and toString() rendered the text "null". This is reachable in production: EdidUtil.synthesizeDisplayInfo passes a null resolution when a display reports no pixel dimensions, which is how the Apple Silicon built-in panel is constructed. Absent values now normalize to the empty string, matching the convention the rest of the API follows. Setting an empty preferred resolution into the synthesized EDID behaves identically to leaving it null, so EDID synthesis is unchanged. OperatingSystem.getProcesses() documented that the returned list "may contain null elements" and was "sorted as specified"; neither has been true. It now documents the same INVALID-state caveat as its siblings. oshi.util and oshi.ffm are deliberately left unmarked. oshi.util holds the @publicapi PlatformEnum but many more classes besides, and is Phase 2; oshi.ffm waits on an unreleased NullAway fix for a crash, which also defers marking the @publicapi oshi.ffm.SystemInfo entry point. FAQ.md gains a section collecting all three annotation families OSHI uses to document contracts - @publicapi for semver scope, the oshi.annotation.concurrent annotations for thread safety, and now jSpecify for nullability - since a caller reading one of them will want to know the others exist. * Make the marked packages self-consistent for nullable parameters Two loose ends from review, both declaration-only: no runtime behavior changes and no new tests, because the existing tests already exercise the null inputs involved. ProcessorIdentifier.derivedMicroarchitecture was declared non-null but assigned straight from the @nullable constructor argument. Normalize the absent case to the empty string at the boundary, as DisplayInfoImpl now does: queryMicroarchitecture reaches the field through Util.isBlank, which treats null and empty identically, so Constants.UNKNOWN remains the result when no microarchitecture is available. The local variable in that method is deliberately left alone; jSpecify does not apply to local variable declarations, whose nullness an analyzer infers. Overrides in oshi.hardware and oshi.software.os cannot narrow a parameter from @nullable to non-null, so an unannotated override of one in those packages contradicts the interface. Every such override is a test double: two in OSThreadTest, two in OSProcessTest, and three in OperatingSystemTest (getProcesses, getChildProcesses, getDescendantProcesses). AbstractOSThread and the platform implementations are not affected, as they live in subpackages that are not marked and therefore make no nullness claim. That is the first jspecify import from test code, so config/import-control-test.xml needs the same allowlist entry the main import-control file already got. * Enforce the jSpecify annotations with NullAway The Phase 1 annotations documented the API's nullability but nothing checked them, so a violation was only ever caught by review — as one was: the @nullable microarchitecture assigned to a non-null field. Add NullAway 0.13.8 to the existing error-prone profile at ERROR severity with OnlyNullMarked=true and JSpecifyMode=true. OnlyNullMarked scopes the analysis to @NullMarked code rather than to a module list, so the two marked API packages are checked and everything else is untouched; marking a package in a later phase needs no build change. 0.12.x is incompatible with Error Prone 2.50.0. Fix the 16 findings this surfaces. One is in main code: queryMicroarchitecture spells out its null-and-empty check because NullAway cannot see through Util.isBlank to learn the value is non-null on the branch that follows. The other 15 are test stubs returning null for non-null API methods; they throw UnsupportedOperationException instead, except OperatingSystemTest.getProcess(int), whose null is load-bearing for the getCurrentProcess() default-method test and is annotated @nullable to match the interface. The suite passing proves the 14 throws are unreached. Verified the gate fires by reintroducing each finding class in turn: assigning null to a non-null field, returning null from a non-null method, and dereferencing a @nullable value all fail the build, and the restored tree passes. -DskipTests skips test execution but not test compilation, so the CI job covers test sources too. Also correct the AGENTS.md note that oshi.ffm was blocked on a NullAway fix; it is not, on 0.13.8. * Tighten the changelog entries for this release State the changed behavior and stop there. Combine #3611 and #3612, which were one change to logging behavior split across two PRs. * Drop getSerialNo() from the changelog's null-fix list The only production callers of the synthetic DisplayInfo path are MacDisplayJNA and MacDisplayFFM, both via EdidUtil.synthesizeDisplayInfo, which substitutes "00000000" for an absent serial. getSerialNo() never returned null there, so it was not one of the getters fixed.
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.
Follow-up to #3610, which adopted the
errorprone-slf4jplugin and leftSlf4jDoNotLogMessageOfExceptionExplicitlyatWARNwith a 74-site backlog. This drains the backlog and moves the check to the plugin's defaultERROR.What was wrong
All 74 sites substituted the exception's message into the log text instead of passing the exception:
Passing the throwable is better on three counts:
getMessage()is null for exceptions constructed without one, so those sites logged the literal textnull. A barenew IOException()is a real case here.getMessage()is evaluated at the call site regardless of level. Most of these aredebug/tracein per-poll paths.What changed
Where the trailing placeholder existed only to hold the exception text, it is dropped along with any separator left dangling in front of it:
Three shared format constants lost their trailing placeholder rather than being edited at each use:
COM_EXCEPTION_MSGinoshi-common'sWindowsSensors(shared by both Sensors twins) andCOM_EXCEPTION_FMTin eachWmiQueryHandlertwin, covering eleven call sites between them.AbstractNetworkIFbuilt itsInstantiationExceptionfrom theSocketException's message and discarded the exception itself, so the stack tracegetNetworks()now logs would have dead-ended there. It attaches the cause withinitCause, sinceInstantiationExceptionhas no(String, Throwable)constructor.The JNA and FFM twins moved together throughout.
Known remaining backlog, deliberately not in this PR
ExceptionUtil.logAtLevel— the shared dispatch behindgetOrDefault/runOrLog/getOptional*— appends botht.getMessage()andtinto anObject[]before dispatching:These checks cannot see through an argument array, so none of its callers were reported, and escalating to
ERRORdoes not catch them. The stack trace is never lost there (the throwable is passed), but the message text is reported twice and is still rendered when the level is disabled. 67 call sites across 21 files pass a message ending in{}to catch it inline; 59 others already omit the placeholder, sogetMessage()lands as an unmatched extra argument that SLF4J discards. Changing that contract plus its callers is a different shape of change from this mechanical sweep, so it is left for a follow-up.Verification
./mvnw clean spotless:apply sortpom:sort checkstyle:check install forbiddenapis:check javadoc:javadoc- exit 0, 1559 tests successful, 0 failed../mvnw clean install -DskipTests -Perror-prone- zero Error Prone output with the check atERROR, so nothing was missed. A clean build is required to see these findings at all; an incremental one silently reports none.Log output changes broadly, so unlike #3610 this carries a CHANGELOG entry. The behavior is only reachable through consumers' logging configuration; no API changes.
Summary by CodeRabbit
Bug Fixes
Chores
Documentation