Repository navigation
Consolidate try/catch-log-return-default patterns to use ExceptionUtil - #3444
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (8)
📜 Recent review details⏰ Context from checks skipped due to timeout. (13)
🧰 Additional context used🧠 Learnings (4)📚 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-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (9)
📝 WalkthroughWalkthroughThe changes replace several explicit try/catch-and-default patterns with ChangesExceptionUtil consolidation
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
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 #3444 +/- ##
============================================
+ Coverage 68.21% 74.38% +6.16%
Complexity 76 76
============================================
Files 580 580
Lines 21969 21945 -24
Branches 3670 3670
============================================
+ Hits 14987 16323 +1336
+ Misses 5139 3582 -1557
- Partials 1843 2040 +197
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:
|
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.
Summary
Replace manual try/catch blocks that log and return a default value with
ExceptionUtilmethod calls, reducing boilerplate and routing exception handling through the common tested path.Converted patterns:
LinuxOSProcess.parseAffinityMask— BigInteger hex parse →getLongOrDefaultLinuxOperatingSystemNF.getThreadId— symlink read →getIntOrDefaultLinuxOperatingSystemJNA.getThreadId— same pattern →getIntOrDefaultLinuxFirmware.queryVcGenCmd— date format parse →getOrDefaultLinuxCentralProcessor.parseCacheType— enum valueOf →getOrDefaultWindowsInternetProtocolStatsFFM— 4 TCP/UDP stats methods →getOrDefaultAbstractNetworkIF—getAllNetworkInterfacesandisLocalInterface→getOrDefault/getBooleanOrDefaultAlso downgrades logging from ERROR to DEBUG for network interface and IP stats exceptions — these represent transient/environmental conditions, not application errors.
Test plan
mvn compilepasses for oshi-common, oshi-core, oshi-core-ffmmvn testpasses for oshi-common, oshi-core-ffm, oshi-benchmarkmvn spotless:apply,checkstyle:check,forbiddenapis:check,javadoc:javadocall passSummary by CodeRabbit
Bug Fixes
Documentation