Repository navigation
Triage Error Prone MixedMutabilityReturnType warnings - #3600
Conversation
21 methods returned Collections.emptyList()/emptyMap() on one path and a freshly-built mutable ArrayList/HashMap on another. Rather than making the empty-path mutable (which would add pointless allocation, since Collections.emptyList()/emptyMap() are singleton immutable instances with no per-call cost), wrap the mutable success path in Collections.unmodifiableList/unmodifiableMap so every path is consistently immutable. This also matters concretely for MacUsbDevice.getUsbDevices() and the GraphicsCard.getGraphicsCards() implementations: AbstractHardwareAbstractionLayer memoizes their results, so the same list instance is shared across every caller until the memo expires - mutating it would corrupt what every subsequent caller sees. Also brought two twins in line that weren't independently flagged (their mixed-mutability wasn't attributed to the enclosing method by the checker, one because it's inside a lambda) but had the identical shape as their now-fixed counterpart: WindowsInternetProtocolStatsFFM and WindowsOperatingSystemFFM's getServices()/getConnections().
|
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 (22)
📜 Recent review details⏰ Context from checks skipped due to timeout. (1)
🧰 Additional context used📓 Path-based instructions (4)**/*.{java,properties}📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-common/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
oshi-core-ffm/**/*.java📄 CodeRabbit inference engine (AGENTS.md)
Files:
🧠 Learnings (20)📚 Learning: 2026-04-08T00:58:10.736ZApplied to files:
📚 Learning: 2026-04-06T04:45:51.516ZApplied to files:
📚 Learning: 2026-06-12T16:33:11.703ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied 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-03-29T20:01:06.452ZApplied to files:
📚 Learning: 2026-04-06T04:45:47.644ZApplied to files:
📚 Learning: 2026-08-02T23:56:23.866ZApplied to files:
📚 Learning: 2026-04-05T15:37:17.867ZApplied to files:
📚 Learning: 2026-04-06T21:48:11.921ZApplied to files:
📚 Learning: 2026-04-06T22:30:07.083ZApplied to files:
📚 Learning: 2026-07-28T18:20:41.673ZApplied to files:
📚 Learning: 2026-04-05T16:15:06.124ZApplied to files:
📚 Learning: 2026-08-12T22:15:37.668ZApplied to files:
📚 Learning: 2026-04-05T05:40:45.797ZApplied to files:
📚 Learning: 2026-04-05T05:39:21.126ZApplied to files:
📚 Learning: 2026-08-12T22:15:37.668ZApplied to files:
📚 Learning: 2026-04-05T15:37:16.042ZApplied to files:
🔇 Additional comments (22)
📝 WalkthroughWalkthroughThe PR changes collection-returning methods across common, FFM, and JNA implementations to return unmodifiable lists or maps instead of mutable results. ChangesUnmodifiable collection returns
Estimated code review effort: 2 (Simple) | ~10 minutes Mergeability Score: ⚪ Minimal · up to The change consistently returns immutable collections across affected paths, with the reported validation checks passing; no actionable merge-blocking risk remains beyond normal review. 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✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3600 +/- ##
============================================
- Coverage 79.85% 79.80% -0.05%
- Complexity 3873 3996 +123
============================================
Files 710 710
Lines 24254 24254
Branches 4057 4057
============================================
- Hits 19367 19356 -11
- Misses 2725 2734 +9
- Partials 2162 2164 +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:
|
Summary
Collections.emptyList()/emptyMap()on one path and a freshly-built mutableArrayList/HashMapon another. Fixed by wrapping the mutable success path inCollections.unmodifiableList/unmodifiableMap— a zero-cost O(1) view, not a copy — so every return path is consistently immutable, rather than making the empty-path mutable (which would just add pointless per-call allocation, sinceCollections.emptyList()/emptyMap()are already free singleton immutable instances).AbstractHardwareAbstractionLayermemoizesgetUsbDevices()/getGraphicsCards()(memoize(this::createX, slowExpiration())), soMacUsbDevice.getUsbDevices()and bothGraphicsCard.getGraphicsCards()implementations return the same shared list instance to every caller until the memo expires — an accidental mutation there would corrupt what every other caller sees.WindowsInternetProtocolStatsFFM.getConnections()andWindowsOperatingSystemFFM'squeryServicesFFM().Test plan
./mvnw clean install -Perror-prone -DskipTests: 0 ERROR,MixedMutabilityReturnType21 → 0./mvnw -pl oshi-common,oshi-core,oshi-core-ffm -am test: 0 tests failed./mvnw checkstyle:check,forbiddenapis:check,clean compile javadoc:javadoc: all passSummary by CodeRabbit