Repository navigation
Migrate MacFileSystemFFM to AutoCloseable try-with-resources - #3294
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 (2)
📜 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). (11)
🧰 Additional context used🧠 Learnings (1)📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
🔇 Additional comments (4)
📝 WalkthroughWalkthrough
ChangesDiskArbitration and IOKit Resource Management Refactoring
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 #3294 +/- ##
============================================
- Coverage 75.62% 75.58% -0.04%
Complexity 76 76
============================================
Files 410 410
Lines 15807 15800 -7
Branches 2529 2528 -1
============================================
- Hits 11954 11943 -11
- Misses 2381 2385 +4
Partials 1472 1472
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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/mac/MacFileSystemFFM.java`:
- Around line 162-170: The code in MacFileSystemFFM currently calls
fsIter.next() into fsEntry and only uses try (fsEntry) when
fsEntry.conformsTo("IOMedia"), causing a resource leak when conformsTo returns
false; to fix, move the try-with-resources to wrap the fsEntry declaration
unconditionally (i.e., obtain fsEntry and immediately enter try (fsEntry) { ...
}), then inside the try check fsEntry != null and fsEntry.conformsTo("IOMedia")
before accessing getStringProperty("UUID") so the resource is always closed
regardless of conformity.
🪄 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
Run ID: c3fb7991-351a-45b5-bacc-a122de8f41b9
📒 Files selected for processing (1)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java
📜 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). (13)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Analyze (java)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🔇 Additional comments (3)
oshi-core-ffm/src/main/java/oshi/software/os/mac/MacFileSystemFFM.java (3)
91-93: LGTM!
141-153: LGTM!
158-159: LGTM!
bb13e0e to
4ac81d7
Compare
Replace manual finally blocks with try-with-resources for CF/IOKit
object lifecycle management in MacFileSystemFFM.
Also fixes a pre-existing IORegistryEntry leak in both JNA and FFM
implementations: when fsEntry.conformsTo("IOMedia") returned false,
the entry was never released. This bug was discovered through the
AutoCloseable migration which made the missing cleanup path obvious.
MacHWDiskStoreFFM deferred — deeply nested structure requires
dedicated careful attention.
4ac81d7 to
73e1659
Compare
Replace manual
finallyblocks with try-with-resources for CF/IOKit object lifecycle management inMacFileSystemFFM.Changes
try (session)andtry (daVolumeNameKey)try (DADiskRef disk)andtry (CFDictionaryRef diskInfo)for DiskArbitration lookupstry (IOIterator fsIter)andtry (IORegistryEntry fsEntry)for UUID lookupBug fix: IORegistryEntry leak (JNA + FFM)
The AutoCloseable migration revealed a pre-existing resource leak in both the JNA and FFM implementations: when
fsEntry.conformsTo("IOMedia")returnedfalse, theIORegistryEntrywas never released. This was invisible in the original code because the release was inside theifblock. The try-with-resources refactoring made the missing cleanup path obvious.Fixed in both:
MacFileSystemFFM.java—try (IORegistryEntry fsEntry = ...)ensures unconditional releaseMacFileSystemJNA.java— movedfsEntry.release()outside theconformsTocheckDeferred
MacHWDiskStoreFFM— deeply nested (18 finally blocks across 3 methods), requires dedicated careful attention in a separate PR.Summary by CodeRabbit
Refactor
Bug Fixes