Skip to content

Apply ExceptionUtil to remaining FFM files - #3273

Merged
dbwiddis merged 1 commit into
masterfrom
feature/exception-util-remaining
May 19, 2026
Merged

dbwiddis merged 1 commit into
masterfrom
feature/exception-util-remaining

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #3272. Applies the ExceptionUtil pattern to 19 additional files in oshi-core-ffm, eliminating ~98 total catch(Throwable) boilerplate blocks across both PRs.

Changes

19 files refactored using static imports of getOptionalInt, getOptional, getOptionalLong, getBooleanOrDefault, getIntOrDefault, getOrDefault, runSilently, and runOrLog.

Net: -112 lines (108 insertions, 220 deletions).

Remaining Work

178 catch(Throwable) blocks remain. These have patterns that don't mechanically convert:

  • Non-final variable captures: try bodies that assign to variables declared before the try
  • Type inference issues: lambdas returning Optional.empty() from multiple branches confuse type inference
  • Complex catch bodies: blocks that check error codes, call GetLastError, or have conditional logic
  • Static initializer blocks: library loading in static {} blocks

These can be addressed in future PRs with targeted manual refactoring.

Verification

  • ✅ spotless:apply
  • ✅ checkstyle:check
  • ✅ install (compile + test, 0 failures)
  • ✅ forbiddenapis:check
  • ✅ javadoc:javadoc

Summary by CodeRabbit

  • Refactor
    • Standardized exception handling patterns across the library by consolidating error-handling logic into centralized utility methods, improving code consistency and maintainability.

Review Change Stack

Refactor 19 additional files in oshi-core-ffm to use ExceptionUtil static
imports, eliminating catch(Throwable) boilerplate blocks.

Total catch(Throwable) blocks eliminated across both PRs: ~98
(from 276 original down to 178 remaining).

Files with complex patterns (non-final variable captures in lambdas,
type inference issues with Optional returns, multi-statement catch blocks
with error code checking) are left for follow-up work.
@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a82e2c6c-40c8-484a-bf88-e735280b96e5

📥 Commits

Reviewing files that changed from the base of the PR and between bed5eda and 31aef42.

📒 Files selected for processing (19)
  • oshi-core-ffm/src/main/java/oshi/driver/mac/IOReportClientFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/mac/DiskArbitration.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/IOKitUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/Advapi32FFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/Kernel32FFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/NtDllFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/com/BStrFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IEnumWbemClassObjectFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IUnknownFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IWbemClassObjectFFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/com/Ole32FFM.java
  • oshi-core-ffm/src/main/java/oshi/ffm/windows/com/VariantFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Analyze (java)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🔇 Additional comments (19)
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java (1)

30-30: LGTM!

Also applies to: 233-233, 258-258

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

12-12: LGTM!

Also applies to: 43-43, 47-47, 89-89, 95-95, 107-107, 110-110

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

9-9: LGTM!

Also applies to: 64-64, 71-71

oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IEnumWbemClassObjectFFM.java (1)

10-10: LGTM!

Also applies to: 77-77, 92-92, 120-120, 126-126

oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IWbemClassObjectFFM.java (1)

10-10: LGTM!

Also applies to: 77-77, 93-94

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

26-26: LGTM!

Also applies to: 120-122

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

15-15: LGTM!

Also applies to: 126-129

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

18-18: LGTM!

Also applies to: 130-130, 135-136

oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IUnknownFFM.java (1)

10-10: LGTM!

Also applies to: 53-58, 72-77

oshi-core-ffm/src/main/java/oshi/ffm/windows/com/VariantFFM.java (1)

15-15: LGTM!

Also applies to: 228-228

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

13-15: LGTM!

Also applies to: 111-112, 118-119, 177-178, 221-224, 230-231, 240-243, 250-253, 259-259, 286-287

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

7-8: LGTM!

Also applies to: 338-338

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

17-18: LGTM!

Also applies to: 59-64, 93-98, 170-174

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

9-9: LGTM!

Also applies to: 134-137

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

8-8: LGTM!

Also applies to: 165-166, 203-203

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

7-8: LGTM!

Also applies to: 90-90, 158-158

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

20-21: LGTM!

Also applies to: 58-59, 99-99, 180-181

oshi-core-ffm/src/main/java/oshi/ffm/windows/com/BStrFFM.java (1)

10-12: LGTM!

Also applies to: 54-57, 72-72, 88-88

