Repository navigation
Sonar JDK-modernization sweep (S1481, S1117, S6201, S6208, S6880) - #3393
Conversation
The FFM port wraps native handles/pointers in AutoCloseable RAII helpers (CFTypeRef, NativeHandle) inside try-with-resources purely so close() runs the native release (CFRelease, udev_unref, CloseHandle, ...). The body uses the raw segment, never the wrapper, so Sonar S1481 flagged the wrapper as an unused local. Replace those names with the Java 22 unnamed variable '_' (oshi-core-ffm is release 25) and add a short comment noting the cleanup-only intent. Deleting them, as the rule literally suggests, would leak the native objects. One genuine case differed: CoreFoundationTest opened an Arena it never allocated from, so that one is removed outright rather than renamed. Left untouched the named handles that ARE read in their bodies (e.g. WindowsOperatingSystemFFM hToken). No behavior change.
Three independent name-shadowing fixes flagged by Sonar S1117: - LinuxOSProcess: the two ctxt-switch locals shadowed the same-named fields and added nothing, so assign the parsed values straight to the fields. - MemoizerTest: the ThreadPoolExecutor local 'ex' shadowed the ExecutorService field 'ex'; rename the local to 'executor'. - OperatingSystemTest: eight test methods declared a local 'os' shadowing the shared 'os' field; rename those locals to 'system'. Pure rename, no change to which instance each test uses (the locals were createOperatingSystem() calls, not the field). No behavior change.
Collapse the five 'instanceof X' + explicit cast pairs in the FFM port into 'instanceof X binding' form (JDK 16; oshi-core-ffm is release 25). No behavior change.
Merge consecutive fall-through 'case' labels into single comma-separated labels (JDK 14 multi-label cases, colon form). Purely a label-syntax change; the switch bodies and fall-through semantics are unchanged.
Convert four single-variable if/else cascades to switch (JDK 14+ arrow form): - WindowsCentralProcessorFFM: clean value-producing switch expression for freqs. - HkeyPerformanceDataUtilFFM: switch expression yielding the counter value, then put/return null as before (the default arm is the not-in-registry sentinel). - MacInternetProtocolStatsFFM (x2): the branches assign several locals and have an early return, so these become arrow switch statements rather than expressions. Verified on macOS via NativeComparisonTest. No behavior change.
|
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 (29)
📜 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 (3)📚 Learning: 2026-04-08T00:58:07.212ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-05T15:37:16.042ZApplied to files:
🔇 Additional comments (39)
📝 WalkthroughWalkthroughThis PR modernizes the codebase across multiple dimensions: Java language features (pattern matching, switch expressions, combined switch cases), resource management in CoreFoundation and native-handle contexts via unnamed try-with-resources bindings, and test refactoring to use local OS instances. Changes span driver, utility, hardware-platform, and test modules. ChangesSystematic Java Modernization and Resource Management Refactoring
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 #3393 +/- ##
============================================
+ Coverage 68.65% 75.02% +6.37%
Complexity 76 76
============================================
Files 579 579
Lines 21363 21364 +1
Branches 3560 3556 -4
============================================
+ Hits 14666 16029 +1363
+ Misses 4868 3307 -1561
- Partials 1829 2028 +199
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:
|
Mechanical SonarCloud modernization, one commit per rule. No behavior change; verified locally with a clean
install -P native-comparison(NativeComparisonTest green) plus checkstyle/forbiddenapis/javadoc on the touched modules.Commits
CFTypeRef,NativeHandle) wrapped in try-with-resources purely to run the native release onclose()were flagged as unused locals. Replaced their names with the JDK 22 unnamed variable_(oshi-core-ffm is release 25) and added a short comment noting the cleanup-only intent. Deleting them, as the rule literally suggests, would leak the native objects. One genuine stray case (aCoreFoundationTestArena never allocated from) is removed outright.LinuxOSProcessctxt-switch locals assigned straight to their fields;MemoizerTestlocalex→executor; eightOperatingSystemTestmethod localsos→system. Pure renames.instanceof X+ cast pairs → pattern-matchinginstanceof X binding(JDK 16).caselabels merged into comma-separated labels (JDK 14, colon form).switch(JDK 14+ arrow form). Two are clean value-producing switch expressions; the twoMacInternetProtocolStatsFFMchains assign several locals with an early return, so they become arrow switch statements (verified on macOS via NativeComparisonTest).All changes are confined to
oshi-core-ffmexcept the S1117 renames (oshi-common / oshi-core). A separate follow-up will cover thejava8-tagged findings (project-wide, release 8/9 modules).Summary by CodeRabbit
Refactor
Tests