oshi-core-ffm/src/main/java/oshi/ffm/windows/com/Ole32FFM.java (1)

10-11: LGTM!

Also applies to: 85-88, 98-98, 114-126, 143-151, 171-181


📝 Walkthrough

Walkthrough

This PR systematically replaces manual try-catch exception handling with centralized ExceptionUtil helpers across 20+ FFM wrapper files. The refactoring preserves all functional behavior, logging, and fallback values while eliminating boilerplate through four patterns: fire-and-forget cleanup (runSilently/runOrLog), simple fallback values (getIntOrDefault), complex supplier logic (getOrDefault with lambdas), and optional return types (getOptional*).

Changes

Exception handling centralization via ExceptionUtil

Layer / File(s) Summary
Cleanup and deallocation with runSilently/runOrLog
oshi-core-ffm/src/main/java/oshi/driver/mac/IOReportClientFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/IOKitUtilFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacCentralProcessorFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacUsbDeviceFFM.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsGraphicsCardFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/BStrFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/Ole32FFM.java, oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.java
Fire-and-forget cleanup and logged no-op operations delegate exception suppression to runSilently() (for exception swallowing in cfRelease, deallocatePort, SysFreeString) and runOrLog() (for deallocation with warning logs in vm_deallocate, controller lookups, enumeration attempts, COM uninitialization).
Simple integer and default fallback values
oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/SmcUtilFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/NtDllFFM.java, oshi-core-ffm/src/main/java/oshi/software/os/mac/MacOperatingSystemFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/BStrFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IUnknownFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/VariantFFM.java
Methods returning a single integer or null with a fixed fallback adopt getIntOrDefault() and simple getOrDefault() patterns to convert exceptions directly to fallback values (−1, 0, null, or empty) with centralized logging.
Complex supplier logic and retrieval operations
oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyPerformanceDataUtilFFM.java, oshi-core-ffm/src/main/java/oshi/driver/windows/registry/HkeyUserDataFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/mac/DiskArbitration.java, oshi-core-ffm/src/main/java/oshi/ffm/util/platform/mac/IOKitUtilFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/Advapi32FFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/BStrFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IEnumWbemClassObjectFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/IWbemClassObjectFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/windows/com/Ole32FFM.java
Registry lookups, Disk Arbitration object creation, IOKit service resolution, COM object access, BSTR allocation, and WMI enumeration wrap multi-statement operation logic inside getOrDefault() lambdas with standardized failure fallbacks and method-specific error logging.
Optional return type refactoring for Kernel32 downcalls
oshi-core-ffm/src/main/java/oshi/ffm/windows/Kernel32FFM.java
Nine public methods returning Optional, OptionalInt, or OptionalLong adopt getOptional(), getOptionalInt(), and getOptionalLong() helpers to wrap foreign downcalls, replacing per-method try-catch blocks with consistent exception-to-empty fallback conversion and debug logging.

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • oshi/oshi#3272: This PR directly builds on PR #3272's introduction of the ExceptionUtil static helpers used throughout this refactoring; #3272 creates the centralized exception-handling infrastructure that this PR applies across the codebase.

🐰 From import to unwrap, we now leap,
Where exceptions sleep in helpers' keep,
No more catch blocks—just silent peace,
Each fallback value finds sweet release,
One util to rule them all! 🎯

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 54.55% 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 clearly and concisely summarizes the main change: applying the ExceptionUtil pattern to remaining FFM files, which directly aligns with the substantial refactoring across 19 files documented in the PR objectives.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/exception-util-remaining

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 and usage tips.

@codecov

codecov Bot commented May 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.65%. Comparing base (bed5eda) to head (31aef42).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3273      +/-   ##
============================================
+ Coverage     74.60%   74.65%   +0.05%     
  Complexity       73       73              
============================================
  Files           407      407              
  Lines         16103    16090      -13     
  Branches       2554     2554              
============================================
- Hits          12013    12012       -1     
+ Misses         2607     2594      -13     
- Partials       1483     1484       +1     
Flag Coverage Δ
linux 39.04% <0.00%> (+0.05%) ⬆️
macos 39.67% <50.00%> (+0.03%) ⬆️
windows 47.52% <50.00%> (+<0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@dbwiddis
dbwiddis merged commit 47d2588 into master May 19, 2026
20 checks passed
@dbwiddis
dbwiddis deleted the feature/exception-util-remaining branch May 19, 2026 18:16
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